public async Task GetCalculationByName_GivenSpecificationExistsAndCalculationExists_ReturnsSuccess() { //Arrange CalculationVersion calculationVersion = new CalculationVersion { Name = CalculationName, Date = new DateTimeOffset(2013, 1, 2, 3, 4, 55, TimeSpan.Zero), }; Calculation calc = new Calculation { Current = calculationVersion }; CalculationGetModel model = new CalculationGetModel { SpecificationId = SpecificationId, Name = CalculationName }; ILogger logger = CreateLogger(); ICalculationsRepository calculationsRepository = CreateCalculationsRepository(); calculationsRepository .GetCalculationsBySpecificationIdAndCalculationName(Arg.Is(SpecificationId), Arg.Is(CalculationName)) .Returns(calc); CalculationService service = CreateCalculationService(calculationsRepository: calculationsRepository, logger: logger); //Act IActionResult result = await service.GetCalculationByName(model); //Assert result .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeEquivalentTo(new CalculationResponseModel() { Name = CalculationName, SourceCode = "Return 0", LastUpdated = new DateTimeOffset(2013, 1, 2, 3, 4, 55, TimeSpan.Zero), }); }
public async Task GetCalculationByName_GivenModelDoesNotContainASpecificationId_ReturnsBadRequest() { //Arrange CalculationGetModel model = new CalculationGetModel(); ILogger logger = CreateLogger(); CalculationService service = CreateCalculationService(logger: logger); //Act IActionResult result = await service.GetCalculationByName(model); //Assert result .Should() .BeOfType <BadRequestObjectResult>(); logger .Received(1) .Error(Arg.Is("No specification id was provided to GetCalculationByName")); }
public async Task GetCalculationByName_GivenSpecificationExistsAndCalculationDoesNotExist_ReturnsNotFound() { //Arrange Calculation calc = new Calculation { Current = new CalculationVersion { Name = CalculationName } }; CalculationGetModel model = new CalculationGetModel { SpecificationId = SpecificationId, Name = CalculationName }; ILogger logger = CreateLogger(); ICalculationsRepository calculationsRepository = CreateCalculationsRepository(); calculationsRepository .GetCalculationsBySpecificationIdAndCalculationName(Arg.Is(SpecificationId), Arg.Is(CalculationName)) .Returns((Calculation)null); CalculationService service = CreateCalculationService(calculationsRepository: calculationsRepository, logger: logger); //Act IActionResult result = await service.GetCalculationByName(model); //Assert result .Should() .BeOfType <NotFoundResult>(); logger .Received(1) .Information(Arg.Is($"A calculation was not found for specification id {SpecificationId} and name {CalculationName}")); }