Exemplo n.º 1
0
        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),
            });
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        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}"));
        }