Browse Source

updated repository tests

pull/56/head
Galip Tolga Erdem 4 years ago
parent
commit
07a71a4d75
  1. 14
      services/ordering/test/EShopOnAbp.OrderingService.EntityFrameworkCore.Tests/EntityFrameworkCore/Orders/OrderRepository_Tests.cs
  2. 12
      services/ordering/test/EShopOnAbp.OrderingService.EntityFrameworkCore.Tests/EntityFrameworkCore/Samples/SampleRepository_Tests.cs
  3. 25
      services/ordering/test/EShopOnAbp.OrderingService.TestBase/OrderingServiceTestDataSeedContributor.cs
  4. 3
      services/ordering/test/EShopOnAbp.OrderingService.TestBase/TestData.cs

14
services/ordering/test/EShopOnAbp.OrderingService.EntityFrameworkCore.Tests/EntityFrameworkCore/Orders/OrderRepository_Tests.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using EShopOnAbp.OrderingService.Orders;
using EShopOnAbp.OrderingService.Orders.Specifications;
using EShopOnAbp.OrderingService.Samples;
@ -34,6 +35,15 @@ public class OrderRepository_Tests : SampleRepository_Tests<OrderingServiceEntit
{
var orders =
await _orderRepository.GetOrdersByUserId(_testData.CurrentUserId, new Last30DaysSpecification(), true);
orders.Count.ShouldBe(2);
orders.Count.ShouldBe(3);
var firstOrder = orders.First();
firstOrder.OrderItems.Count.ShouldBe(5);
}
[Fact]
public async Task Should_Get_Users_Last_Year_Orders()
{
var orders =
await _orderRepository.GetOrdersByUserId(_testData.CurrentUserId, new YearSpecification(2020), true);
orders.Count.ShouldBe(0);
}
}

12
services/ordering/test/EShopOnAbp.OrderingService.EntityFrameworkCore.Tests/EntityFrameworkCore/Samples/SampleRepository_Tests.cs

@ -1,12 +0,0 @@
using EShopOnAbp.OrderingService.Samples;
namespace EShopOnAbp.OrderingService.EntityFrameworkCore.Samples
{
public class SampleRepository_Tests : SampleRepository_Tests<OrderingServiceEntityFrameworkCoreTestModule>
{
/* Don't write custom repository tests here, instead write to
* the base class.
* One exception can be some specific tests related to EF core.
*/
}
}

25
services/ordering/test/EShopOnAbp.OrderingService.TestBase/OrderingServiceTestDataSeedContributor.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using EShopOnAbp.OrderingService.Orders;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
@ -28,7 +29,7 @@ namespace EShopOnAbp.OrderingService
private async Task SeedTestOrdersAsync()
{
var order1 = await _orderManager.CreateOrderAsync(
await _orderManager.CreateOrderAsync(
1,
_testData.CurrentUserId,
_testData.CurrentUserName,
@ -40,7 +41,7 @@ namespace EShopOnAbp.OrderingService
_testData.Address.ZipCode
);
var order2 = await _orderManager.CreateOrderAsync(
await _orderManager.CreateOrderAsync(
1, _testData.CurrentUserId, _testData.CurrentUserName, _testData.CurrentUserEmail,
_testProducts.GetRandomProducts(10),
_testData.Address.Street,
@ -48,6 +49,24 @@ namespace EShopOnAbp.OrderingService
_testData.Address.Country,
_testData.Address.ZipCode
);
await _orderManager.CreateOrderAsync(
1, _testData.CurrentUserId, _testData.CurrentUserName, _testData.CurrentUserEmail,
_testProducts.GetRandomProducts(2),
_testData.Address.Street,
_testData.Address.City,
_testData.Address.Country,
_testData.Address.ZipCode
);
await _orderManager.CreateOrderAsync(
1, _testData.TestUserId, _testData.TestUserName, _testData.TestUserEmail,
_testProducts.GetRandomProducts(7),
_testData.Address.Street,
_testData.Address.City,
_testData.Address.Country,
_testData.Address.ZipCode
);
}
}
}

3
services/ordering/test/EShopOnAbp.OrderingService.TestBase/TestData.cs

@ -8,6 +8,9 @@ public class TestData : ISingletonDependency
public string CurrentUserEmail { get; set; } = "galip.erdem@volosoft.com";
public Guid CurrentUserId { get; set; } = Guid.NewGuid();
public string CurrentUserName { get; set; } = "Galip T. ERDEM";
public Guid TestUserId { get; set; } = Guid.NewGuid();
public string TestUserEmail { get; set; } = "test@user.com";
public string TestUserName { get; set; } = "Test User";
public DemoAddress Address { get; set; } = new DemoAddress();
public class DemoAddress

Loading…
Cancel
Save