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.
119 lines
3.5 KiB
119 lines
3.5 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Shentun.Peis.GuideTypes;
|
|
using Shentun.Peis.Models;
|
|
using Shouldly;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Uow;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Shentun.Peis
|
|
{
|
|
public class GuideTypeAppServiceTest: PeisApplicationTestBase
|
|
{
|
|
private readonly IRepository<GuideType, char> _repository;
|
|
private readonly GuideTypeAppService _guideTypeAppService;
|
|
private readonly ITestOutputHelper _output;
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|
public GuideTypeAppServiceTest(ITestOutputHelper testOutputHelper)
|
|
{
|
|
_output = testOutputHelper;
|
|
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
|
|
_repository = GetRequiredService<IRepository<GuideType, char>>();
|
|
_guideTypeAppService = GetRequiredService<GuideTypeAppService>();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetQueryListAsync()
|
|
{
|
|
using (var uow = _unitOfWorkManager.Begin())
|
|
{
|
|
IQueryable<GuideType> queryable = await _repository.GetQueryableAsync();
|
|
var itemTypes = (from item in queryable
|
|
|
|
select item).ToList();
|
|
foreach (var item in itemTypes)
|
|
{
|
|
|
|
_output.WriteLine(item.DisplayName);
|
|
}
|
|
await uow.CompleteAsync();
|
|
}
|
|
|
|
|
|
}
|
|
[Fact]
|
|
public async Task GetListAsync()
|
|
{
|
|
PagedAndSortedResultRequestDto qc = new PagedAndSortedResultRequestDto()
|
|
{
|
|
Sorting = "displayorder"
|
|
};
|
|
var result = await _guideTypeAppService.GetListAsync(qc);
|
|
|
|
|
|
_output.WriteLine(result.TotalCount.ToString());
|
|
foreach (var item in result.Items)
|
|
{
|
|
Console.WriteLine(item.DisplayName);
|
|
_output.WriteLine(item.DisplayName);
|
|
}
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetList()
|
|
{
|
|
PagedAndSortedResultRequestDto qc = new PagedAndSortedResultRequestDto() {
|
|
Sorting = "displayorder"};
|
|
var result = await _guideTypeAppService.GetListAsync(qc);
|
|
result.TotalCount.ShouldBeGreaterThanOrEqualTo(4);
|
|
Console.WriteLine(result.TotalCount);
|
|
_output.WriteLine(result.TotalCount.ToString());
|
|
foreach (var item in result.Items)
|
|
{
|
|
Console.WriteLine(item.DisplayName);
|
|
_output.WriteLine(item.DisplayName);
|
|
}
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Create()
|
|
{
|
|
|
|
var result = await _guideTypeAppService.CreateAsync(new CreateGuideTypeDto()
|
|
{
|
|
DisplayName = "Foo",
|
|
});
|
|
_output.WriteLine(result.Id.ToString());
|
|
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DeleteAsync()
|
|
{
|
|
try
|
|
{
|
|
using (var uow = _unitOfWorkManager.Begin())
|
|
{
|
|
await _guideTypeAppService.DeleteAsync('0');
|
|
_output.WriteLine("删除成功");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_output.WriteLine(ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|