Browse Source

Complete the basic unit test of the stores module.

pull/99/head
GameBelial 6 years ago
parent
commit
9d6ad6a3d3
  1. 29
      modules/EasyAbp.EShop.Stores/test/EasyAbp.EShop.Stores.Application.Tests/Stores/StoreAppServiceTests.cs
  2. 13
      modules/EasyAbp.EShop.Stores/test/EasyAbp.EShop.Stores.Application.Tests/StoresApplicationTestBase.cs
  3. 7
      modules/EasyAbp.EShop.Stores/test/EasyAbp.EShop.Stores.TestBase/StoresTestData.cs

29
modules/EasyAbp.EShop.Stores/test/EasyAbp.EShop.Stores.Application.Tests/Stores/StoreAppServiceTests.cs

@ -1,5 +1,7 @@
using System.Linq;
using Shouldly; using Shouldly;
using System.Threading.Tasks; using System.Threading.Tasks;
using EasyAbp.EShop.Stores.Stores.Dtos;
using Xunit; using Xunit;
namespace EasyAbp.EShop.Stores.Stores namespace EasyAbp.EShop.Stores.Stores
@ -14,13 +16,38 @@ namespace EasyAbp.EShop.Stores.Stores
} }
[Fact] [Fact]
public async Task Test1() public async Task Should_Create_A_Store()
{ {
// Arrange // Arrange
var request = new CreateUpdateStoreDto
{
Name = "New Store 2"
};
// Act // Act
var response = await _storeAppService.CreateAsync(request);
// Assert // Assert
response.ShouldNotBeNull();
response.Name.ShouldBe("New Store 2");
UsingDbContext(db =>
{
var store = db.Stores.FirstOrDefault(x=>x.Id == response.Id);
store.ShouldNotBeNull();
store.Name.ShouldBe("New Store 2");
});
}
[Fact]
public async Task Should_Return_Default_Store()
{
// Arrange & Act
var response = await _storeAppService.GetDefaultAsync();
// Assert
response.ShouldNotBeNull();
response.Name.ShouldBe("My Store");
} }
} }
} }

13
modules/EasyAbp.EShop.Stores/test/EasyAbp.EShop.Stores.Application.Tests/StoresApplicationTestBase.cs

@ -1,10 +1,19 @@
namespace EasyAbp.EShop.Stores using System;
using EasyAbp.EShop.Stores.EntityFrameworkCore;
namespace EasyAbp.EShop.Stores
{ {
/* Inherit from this class for your application layer tests. /* Inherit from this class for your application layer tests.
* See SampleAppService_Tests for example. * See SampleAppService_Tests for example.
*/ */
public abstract class StoresApplicationTestBase : StoresTestBase<EShopStoresApplicationTestModule> public abstract class StoresApplicationTestBase : StoresTestBase<EShopStoresApplicationTestModule>
{ {
protected void UsingDbContext(Action<IStoresDbContext> action)
{
using (var dbContext = GetRequiredService<IStoresDbContext>())
{
action.Invoke(dbContext);
}
}
} }
} }

7
modules/EasyAbp.EShop.Stores/test/EasyAbp.EShop.Stores.TestBase/StoresTestData.cs

@ -0,0 +1,7 @@
namespace EasyAbp.EShop.Stores
{
public static class StoresTestData
{
}
}
Loading…
Cancel
Save