init
This commit is contained in:
179
DouyinApi.Tests/Controller_Test/BlogController_Should.cs
Normal file
179
DouyinApi.Tests/Controller_Test/BlogController_Should.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
using Autofac;
|
||||
using DouyinApi.Controllers;
|
||||
using DouyinApi.IServices;
|
||||
using DouyinApi.Model;
|
||||
using DouyinApi.Model.Models;
|
||||
using DouyinApi.Model.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace DouyinApi.Tests
|
||||
{
|
||||
public class BlogController_Should
|
||||
{
|
||||
Mock<IBlogArticleServices> mockBlogSev = new Mock<IBlogArticleServices>();
|
||||
Mock<ILogger<BlogController>> mockLogger = new Mock<ILogger<BlogController>>();
|
||||
BlogController blogController;
|
||||
|
||||
private IBlogArticleServices blogArticleServices;
|
||||
DI_Test dI_Test = new DI_Test();
|
||||
|
||||
|
||||
|
||||
public BlogController_Should()
|
||||
{
|
||||
mockBlogSev.Setup(r => r.Query());
|
||||
|
||||
var container = dI_Test.DICollections();
|
||||
blogArticleServices = container.Resolve<IBlogArticleServices>();
|
||||
blogController = new BlogController(mockLogger.Object);
|
||||
blogController._blogArticleServices = blogArticleServices;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEntity()
|
||||
{
|
||||
BlogArticle blogArticle = new BlogArticle();
|
||||
|
||||
Assert.True(blogArticle.bID >= 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Blog_Page_Test()
|
||||
{
|
||||
MessageModel<PageModel<BlogArticle>> blogs = await blogController.Get(1, 1, "技术博文", "");
|
||||
Assert.NotNull(blogs);
|
||||
Assert.NotNull(blogs.response);
|
||||
Assert.True(blogs.response.dataCount >= 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Blog_Test()
|
||||
{
|
||||
MessageModel<BlogViewModels> blogVo = await blogController.Get(1.ObjToLong());
|
||||
|
||||
Assert.NotNull(blogVo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Blog_For_Nuxt_Test()
|
||||
{
|
||||
MessageModel<BlogViewModels> blogVo = await blogController.DetailNuxtNoPer(1);
|
||||
|
||||
Assert.NotNull(blogVo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Go_Url_Test()
|
||||
{
|
||||
object urlAction = await blogController.GoUrl(1);
|
||||
|
||||
Assert.NotNull(urlAction);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Blog_By_Type_For_MVP_Test()
|
||||
{
|
||||
MessageModel<List<BlogArticle>> blogs = await blogController.GetBlogsByTypesForMVP("技术博文");
|
||||
|
||||
Assert.NotNull(blogs);
|
||||
Assert.True(blogs.success);
|
||||
Assert.NotNull(blogs.response);
|
||||
Assert.True(blogs.response.Count >= 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Blog_By_Id_For_MVP_Test()
|
||||
{
|
||||
MessageModel<BlogArticle> blog = await blogController.GetBlogByIdForMVP(1);
|
||||
|
||||
Assert.NotNull(blog);
|
||||
Assert.True(blog.success);
|
||||
Assert.NotNull(blog.response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void PostTest()
|
||||
{
|
||||
BlogArticle blogArticle = new BlogArticle()
|
||||
{
|
||||
bCreateTime = DateTime.Now,
|
||||
bUpdateTime = DateTime.Now,
|
||||
btitle = "xuint :test controller addEntity",
|
||||
bcontent = "xuint :test controller addEntity. this is content.this is content."
|
||||
};
|
||||
|
||||
var res = await blogController.Post(blogArticle);
|
||||
|
||||
Assert.True(res.success);
|
||||
|
||||
var data = res.response;
|
||||
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Post_Insert_For_MVP_Test()
|
||||
{
|
||||
BlogArticle blogArticle = new BlogArticle()
|
||||
{
|
||||
bCreateTime = DateTime.Now,
|
||||
bUpdateTime = DateTime.Now,
|
||||
btitle = "xuint :test controller addEntity",
|
||||
bcontent = "xuint :test controller addEntity. this is content.this is content."
|
||||
};
|
||||
|
||||
var res = await blogController.AddForMVP(blogArticle);
|
||||
|
||||
Assert.True(res.success);
|
||||
|
||||
var data = res.response;
|
||||
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Put_Test()
|
||||
{
|
||||
BlogArticle blogArticle = new BlogArticle()
|
||||
{
|
||||
bID = 1,
|
||||
bCreateTime = DateTime.Now,
|
||||
bUpdateTime = DateTime.Now,
|
||||
btitle = "xuint put :test controller addEntity",
|
||||
bcontent = "xuint put :test controller addEntity. this is content.this is content."
|
||||
};
|
||||
|
||||
var res = await blogController.Put(blogArticle);
|
||||
|
||||
Assert.True(res.success);
|
||||
|
||||
var data = res.response;
|
||||
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Delete_Test()
|
||||
{
|
||||
var res = await blogController.Delete(99);
|
||||
|
||||
Assert.False(res.success);
|
||||
|
||||
var data = res.response;
|
||||
|
||||
Assert.Null(data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Apache_Update_Test()
|
||||
{
|
||||
var res = await blogController.ApacheTestUpdate();
|
||||
|
||||
Assert.True(res.success);
|
||||
}
|
||||
}
|
||||
}
|
||||
78
DouyinApi.Tests/Controller_Test/LoginController_Should.cs
Normal file
78
DouyinApi.Tests/Controller_Test/LoginController_Should.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using DouyinApi.Controllers;
|
||||
using DouyinApi.IServices;
|
||||
using Xunit;
|
||||
using Autofac;
|
||||
using DouyinApi.AuthHelper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DouyinApi.Tests
|
||||
{
|
||||
public class LoginController_Should
|
||||
{
|
||||
LoginController loginController;
|
||||
|
||||
private readonly ISysUserInfoServices _sysUserInfoServices;
|
||||
private readonly IUserRoleServices _userRoleServices;
|
||||
private readonly IRoleServices _roleServices;
|
||||
private readonly PermissionRequirement _requirement;
|
||||
private readonly IRoleModulePermissionServices _roleModulePermissionServices;
|
||||
private readonly ILogger<LoginController> _logger;
|
||||
|
||||
DI_Test dI_Test = new DI_Test();
|
||||
|
||||
|
||||
public LoginController_Should()
|
||||
{
|
||||
var container = dI_Test.DICollections();
|
||||
_sysUserInfoServices = container.Resolve<ISysUserInfoServices>();
|
||||
_userRoleServices = container.Resolve<IUserRoleServices>();
|
||||
_roleServices = container.Resolve<IRoleServices>();
|
||||
_requirement = container.Resolve<PermissionRequirement>();
|
||||
_roleModulePermissionServices = container.Resolve<IRoleModulePermissionServices>();
|
||||
_logger = container.Resolve<ILogger<LoginController>>();
|
||||
loginController = new LoginController(_sysUserInfoServices, _userRoleServices, _roleServices, _requirement,
|
||||
_roleModulePermissionServices, _logger);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetJwtStrTest()
|
||||
{
|
||||
var data = loginController.GetJwtStr("test", "test");
|
||||
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetJwtStrForNuxtTest()
|
||||
{
|
||||
object blogs = loginController.GetJwtStrForNuxt("test", "test");
|
||||
|
||||
Assert.NotNull(blogs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetJwtToken3Test()
|
||||
{
|
||||
var res = await loginController.GetJwtToken3("test", "test");
|
||||
|
||||
Assert.NotNull(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void RefreshTokenTest()
|
||||
{
|
||||
var res = await loginController.RefreshToken(
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoidGVzdCIsImp0aSI6IjgiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL2V4cGlyYXRpb24iOiIyMDE5LzEwLzE4IDIzOjI2OjQ5IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW5UZXN0IiwibmJmIjoxNTcxNDA4ODA5LCJleHAiOjE1NzE0MTI0MDksImlzcyI6IkJsb2cuQ29yZSIsImF1ZCI6IndyIn0.oz-SPz6UCL78fM09bUecw5rmjcNYEY9dWGtuPs2gdBg");
|
||||
|
||||
Assert.NotNull(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Md5PasswordTest()
|
||||
{
|
||||
var res = loginController.Md5Password("test");
|
||||
|
||||
Assert.NotNull(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user