Ejemplo n.º 1
0
 public NewTaskToken(SpecificationVersion specVersion)
 {
     SpecificationVersion = specVersion;
 }
        public async Task CreateCalculation_GivenValidModelForSubPolicyAndSubPolicyFoundAndUpdated_ReturnsOK()
        {
            //Arrange
            AllocationLine allocationLine = new AllocationLine
            {
                Id   = "02a6eeaf-e1a0-476e-9cf9-8aa5d9129345",
                Name = "test alloctaion"
            };

            List <FundingStream> fundingStreams = new List <FundingStream>();

            FundingStream fundingStream = new FundingStream
            {
                AllocationLines = new List <AllocationLine>
                {
                    allocationLine
                },
                Id = FundingStreamId
            };

            fundingStreams.Add(fundingStream);

            Policy policy = new Policy
            {
                Id   = PolicyId,
                Name = PolicyName,
            };

            Specification specification = CreateSpecification();

            specification.Current.Policies       = new[] { policy };
            specification.Current.FundingStreams = new List <Reference>()
            {
                new Reference {
                    Id = FundingStreamId
                }
            };

            CalculationCreateModel model = new CalculationCreateModel
            {
                SpecificationId  = SpecificationId,
                PolicyId         = PolicyId,
                AllocationLineId = AllocationLineId
            };

            string json = JsonConvert.SerializeObject(model);

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

            ClaimsPrincipal principle = new ClaimsPrincipal(new[]
            {
                new ClaimsIdentity(new [] { new Claim(ClaimTypes.Sid, UserId), new Claim(ClaimTypes.Name, Username) })
            });

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

            context
            .User
            .Returns(principle);

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

            request
            .Body
            .Returns(stream);

            request
            .HttpContext
            .Returns(context);

            IHeaderDictionary headerDictionary = new HeaderDictionary();

            headerDictionary
            .Add("sfa-correlationId", new StringValues(SfaCorrelationId));

            request
            .Headers
            .Returns(headerDictionary);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationById(Arg.Is(SpecificationId))
            .Returns(specification);

            specificationsRepository
            .GetFundingStreams(Arg.Any <Expression <Func <FundingStream, bool> > >())
            .Returns(fundingStreams);

            specificationsRepository
            .UpdateSpecification(Arg.Is(specification))
            .Returns(HttpStatusCode.OK);

            Calculation calculation = new Calculation
            {
                AllocationLine = new Reference()
            };

            IMapper mapper = CreateMapper();

            mapper
            .Map <Calculation>(Arg.Any <CalculationCreateModel>())
            .Returns(calculation);

            IMessengerService messengerService = CreateMessengerService();

            SpecificationVersion newSpecVersion = specification.Current.Clone() as SpecificationVersion;

            newSpecVersion.PublishStatus = PublishStatus.Updated;
            newSpecVersion.Version       = 2;

            IVersionRepository <SpecificationVersion> mockVersionRepository = CreateVersionRepository();

            mockVersionRepository
            .CreateVersion(Arg.Any <SpecificationVersion>(), Arg.Any <SpecificationVersion>())
            .Returns(newSpecVersion);

            SpecificationsService service = CreateService(logs: logger, specificationsRepository: specificationsRepository,
                                                          mapper: mapper, messengerService: messengerService, specificationVersionRepository: mockVersionRepository);

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

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

            await
            messengerService
            .Received(1)
            .SendToQueue(Arg.Is("calc-events-create-draft"),
                         Arg.Is <Models.Calcs.Calculation>(m =>
                                                           m.CalculationSpecification.Id == calculation.Id &&
                                                           m.CalculationSpecification.Name == calculation.Name &&
                                                           m.Name == calculation.Name &&
                                                           !string.IsNullOrEmpty(m.Id) &&
                                                           m.AllocationLine.Id == allocationLine.Id &&
                                                           m.AllocationLine.Name == allocationLine.Name),
                         Arg.Is <IDictionary <string, string> >(m =>
                                                                m["user-id"] == UserId &&
                                                                m["user-name"] == Username &&
                                                                m["sfa-correlationId"] == SfaCorrelationId));
        }
        public void CreateCalculation_WhenSomethingGoesWrongDuringIndexing_ShouldThrowException()
        {
            //Arrange
            const string errorMessage = "Encountered 802 error code";

            AllocationLine allocationLine = new AllocationLine
            {
                Id   = "02a6eeaf-e1a0-476e-9cf9-8aa5d9129345",
                Name = "test alloctaion"
            };

            List <FundingStream> fundingStreams = new List <FundingStream>();

            FundingStream fundingStream = new FundingStream
            {
                AllocationLines = new List <AllocationLine>
                {
                    allocationLine
                },
                Id = FundingStreamId
            };

            fundingStreams.Add(fundingStream);

            Policy policy = new Policy
            {
                Id   = PolicyId,
                Name = PolicyName,
            };

            Specification specification = CreateSpecification();

            specification.Current.Policies       = new[] { policy };
            specification.Current.FundingStreams = new List <Reference>()
            {
                new Reference {
                    Id = FundingStreamId
                }
            };

            CalculationCreateModel model = new CalculationCreateModel
            {
                SpecificationId  = SpecificationId,
                PolicyId         = PolicyId,
                AllocationLineId = AllocationLineId
            };

            string json = JsonConvert.SerializeObject(model);

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

            ClaimsPrincipal principle = new ClaimsPrincipal(new[]
            {
                new ClaimsIdentity(new [] { new Claim(ClaimTypes.Sid, UserId), new Claim(ClaimTypes.Name, Username) })
            });

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

            context
            .User
            .Returns(principle);

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

            request
            .Body
            .Returns(stream);

            request
            .HttpContext
            .Returns(context);

            IHeaderDictionary headerDictionary = new HeaderDictionary();

            headerDictionary
            .Add("sfa-correlationId", new StringValues(SfaCorrelationId));

            request
            .Headers
            .Returns(headerDictionary);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationById(Arg.Is(SpecificationId))
            .Returns(specification);

            specificationsRepository
            .GetFundingStreams(Arg.Any <Expression <Func <FundingStream, bool> > >())
            .Returns(fundingStreams);

            specificationsRepository
            .UpdateSpecification(Arg.Is(specification))
            .Returns(HttpStatusCode.OK);

            Calculation calculation = new Calculation
            {
                AllocationLine = new Reference()
            };

            IMapper mapper = CreateMapper();

            mapper
            .Map <Calculation>(Arg.Any <CalculationCreateModel>())
            .Returns(calculation);

            IMessengerService messengerService = CreateMessengerService();

            ISearchRepository <SpecificationIndex> mockSearchRepository = CreateSearchRepository();

            mockSearchRepository
            .Index(Arg.Any <IEnumerable <SpecificationIndex> >())
            .Returns(new List <IndexError>()
            {
                new IndexError()
                {
                    ErrorMessage = errorMessage
                }
            });

            SpecificationVersion newSpecVersion = specification.Current.Clone() as SpecificationVersion;

            newSpecVersion.PublishStatus = PublishStatus.Updated;
            newSpecVersion.Version       = 2;
            IVersionRepository <SpecificationVersion> mockVersionRepository = CreateVersionRepository();

            mockVersionRepository
            .CreateVersion(Arg.Any <SpecificationVersion>(), Arg.Any <SpecificationVersion>())
            .Returns(newSpecVersion);

            SpecificationsService service = CreateService(logs: logger, specificationsRepository: specificationsRepository,
                                                          mapper: mapper, messengerService: messengerService, specificationVersionRepository: mockVersionRepository, searchRepository: mockSearchRepository);


            //Act
            Func <Task <IActionResult> > createCalculation = async() => await service.CreateCalculation(request);

            //Assert
            createCalculation
            .Should()
            .Throw <ApplicationException>()
            .Which
            .Message
            .Should()
            .Be($"Could not index specification {specification.Current.Id} because: {errorMessage}");
        }
        public async Task SpecificationsService_CreateSpecification_WhenValidInputProvided_ThenSpecificationIsCreated()
        {
            // Arrange
            const string fundingStreamId = "fs1";
            const string fundingPeriodId = "fp1";


            ISpecificationsRepository specificationsRepository      = CreateSpecificationsRepository();
            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            IMapper mapper = CreateImplementedMapper();
            IVersionRepository <SpecificationVersion> versionRepository = CreateVersionRepository();

            SpecificationsService specificationsService = CreateService(
                specificationsRepository: specificationsRepository,
                searchRepository: searchRepository,
                mapper: mapper,
                specificationVersionRepository: versionRepository);

            SpecificationCreateModel specificationCreateModel = new SpecificationCreateModel()
            {
                Name             = "Specification Name",
                Description      = "Specification Description",
                FundingPeriodId  = "fp1",
                FundingStreamIds = new List <string>()
                {
                    fundingStreamId
                },
            };

            string json = JsonConvert.SerializeObject(specificationCreateModel);

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

            ClaimsPrincipal principle = new ClaimsPrincipal(new[]
            {
                new ClaimsIdentity(new [] { new Claim(ClaimTypes.Sid, UserId), new Claim(ClaimTypes.Name, Username) })
            });

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

            context
            .User
            .Returns(principle);

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

            request
            .Body
            .Returns(stream);

            request
            .HttpContext
            .Returns(context);

            specificationsRepository
            .GetSpecificationByQuery(Arg.Any <Expression <Func <Specification, bool> > >())
            .Returns((Specification)null);

            Period fundingPeriod = new Period()
            {
                Id   = fundingPeriodId,
                Name = "Funding Period 1"
            };

            specificationsRepository
            .GetPeriodById(Arg.Is(fundingPeriodId))
            .Returns(fundingPeriod);

            FundingStream fundingStream = new FundingStream()
            {
                Id              = fundingStreamId,
                Name            = "Funding Stream 1",
                AllocationLines = new List <AllocationLine>(),
            };

            specificationsRepository
            .GetFundingStreamById(Arg.Is(fundingStreamId))
            .Returns(fundingStream);

            DateTime createdDate = new DateTime(2018, 1, 2, 5, 6, 2);

            SpecificationVersion specificationVersion = new SpecificationVersion()
            {
                Description    = "Specification Description",
                FundingPeriod  = new Reference("fp1", "Funding Period 1"),
                Date           = createdDate,
                PublishStatus  = Models.Versioning.PublishStatus.Draft,
                FundingStreams = new List <Reference>()
                {
                    new Reference(FundingStreamId, "Funding Stream 1")
                },
                Name            = "Specification Name",
                Version         = 1,
                SpecificationId = SpecificationId
            };

            versionRepository
            .CreateVersion(Arg.Any <SpecificationVersion>())
            .Returns(specificationVersion);

            DocumentEntity <Specification> createdSpecification = new DocumentEntity <Specification>()
            {
                Content = new Specification()
                {
                    Name    = "Specification Name",
                    Id      = "createdSpec",
                    Current = specificationVersion
                },
            };

            specificationsRepository
            .CreateSpecification(Arg.Is <Specification>(
                                     s => s.Name == specificationCreateModel.Name &&
                                     s.Current.Description == specificationCreateModel.Description &&
                                     s.Current.FundingPeriod.Id == fundingPeriodId))
            .Returns(createdSpecification);

            // Act
            IActionResult result = await specificationsService.CreateSpecification(request);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .BeOfType <SpecificationCurrentVersion>()
            .And
            .NotBeNull();

            await specificationsRepository
            .Received(1)
            .CreateSpecification(Arg.Is <Specification>(
                                     s => s.Name == specificationCreateModel.Name &&
                                     s.Current.Description == specificationCreateModel.Description &&
                                     s.Current.FundingPeriod.Id == fundingPeriodId));

            await searchRepository
            .Received(1)
            .Index(Arg.Is <List <SpecificationIndex> >(c =>
                                                       c.Count() == 1 &&
                                                       !string.IsNullOrWhiteSpace(c.First().Id) &&
                                                       c.First().Name == specificationCreateModel.Name
                                                       ));

            await versionRepository
            .Received(1)
            .SaveVersion(Arg.Is <SpecificationVersion>(
                             m => !string.IsNullOrWhiteSpace(m.EntityId) &&
                             m.PublishStatus == Models.Versioning.PublishStatus.Draft &&
                             m.Description == "Specification Description" &&
                             m.FundingPeriod.Id == "fp1" &&
                             m.FundingPeriod.Name == "Funding Period 1" &&
                             m.FundingStreams.Any() &&
                             m.Name == "Specification Name" &&
                             m.Version == 1
                             ));
        }
