private void SetupMocks()
            {
                _validatorFactory = Substitute.For <IIoCValidatorFactory>();
                _validatorFactory.Validate(Arg.Any <object>()).Returns(new ValidationResult());
                _templateRepository = Substitute.For <ITemplateRepository>();
                _templateRepository.Update(Arg.Any <Template>()).Returns(HttpStatusCode.OK);
                _templateVersionPrevious = new TemplateVersion
                {
                    Name          = "Previous Version Test Name",
                    TemplateId    = _templateId,
                    Version       = 32,
                    MinorVersion  = 2,
                    MajorVersion  = 1,
                    TemplateJson  = "{ \"Lorem\": \"ipsum\" }",
                    SchemaVersion = "1.1",
                    Status        = TemplateStatus.Draft,
                    Author        = new Reference("111", "FirstTestUser")
                };
                _templateVersionCurrent = new TemplateVersion
                {
                    Name          = "Current Version Test Name",
                    TemplateId    = _templateId,
                    Version       = 46,
                    MinorVersion  = 16,
                    MajorVersion  = 2,
                    TemplateJson  = "{ \"Lorem\": \"ipsum\" }",
                    SchemaVersion = "1.1",
                    Status        = TemplateStatus.Draft,
                    Author        = new Reference("111", "FirstTestUser")
                };
                _templateBeforeUpdate = new Template
                {
                    Name          = _templateVersionPrevious.Name,
                    TemplateId    = _templateVersionPrevious.TemplateId,
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    Current = _templateVersionCurrent
                };
                _templateRepository.GetTemplate(Arg.Is(_templateId)).Returns(_templateBeforeUpdate);
                _templateRepository.Update(Arg.Any <Template>()).Returns(HttpStatusCode.OK);

                _versionRepository = Substitute.For <ITemplateVersionRepository>();
                _versionRepository.GetTemplateVersion(Arg.Is(_templateId), Arg.Is(_templateVersionPrevious.Version))
                .Returns(_templateVersionPrevious);
                _versionRepository.SaveVersion(Arg.Any <TemplateVersion>()).Returns(HttpStatusCode.OK);
                _templateBlobService = Substitute.For <ITemplateBlobService>();
                _templateBlobService.PublishTemplate(Arg.Any <Template>()).Returns(CommandResult.Success());
            }
Exemplo n.º 2
0
            public When_i_request_previous_version_of_template()
            {
                _templateVersionPrevious = new TemplateVersion
                {
                    Name            = "Test Name 1",
                    TemplateId      = "123",
                    TemplateJson    = null,
                    Version         = 1,
                    SchemaVersion   = "1.1",
                    FundingPeriodId = "12345",
                    Status          = TemplateStatus.Draft,
                    Author          = new Reference("111", "FirstTestUser")
                };
                _templateVersionCurrent = new TemplateVersion
                {
                    Name            = "Test Name 2",
                    TemplateId      = "456",
                    TemplateJson    = null,
                    Version         = 2,
                    SchemaVersion   = "1.1",
                    FundingPeriodId = "12345",
                    Status          = TemplateStatus.Draft,
                    Author          = new Reference("222", "SecondTestUser")
                };
                _template = new Template
                {
                    TemplateId    = _templateVersionPrevious.TemplateId,
                    Name          = _templateVersionPrevious.Name,
                    Description   = "Description",
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    Current = _templateVersionCurrent
                };
                _templateVersionRepository = Substitute.For <ITemplateVersionRepository>();
                _templateVersionRepository.GetTemplateVersion(
                    Arg.Is(_templateVersionPrevious.TemplateId),
                    Arg.Is(_templateVersionPrevious.Version)).Returns(_templateVersionPrevious);
                _templateRepository = Substitute.For <ITemplateRepository>();
                _templateRepository.GetTemplate(Arg.Is(_template.TemplateId)).Returns(_template);

                _service = new TemplateBuilderService(
                    Substitute.For <IIoCValidatorFactory>(),
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    _templateVersionRepository,
                    _templateRepository,
                    Substitute.For <ISearchRepository <TemplateIndex> >(),
                    Substitute.For <IPolicyRepository>(),
                    Substitute.For <ITemplateBlobService>(),
                    Substitute.For <ILogger>());

                _result = _service
                          .GetTemplateVersion(_templateVersionPrevious.TemplateId, _templateVersionPrevious.Version.ToString())
                          .GetAwaiter()
                          .GetResult();
            }