Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImplementGetTax_ValidData_ReturnsViewResults #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,10 +37,46 @@ public async Task AddTax_InvalidInput_ReturnsToSameActionWithValidation()
Assert.IsNotType<LocalRedirectResult>(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<UserManager<ApplicationUser>>(Substitute.For<IUserStore<ApplicationUser>>(), null, null, null, null, null, null, null, null);
var logger = Substitute.For<ILogger<TaxController>>();
var userTaxRepo = Substitute.For<IUserTaxRepository>();
var taxService = Substitute.For<ITaxService>();
var taxController = new TaxController(userManagerStub, logger, userTaxRepo, taxService);
var claimsPrincipal = Substitute.For<ClaimsPrincipal>();
ApplicationUser user = new ApplicationUser
{
UserName = "[email protected]",
Id = Guid.NewGuid().ToString(),
Email = "[email protected]"
};
_ = userManagerStub.GetUserAsync(claimsPrincipal).Returns(user);
const int year = 2000;
var userTax = new UserTax
{
CharityPaidAmount = 10,
NumberOfChildren = 0,
TaxDueAmount = 10,
TotalIncome = 3000,
Year = 2000
};
_ = 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);
Assert.IsType<ViewResult>(result);
}
}
}