Ejemplo n.º 5
0
 private bool IsCerx(StandardDataType standardDataType, VersionNumber version)
 {
     return(SpecificationVersion.IsVersion(standardDataType, version, Hl7BaseVersion.CERX));
 }
Ejemplo n.º 6
0
        public void EditSpecificationStatus_GivenSomethingGoesWrongDuringIndexing_ShouldThrowException()
        {
            //Arrange
            const string errorMessage = "Encountered 802 error code";

            EditStatusModel specificationEditStatusModel = new EditStatusModel
            {
                PublishStatus = PublishStatus.Approved
            };

            string json = JsonConvert.SerializeObject(specificationEditStatusModel);

            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>
            {
                { "specificationId", new StringValues(SpecificationId) },
            });

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

            request
            .HttpContext
            .Returns(context);

            ILogger logger = CreateLogger();

            Specification specification = CreateSpecification();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationById(Arg.Is(SpecificationId))
            .Returns(specification);

            specificationsRepository
            .UpdateSpecification(Arg.Any <Specification>())
            .Returns(HttpStatusCode.OK);

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Index(Arg.Any <IEnumerable <SpecificationIndex> >())
            .Returns(new[] { new IndexError()
                             {
                                 ErrorMessage = errorMessage
                             } });

            SpecificationVersion newSpecVersion = specification.Current.Clone() as SpecificationVersion;

            newSpecVersion.PublishStatus = PublishStatus.Approved;

            IVersionRepository <SpecificationVersion> versionRepository = CreateVersionRepository();

            versionRepository
            .CreateVersion(Arg.Any <SpecificationVersion>(), Arg.Any <SpecificationVersion>())
            .Returns(newSpecVersion);

            SpecificationsService service = CreateService(
                logs: logger, specificationsRepository: specificationsRepository, searchRepository: searchRepository, specificationVersionRepository: versionRepository);

            // Act
            Func <Task <IActionResult> > editSpecificationStatus = async() => await service.EditSpecificationStatus(request);

            // Assert
            editSpecificationStatus
            .Should()
            .Throw <ApplicationException>()
            .Which
            .Message
            .Should()
            .Be($"Could not index specification {specification.Current.Id} because: {errorMessage}");
        }
        public async Task Run(
            SpecificationVersion specificationVersion,
            Reference user,
            string correlationId,
            bool triggerProviderSnapshotDataLoadJob,
            bool triggerCalculationEngineRunJob)
        {
            string    errorMessage   = $"Unable to queue ProviderSnapshotDataLoadJob for specification - {specificationVersion.SpecificationId}";
            string    triggerMessage = $"Assigning ProviderVersionId for specification: {specificationVersion.SpecificationId}";
            Reference fundingStream  = specificationVersion.FundingStreams.FirstOrDefault();

            if (fundingStream != null && (specificationVersion.ProviderSource == Models.Providers.ProviderSource.FDZ || triggerProviderSnapshotDataLoadJob))
            {
                Job createProviderSnapshotDataLoadJob = await CreateJob(errorMessage,
                                                                        NewJobCreateModel(specificationVersion.SpecificationId,
                                                                                          triggerMessage,
                                                                                          JobConstants.DefinitionNames.ProviderSnapshotDataLoadJob,
                                                                                          correlationId,
                                                                                          user,
                                                                                          new Dictionary <string, string>
                {
                    { "specification-id", specificationVersion.SpecificationId },
                    { "fundingstream-id", fundingStream.Id },
                    { "providerSanpshot-id", specificationVersion.ProviderSnapshotId?.ToString() },
                    { "disableQueueCalculationJob", (!triggerCalculationEngineRunJob).ToString() }
                }));

                GuardAgainstNullJob(createProviderSnapshotDataLoadJob, errorMessage);
            }

            if (specificationVersion.ProviderSource == Models.Providers.ProviderSource.CFS && !string.IsNullOrWhiteSpace(specificationVersion.ProviderVersionId))
            {
                ApiResponse <IEnumerable <DatasetSpecificationRelationshipViewModel> > response =
                    await _datasetsPolicy.ExecuteAsync(() => _datasets.GetRelationshipsBySpecificationId(specificationVersion.SpecificationId));

                DatasetSpecificationRelationshipViewModel providerRelationship = response?.Content?.Where(_ => _.IsProviderData).FirstOrDefault();

                if (providerRelationship != null)
                {
                    ApiResponse <DatasetViewModel> datasetResponse =
                        await _datasetsPolicy.ExecuteAsync(() => _datasets.GetDatasetByDatasetId(providerRelationship.DatasetId));

                    if (datasetResponse?.StatusCode.IsSuccess() == false || datasetResponse?.Content == null)
                    {
                        errorMessage = $"Unable to retrieve dataset for specification {specificationVersion.SpecificationId}";
                        _logger.Error(errorMessage);
                        throw new Exception(errorMessage);
                    }

                    errorMessage = $"Unable to queue MapScopedDatasetJob for specification - {specificationVersion.SpecificationId}";
                    Job mapScopedDatasetJob = await CreateJob(errorMessage,
                                                              NewJobCreateModel(specificationVersion.SpecificationId,
                                                                                triggerMessage,
                                                                                JobConstants.DefinitionNames.MapScopedDatasetJob,
                                                                                correlationId,
                                                                                user,
                                                                                new Dictionary <string, string>
                    {
                        { "specification-id", specificationVersion.SpecificationId },
                        { "provider-cache-key", $"{CacheKeys.ScopedProviderSummariesPrefix}{specificationVersion.SpecificationId}" },
                        { "specification-summary-cache-key", $"{CacheKeys.SpecificationSummaryById}{specificationVersion.SpecificationId}" },
                        { "disableQueueCalculationJob", (!triggerCalculationEngineRunJob).ToString() },
                    }));

                    GuardAgainstNullJob(mapScopedDatasetJob, errorMessage);

                    errorMessage = $"Unable to queue MapDatasetJob for specification - {specificationVersion.SpecificationId}";
                    Job mapDataset = await CreateJob(errorMessage, NewJobCreateModel(specificationVersion.SpecificationId,
                                                                                     triggerMessage,
                                                                                     JobConstants.DefinitionNames.MapDatasetJob,
                                                                                     correlationId,
                                                                                     user,
                                                                                     new Dictionary <string, string>
                    {
                        { "specification-id", specificationVersion.SpecificationId },
                        { "relationship-id", providerRelationship.Id },
                        { "user-id", user?.Id },
                        { "user-name", user?.Name },
                        { "parentJobId", mapScopedDatasetJob.Id },
                        { "disableQueueCalculationJob", (!triggerCalculationEngineRunJob).ToString() },
                    },
                                                                                     mapScopedDatasetJob.Id,
                                                                                     messageBody : JsonConvert.SerializeObject(datasetResponse.Content)));

                    GuardAgainstNullJob(mapDataset, errorMessage);
                }
            }
        }
