async public Task GetCalculationHistory_GivenCalculationIdWasProvidedButHistoryWasNull_ReturnsNotFound()
        {
            //Arrange
            ILogger logger = CreateLogger();

            IVersionRepository <CalculationVersion> versionsRepository = CreateCalculationVersionRepository();

            versionsRepository
            .GetVersions(Arg.Is(CalculationId))
            .Returns((IEnumerable <CalculationVersion>)null);

            CalculationService service = CreateCalculationService(logger: logger, calculationVersionRepository: versionsRepository);

            //Act
            IActionResult result = await service.GetCalculationHistory(CalculationId);

            //Assert
            result
            .Should()
            .BeOfType <NotFoundResult>();

            logger
            .Received(1)
            .Information(Arg.Is($"A calculation was not found for calculation id {CalculationId}"));
        }
        async public Task GetCalculationHistory_GivenCalculationIdWasProvided_ReturnsOK()
        {
            //Arrange
            IEnumerable <CalculationVersion> versions = new List <CalculationVersion>
            {
                new CalculationVersion(),
                new CalculationVersion()
            };

            ILogger logger = CreateLogger();

            IVersionRepository <CalculationVersion> versionsRepository = CreateCalculationVersionRepository();

            versionsRepository
            .GetVersions(Arg.Is(CalculationId))
            .Returns(versions);

            CalculationService service = CreateCalculationService(logger: logger, calculationVersionRepository: versionsRepository);

            //Act
            IActionResult result = await service.GetCalculationHistory(CalculationId);

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
        async public Task GetCalculationHistory_GivenNoCalculationIdWasProvided_ReturnsBadRequest()
        {
            //Arrange
            ILogger logger = CreateLogger();

            CalculationService service = CreateCalculationService(logger: logger);

            //Act
            IActionResult result = await service.GetCalculationHistory(null);

            //Assert
            result
            .Should()
            .BeOfType <BadRequestObjectResult>();

            logger
            .Received(1)
            .Error(Arg.Is("No calculation Id was provided to GetCalculationHistory"));
        }
Ejemplo n.º 4
0
        async public Task GetCalculationHistory_GivenCalculationIdWasProvided_ReturnsOK()
        {
            //Arrange
            IEnumerable <CalculationVersion> versions = new List <CalculationVersion>
            {
                new CalculationVersion(),
                new CalculationVersion()
            };

            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "calculationId", new StringValues(CalculationId) }
            });

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            IVersionRepository <CalculationVersion> versionsRepository = CreateCalculationVersionRepository();

            versionsRepository
            .GetVersions(Arg.Is(CalculationId))
            .Returns(versions);

            CalculationService service = CreateCalculationService(logger: logger, calculationVersionRepository: versionsRepository);

            //Act
            IActionResult result = await service.GetCalculationHistory(request);

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
Ejemplo n.º 5
0
        async public Task GetCalculationHistory_GivenCalculationIdWasProvidedButHistoryWasNull_ReturnsNotFound()
        {
            //Arrange
            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "calculationId", new StringValues(CalculationId) }
            });

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            IVersionRepository <CalculationVersion> versionsRepository = CreateCalculationVersionRepository();

            versionsRepository
            .GetVersions(Arg.Is(CalculationId))
            .Returns((IEnumerable <CalculationVersion>)null);

            CalculationService service = CreateCalculationService(logger: logger, calculationVersionRepository: versionsRepository);

            //Act
            IActionResult result = await service.GetCalculationHistory(request);

            //Assert
            result
            .Should()
            .BeOfType <NotFoundResult>();

            logger
            .Received(1)
            .Information(Arg.Is($"A calculation was not found for calculation id {CalculationId}"));
        }