.NET Core单元测试xUnit

新建工程

在这里插入图片描述

实现,拿登录接口举例

using System;
using System.Threading.Tasks;
using UIH.RT.Cloud.Identity.Controllers;
using UIH.RT.Cloud.Identity.Controllers.Dto;
using UIH.RT.Cloud.Identity.Models;
using UIH.RT.Cloud.Identity.Models.AccountViewModels;
using UIH.RT.Cloud.Identity.Services;
using Xunit;
using Microsoft.AspNetCore.Mvc;



namespace UIH.RT.Cloud.Identity.Tests
{
    public class AccountControllerTest
    {
        private AccountController _myTest;

        private readonly ILoginService<ApplicationUser> _loginService;
        public AccountControllerTest(ILoginService<ApplicationUser> loginService, AccountController myTest)
        {
            _loginService = loginService;
            _myTest = myTest;
        }

        /// <UTSKey>
        /// ID:DS100291
        /// Title:DS_PRA_Common_AccessAuthorization_LoginSystem 100291
        /// <UTSKey>
        [Fact]
        public async Task LogInTest()
        {
            LoginViewModel model = new LoginViewModel();
            model.UserName = "admin";
            model.Password = "111111";
            model.ReturnUrl = "";
            var ret = await _myTest.Login(model);
            if (ret == _myTest.Redirect(model.ReturnUrl))
            {
                Assert.True(true);
            }
            else
            {
                Assert.True(false);
            }
        }
    }
}

发布了78 篇原创文章 · 获赞 0 · 访问量 1267

猜你喜欢

转载自blog.csdn.net/qq_21209307/article/details/105289242