Ejemplo n.º 8
0
        public async Task EditSpecificationStatus_GivenNewStatusOfUpdated_UpdatesSearchReturnsOK()
        {
            //Arrange
            EditStatusModel specificationEditStatusModel = new EditStatusModel
            {
                PublishStatus = PublishStatus.Updated
            };

            string json = JsonConvert.SerializeObject(specificationEditStatusModel);

            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>
            {
                { "specificationId", new StringValues(SpecificationId) },
            });

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

            request
            .HttpContext
            .Returns(context);

            ILogger logger = CreateLogger();

            Specification specification = CreateSpecification();

            SpecificationVersion specificationVersion = specification.Current;

            specificationVersion.PublishStatus = PublishStatus.Approved;

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationById(Arg.Is(SpecificationId))
            .Returns(specification);

            specificationsRepository
            .UpdateSpecification(Arg.Any <Specification>())
            .Returns(HttpStatusCode.OK);

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            SpecificationVersion newSpecVersion = specificationVersion.Clone() as SpecificationVersion;

            newSpecVersion.PublishStatus = PublishStatus.Updated;

            IVersionRepository <SpecificationVersion> versionRepository = CreateVersionRepository();

            versionRepository
            .CreateVersion(Arg.Any <SpecificationVersion>(), Arg.Any <SpecificationVersion>())
            .Returns(newSpecVersion);

            SpecificationsService service = CreateService(
                logs: logger, specificationsRepository: specificationsRepository, searchRepository: searchRepository, specificationVersionRepository: versionRepository);

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

            //Arrange
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .BeOfType <PublishStatusResultModel>()
            .Which
            .PublishStatus
            .Should()
            .Be(PublishStatus.Updated);

            specification
            .Current
            .PublishStatus
            .Should()
            .Be(PublishStatus.Updated);

            await
            searchRepository
            .Received(1)
            .Index(Arg.Is <IEnumerable <SpecificationIndex> >(m => m.First().Status == "Updated"));

            await
            versionRepository
            .Received(1)
            .SaveVersion(Arg.Is(newSpecVersion));
        }
 private async Task WhenTemplateVersionChangeIsHandled(SpecificationVersion previousSpecificationVersion,
                                                       SpecificationVersion specificationVersion,
                                                       IDictionary <string, string> assignedTemplateIds,
                                                       Reference user,
                                                       string correlationId)
 => await _changedHandler.HandleTemplateVersionChanged(previousSpecificationVersion, specificationVersion, assignedTemplateIds, user, correlationId);
 private void AndTheSpecVersionTemplateVersionsAssigned(SpecificationVersion specificationVersion, string fundingStreamId, string expectedVersion)
 {
     specificationVersion.TemplateIds[fundingStreamId]
     .Should()
     .Be(expectedVersion);
 }
