public async Task GetCalculationsMetadataForSpecification_GivenItemsFoundInCache_ReturnsItemsFromCache()
        {
            //Arrange
            List <CalculationMetadata> calculations = new List <CalculationMetadata>
            {
                new CalculationMetadata(),
                new CalculationMetadata()
            };

            string cacheKey = $"{CacheKeys.CalculationsMetadataForSpecification}{SpecificationId}";

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <List <CalculationMetadata> >(Arg.Is(cacheKey))
            .Returns(calculations);

            ICalculationsRepository calculationsRepository = CreateCalculationsRepository();

            CalculationService calculationService = CreateCalculationService(
                cacheProvider: cacheProvider,
                calculationsRepository: calculationsRepository);

            //Act
            IActionResult actionResult = await calculationService.GetCalculationsMetadataForSpecification(SpecificationId);

            //Assert
            actionResult
            .Should()
            .BeAssignableTo <OkObjectResult>()
            .Which
            .Value
            .Should()
            .BeSameAs(calculations);

            await
            calculationsRepository
            .DidNotReceive()
            .GetCalculationsMetatadataBySpecificationId(Arg.Any <string>());
        }
        public async Task EditCalculationStatus_GivenStatusHasNoChanges_DoesNotUpdateReturnsOkResult()
        {
            //Arrange
            EditStatusModel CalculationEditStatusModel = new EditStatusModel
            {
                PublishStatus = PublishStatus.Approved
            };

            ILogger logger = CreateLogger();

            Calculation calculation = CreateCalculation();

            calculation.Current.PublishStatus = PublishStatus.Approved;

            ICalculationsRepository CalculationsRepository = CreateCalculationsRepository();

            CalculationsRepository
            .GetCalculationById(Arg.Is(CalculationId))
            .Returns(calculation);

            CalculationService service = CreateCalculationService(logger: logger, calculationsRepository: CalculationsRepository);

            //Act
            IActionResult result = await service.UpdateCalculationStatus(CalculationId, CalculationEditStatusModel);

            //Arrange
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .Be(calculation.Current);

            await
            CalculationsRepository
            .DidNotReceive()
            .UpdateCalculation(Arg.Any <Calculation>());
        }
        public async Task CreateCalculation_GivenNullCalculation_LogsDoesNotSave()
        {
            //Arrange
            Message message = new Message(new byte[0]);

            ICalculationsRepository repository = CreateCalculationsRepository();

            ILogger logger = CreateLogger();

            CalculationService service = CreateCalculationService(repository, logger);

            //Act
            await service.CreateCalculation(message);

            //Assert
            logger
            .Received(1)
            .Error("A null calculation was provided to CalculateFunding.Services.Calcs.CreateCalculation");

            await
            repository
            .DidNotReceive()
            .CreateDraftCalculation(Arg.Any <Calculation>());
        }
        public async Task EditCalculationStatus_GivenStatusHasntChanges_DoesNotUpdateReturnsOkResult()
        {
            //Arrange
            EditStatusModel CalculationEditStatusModel = new EditStatusModel
            {
                PublishStatus = PublishStatus.Approved
            };

            string json = JsonConvert.SerializeObject(CalculationEditStatusModel);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpContext context = Substitute.For <HttpContext>();

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

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

            request
            .Query
            .Returns(queryStringValues);
            request
            .Body
            .Returns(stream);

            request
            .HttpContext
            .Returns(context);

            ILogger logger = CreateLogger();

            Calculation calculation = CreateCalculation();

            calculation.Current.PublishStatus = PublishStatus.Approved;

            ICalculationsRepository CalculationsRepository = CreateCalculationsRepository();

            CalculationsRepository
            .GetCalculationById(Arg.Is(CalculationId))
            .Returns(calculation);

            CalculationService service = CreateCalculationService(logger: logger, calculationsRepository: CalculationsRepository);

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

            //Arrange
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .Be(calculation.Current);

            await
            CalculationsRepository
            .DidNotReceive()
            .UpdateCalculation(Arg.Any <Calculation>());
        }