From b87461b2306bd850da99c572f1676170bebe40a8 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 21 Jan 2019 10:33:55 +0300 Subject: [PATCH] microservice demo: unit tests fixed --- .../ProductAppService_Tests.cs | 19 +++++++++++++------ .../ProductManagementTestData.cs | 4 ---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/samples/MicroserviceDemo/modules/product/test/ProductManagement.Application.Tests/ProductManagement/ProductAppService_Tests.cs b/samples/MicroserviceDemo/modules/product/test/ProductManagement.Application.Tests/ProductManagement/ProductAppService_Tests.cs index a3320d200f..4964f5df98 100644 --- a/samples/MicroserviceDemo/modules/product/test/ProductManagement.Application.Tests/ProductManagement/ProductAppService_Tests.cs +++ b/samples/MicroserviceDemo/modules/product/test/ProductManagement.Application.Tests/ProductManagement/ProductAppService_Tests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading.Tasks; using Shouldly; @@ -40,7 +41,9 @@ namespace ProductManagement [Fact] public async Task GetAsync() { - var result = await _productAppService.GetAsync(_testData.ProductId1); + var product = (await _productRepository.GetListAsync()).FirstOrDefault(); + + var result = await _productAppService.GetAsync(product.Id); result.ShouldNotBeNull(); result.Name.ShouldBe(_testData.ProductName1); @@ -66,25 +69,29 @@ namespace ProductManagement [Fact] public async Task UpdateAsync() { - var result = await _productAppService.UpdateAsync(_testData.ProductId1, new UpdateProductDto() + var product = (await _productRepository.GetListAsync()).FirstOrDefault(); + + var result = await _productAppService.UpdateAsync(product.Id, new UpdateProductDto() { - Code = nameof(Product.Code), Name = nameof(Product.Name), Price = 15, StockCount = 14 }); result.ShouldNotBeNull(); - result.Code.ShouldBe(nameof(Product.Code)); result.Name.ShouldBe(nameof(Product.Name)); + result.Price.ShouldBe(15); + result.StockCount.ShouldBe(14); } [Fact] public async Task DeleteAsync() { - await _productAppService.DeleteAsync(_testData.ProductId2); + var product = (await _productRepository.GetListAsync()).LastOrDefault(); + + await _productAppService.DeleteAsync(product.Id); - var result = await _productRepository.GetAsync(_testData.ProductId2); + var result = await _productRepository.FindAsync(product.Id); result.ShouldBeNull(); } diff --git a/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement/ProductManagementTestData.cs b/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement/ProductManagementTestData.cs index 14ad09731f..10db3e8c5c 100644 --- a/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement/ProductManagementTestData.cs +++ b/samples/MicroserviceDemo/modules/product/test/ProductManagement.TestBase/ProductManagement/ProductManagementTestData.cs @@ -5,8 +5,6 @@ namespace ProductManagement { public class ProductManagementTestData : ISingletonDependency { - public Guid ProductId1 { get; } = Guid.NewGuid(); - public string ProductCode1 { get; } = "ProductCode1"; public string ProductName1 { get; } = "ProductName1"; @@ -15,8 +13,6 @@ namespace ProductManagement public int ProductStockCount1 { get; } = 100; - public Guid ProductId2 { get; } = Guid.NewGuid(); - public string ProductCode2 { get; } = "ProductCode2"; public string ProductName2 { get; } = "ProductName2";