Ejemplo n.º 11
0
        public async Task QueuesParentJobAndAssignCalculationsJobsWhereConfigurationHasADefaultTemplateVersion()
        {
            string fundingStream1 = NewRandomString();
            string fundingStream2 = NewRandomString();
            string fundingStream3 = NewRandomString();

            string specificationId = NewRandomString();

            string[] fundingStreamIds =
            {
                fundingStream1,
                fundingStream2,
                fundingStream3
            };

            string templateVersion1 = NewRandomString();
            string templateVersion2 = NewRandomString();

            string fundingPeriodId = NewRandomString();

            uint templateCalculationId1 = NewRandomUint();
            uint templateCalculationId2 = NewRandomUint();
            uint templateCalculationId3 = NewRandomUint();
            uint templateCalculationId4 = NewRandomUint();
            uint templateCalculationId5 = NewRandomUint();

            SpecificationVersion specificationVersion = NewSpecificationVersion(_ => _.WithSpecificationId(specificationId)
                                                                                .WithFundingStreamsIds(fundingStreamIds)
                                                                                .WithFundingPeriodId(fundingPeriodId)
                                                                                .WithTemplateIds((fundingStream1, templateVersion1), (fundingStream3, templateVersion2)));

            string expectedParentJobId = NewRandomString();

            Job createSpecificationJob = NewJob(_ => _.WithId(expectedParentJobId));

            GivenTheFundingTemplateContentsForPeriodAndStream(fundingPeriodId, fundingStream1,
                                                              templateVersion1,
                                                              NewTemplateMetadataContents(_ => _.WithFundingLines(
                                                                                              NewFundingLine(fl => fl.WithCalculations(NewCalculation(cal => cal.WithReferenceData(NewReferenceData(), NewReferenceData()).WithTemplateCalculationId(templateCalculationId1)))),
                                                                                              NewFundingLine(fl => fl.WithCalculations(NewCalculation(cal => cal.WithTemplateCalculationId(templateCalculationId2)), NewCalculation(cal => cal.WithTemplateCalculationId(templateCalculationId3))))))); //item count 5
            AndTheFundingTemplateContentsForPeriodAndStream(fundingPeriodId, fundingStream2, string.Empty, NewTemplateMetadataContents());
            AndTheFundingTemplateContentsForPeriodAndStream(fundingPeriodId, fundingStream3,
                                                            templateVersion2,
                                                            NewTemplateMetadataContents(_ => _.WithFundingLines(
                                                                                            NewFundingLine(fl => fl.WithCalculations(NewCalculation(cal => cal.WithReferenceData(NewReferenceData()).WithTemplateCalculationId(templateCalculationId4)))),
                                                                                            NewFundingLine(fl => fl.WithCalculations(NewCalculation(cal => cal.WithTemplateCalculationId(templateCalculationId5))))))); //item count 3


            AndTheJobIsCreatedForARequestModelMatching(CreateJobModelMatching(_ => _.JobDefinitionId == JobConstants.DefinitionNames.CreateSpecificationJob &&
                                                                              HasProperty(_, SpecificationId, specificationId) &&
                                                                              _.ParentJobId == null),
                                                       createSpecificationJob);

            await WhenTheQueueCreateSpecificationJobActionIsRun(specificationVersion, _user, _correlationId);

            await ThenTheAssignTemplateCalculationJobWasCreated(
                CreateJobModelMatching(_ => _.JobDefinitionId == AssignTemplateCalculationsJob &&
                                       _.ParentJobId == expectedParentJobId &&
                                       _.ItemCount == 5 &&
                                       HasProperty(_, TemplateVersion, templateVersion1) &&
                                       HasProperty(_, SpecificationId, specificationId) &&
                                       HasProperty(_, FundingStreamId, fundingStream1) &&
                                       HasProperty(_, FundingPeriodId, fundingPeriodId)));
            await AndTheAssignTemplateCalculationJobWasCreated(
                CreateJobModelMatching(_ => _.JobDefinitionId == AssignTemplateCalculationsJob &&
                                       _.ParentJobId == expectedParentJobId &&
                                       _.ItemCount == 3 &&
                                       HasProperty(_, TemplateVersion, templateVersion2) &&
                                       HasProperty(_, SpecificationId, specificationId) &&
                                       HasProperty(_, FundingStreamId, fundingStream3) &&
                                       HasProperty(_, FundingPeriodId, fundingPeriodId)));
            await AndTheAssignTemplateCalculationJobWasNotCreated(
                CreateJobModelMatching(_ => _.JobDefinitionId == AssignTemplateCalculationsJob &&
                                       _.ParentJobId == expectedParentJobId &&
                                       HasProperty(_, SpecificationId, specificationId) &&
                                       HasProperty(_, FundingStreamId, fundingStream2) &&
                                       HasProperty(_, FundingPeriodId, fundingPeriodId)));
        }
Ejemplo n.º 12
0
 private async Task WhenTheQueueCreateSpecificationJobActionIsRun(SpecificationVersion specificationVersion,
                                                                  Reference user,
                                                                  string correlationId)
 {
     await _action.Run(specificationVersion, user, correlationId);
 }