From 28b84cce90d5e7caff5d8d472ff34aa29d4b4e68 Mon Sep 17 00:00:00 2001 From: Yasmin Mohamed Date: Tue, 4 Aug 2020 16:54:46 +0200 Subject: [PATCH 1/2] ImplementGetTax_ValidData_ReturnsViewResults --- .../Controllers/TaxControllerTests.cs | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs b/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs index 57a0eb1..0fa4f00 100644 --- a/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs +++ b/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System; +using System.Security.Claims; +using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -35,10 +37,46 @@ public async Task AddTax_InvalidInput_ReturnsToSameActionWithValidation() Assert.IsNotType(result); } - [Fact(Skip = "To be done by you, remove Skip property in the Fact attribute to be able to run this method and see it in text explorer")] + [Fact] public async Task GetTax_ValidData_ReturnsViewResults() { // TODO try to stub all dependencies inside GetTax Action inside Tax Controller :) + var userManagerStub = Substitute.For>(Substitute.For>(), null, null, null, null, null, null, null, null); + var logger = Substitute.For>(); + var userTaxRepo = Substitute.For(); + var taxService = Substitute.For(); + var taxController = new TaxController(userManagerStub, logger, userTaxRepo, taxService); + var claimsPrincipal = Substitute.For(); + ApplicationUser user = new ApplicationUser + { + UserName = "test@test.it", + Id = Guid.NewGuid().ToString(), + Email = "test@test.it" + }; + _ = userManagerStub.GetUserAsync(claimsPrincipal).Returns(user); + const int year = 2000; + var userTax = new UserTax + { + CharityPaidAmount = 10, + NumberOfChildren = 0, + TaxDueAmount = 10, + TotalIncome = 3000, + Year = 2020 + }; + _ = userTaxRepo.GetUserTax(user.Id, year).Returns(userTax); + + //var taxViewResult = new TaxViewModel + //{ + // CharityPaidAmount = userTax.CharityPaidAmount, + // NumberOfChildren = userTax.NumberOfChildren, + // TotalIncome = userTax.TotalIncome, + // Year = userTax.Year, + // TaxDueAmount = userTax.TaxDueAmount + //}; + + //I think we don't need to use taxViewResult and i want to know diff btn .Received() and .Returns() + var result = await taxController.GetTax(year).Received(); + Assert.IsType(result); } } } From f7569fe3416e99126731fe0de227c41611f69b82 Mon Sep 17 00:00:00 2001 From: Yasmin Mohamed Date: Sat, 8 Aug 2020 00:36:46 +0200 Subject: [PATCH 2/2] change year value --- .../Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs b/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs index 0fa4f00..be3bbe6 100644 --- a/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs +++ b/Workspace/Tax/Tax.Tests.UnitTests/Controllers/TaxControllerTests.cs @@ -61,7 +61,7 @@ public async Task GetTax_ValidData_ReturnsViewResults() NumberOfChildren = 0, TaxDueAmount = 10, TotalIncome = 3000, - Year = 2020 + Year = 2000 }; _ = userTaxRepo.GetUserTax(user.Id, year).Returns(userTax); @@ -75,7 +75,7 @@ public async Task GetTax_ValidData_ReturnsViewResults() //}; //I think we don't need to use taxViewResult and i want to know diff btn .Received() and .Returns() - var result = await taxController.GetTax(year).Received(); + var result = await taxController.GetTax(year); Assert.IsType(result); } }