You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
5.0 KiB
179 lines
5.0 KiB
using Autofac;
|
|
using Tiobon.Core.Controllers;
|
|
using Tiobon.Core.IServices;
|
|
using Tiobon.Core.Model;
|
|
using Tiobon.Core.Model.Models;
|
|
using Tiobon.Core.Model.ViewModels;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Xunit;
|
|
|
|
namespace Tiobon.Core.Tests
|
|
{
|
|
public class TiobonController_Should
|
|
{
|
|
Mock<ITiobonArticleServices> mockTiobonSev = new Mock<ITiobonArticleServices>();
|
|
Mock<ILogger<TiobonController>> mockLogger = new Mock<ILogger<TiobonController>>();
|
|
TiobonController TiobonController;
|
|
|
|
private ITiobonArticleServices TiobonArticleServices;
|
|
DI_Test dI_Test = new DI_Test();
|
|
|
|
|
|
|
|
public TiobonController_Should()
|
|
{
|
|
mockTiobonSev.Setup(r => r.Query());
|
|
|
|
var container = dI_Test.DICollections();
|
|
TiobonArticleServices = container.Resolve<ITiobonArticleServices>();
|
|
TiobonController = new TiobonController(mockLogger.Object);
|
|
TiobonController._TiobonArticleServices = TiobonArticleServices;
|
|
}
|
|
|
|
[Fact]
|
|
public void TestEntity()
|
|
{
|
|
TiobonArticle TiobonArticle = new TiobonArticle();
|
|
|
|
Assert.True(TiobonArticle.bID >= 0);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Tiobon_Page_Test()
|
|
{
|
|
ServiceResult<PageModel<TiobonArticle>> Tiobons = await TiobonController.Get(1, 1, "技术博文", "");
|
|
Assert.NotNull(Tiobons);
|
|
Assert.NotNull(Tiobons.Data);
|
|
Assert.True(Tiobons.Data.dataCount >= 0);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Tiobon_Test()
|
|
{
|
|
ServiceResult<TiobonViewModels> TiobonVo = await TiobonController.Get(1.ObjToLong());
|
|
|
|
Assert.NotNull(TiobonVo);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Tiobon_For_Nuxt_Test()
|
|
{
|
|
ServiceResult<TiobonViewModels> TiobonVo = await TiobonController.DetailNuxtNoPer(1);
|
|
|
|
Assert.NotNull(TiobonVo);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Go_Url_Test()
|
|
{
|
|
object urlAction = await TiobonController.GoUrl(1);
|
|
|
|
Assert.NotNull(urlAction);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Tiobon_By_Type_For_MVP_Test()
|
|
{
|
|
ServiceResult<List<TiobonArticle>> Tiobons = await TiobonController.GetTiobonsByTypesForMVP("技术博文");
|
|
|
|
Assert.NotNull(Tiobons);
|
|
Assert.True(Tiobons.Success);
|
|
Assert.NotNull(Tiobons.Data);
|
|
Assert.True(Tiobons.Data.Count >= 0);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Tiobon_By_Id_For_MVP_Test()
|
|
{
|
|
ServiceResult<TiobonArticle> Tiobon = await TiobonController.GetTiobonByIdForMVP(1);
|
|
|
|
Assert.NotNull(Tiobon);
|
|
Assert.True(Tiobon.Success);
|
|
Assert.NotNull(Tiobon.Data);
|
|
}
|
|
|
|
[Fact]
|
|
public async void PostTest()
|
|
{
|
|
TiobonArticle TiobonArticle = new TiobonArticle()
|
|
{
|
|
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 TiobonController.Post(TiobonArticle);
|
|
|
|
Assert.True(res.Success);
|
|
|
|
var data = res.Data;
|
|
|
|
Assert.NotNull(data);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Post_Insert_For_MVP_Test()
|
|
{
|
|
TiobonArticle TiobonArticle = new TiobonArticle()
|
|
{
|
|
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 TiobonController.AddForMVP(TiobonArticle);
|
|
|
|
Assert.True(res.Success);
|
|
|
|
var data = res.Data;
|
|
|
|
Assert.NotNull(data);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Put_Test()
|
|
{
|
|
TiobonArticle TiobonArticle = new TiobonArticle()
|
|
{
|
|
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 TiobonController.Put(TiobonArticle);
|
|
|
|
Assert.True(res.Success);
|
|
|
|
var data = res.Data;
|
|
|
|
Assert.NotNull(data);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Delete_Test()
|
|
{
|
|
var res = await TiobonController.Delete(99);
|
|
|
|
Assert.False(res.Success);
|
|
|
|
var data = res.Data;
|
|
|
|
Assert.Null(data);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Apache_Update_Test()
|
|
{
|
|
var res = await TiobonController.ApacheTestUpdate();
|
|
|
|
Assert.True(res.Success);
|
|
}
|
|
}
|
|
}
|
|
|