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()); }
private void SetupMocks() { _validatorFactory = Substitute.For <IIoCValidatorFactory>(); _validatorFactory.Validate(Arg.Any <object>()).Returns(new ValidationResult()); _templateRepository = Substitute.For <ITemplateRepository>(); _templateVersionFirst = new TemplateVersion { Name = "XXX 20-21", TemplateId = _command.TemplateId, TemplateJson = null, Version = 1, MinorVersion = 1, MajorVersion = 0, SchemaVersion = "1.1", FundingStreamId = "XX", FundingPeriodId = "20-21", Status = TemplateStatus.Published, Author = new Reference("111", "FirstTestUser") }; _templateBeforeUpdate = new Template { Name = "Template Name", Description = "Description", TemplateId = _command.TemplateId, FundingPeriod = new FundingPeriod { Id = "20-21", Name = "Test Period", Type = FundingPeriodType.FY }, FundingStream = new FundingStream { Id = "XX", ShortName = "XX", Name = "FundingSteam" }, Current = _templateVersionFirst }; _templateMetadataGenerator = Substitute.For <ITemplateMetadataGenerator>(); _templateMetadataGenerator.Validate(Arg.Any <string>()).Returns(new ValidationResult()); _templateMetadataResolver = Substitute.For <ITemplateMetadataResolver>(); _templateMetadataResolver.GetService(Arg.Any <string>()).Returns(_templateMetadataGenerator); _templateValidationService = Substitute.For <IFundingTemplateValidationService>(); _templateValidationService.ValidateFundingTemplate(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), null).Returns(new FundingTemplateValidationResult { }); _templateRepository.GetTemplate(Arg.Is(_command.TemplateId)).Returns(_templateBeforeUpdate); _templateRepository.Update(Arg.Do <Template>(x => _savedTemplate = x)).Returns(HttpStatusCode.OK); _versionRepository = Substitute.For <ITemplateVersionRepository>(); _versionRepository.SaveVersion(Arg.Do <TemplateVersion>(x => _savedTemplateVersion = x)).Returns(HttpStatusCode.OK); _searchRepository = Substitute.For <ISearchRepository <TemplateIndex> >(); _searchRepository.Index(Arg.Any <IEnumerable <TemplateIndex> >()).Returns(Enumerable.Empty <IndexError>()); _policyRepository = Substitute.For <IPolicyRepository>(); _policyRepository.GetFundingPeriodById(Arg.Any <string>()).Returns(new FundingPeriod { Id = "2021", Name = "Test Period", Type = FundingPeriodType.FY }); _policyRepository.GetFundingStreamById(Arg.Any <string>()).Returns(new FundingStream { Id = "XX", ShortName = "XX", Name = "FundingSteam" }); _templateBlobService = Substitute.For <ITemplateBlobService>(); _templateBlobService.PublishTemplate(Arg.Any <Template>()).Returns(CommandResult.Success()); }
private void SetupMocks() { _validatorFactory = Substitute.For <IIoCValidatorFactory>(); _validatorFactory.Validate(Arg.Any <object>()).Returns(new ValidationResult()); _templateRepository = Substitute.For <ITemplateRepository>(); _sourceTemplateVersion = new TemplateVersion { Name = "Old Test Name", TemplateId = _command.CloneFromTemplateId, TemplateJson = "{ \"Lorem\": \"ipsum\" }", Version = 12, FundingPeriodId = "19-20", FundingStreamId = "OLD", MinorVersion = 1, MajorVersion = 0, SchemaVersion = "1.1", Status = TemplateStatus.Draft, Author = new Reference("111", "FirstTestUser") }; _sourceTemplate = new Template { Name = _sourceTemplateVersion.Name, Description = "Old description", TemplateId = _command.CloneFromTemplateId, FundingPeriod = new FundingPeriod { Id = "2021", Name = "Test Period", Type = FundingPeriodType.FY }, FundingStream = new FundingStream { Id = "XX", ShortName = "XX", Name = "FundingSteam" }, Current = _sourceTemplateVersion }; _templateMetadataGenerator = Substitute.For <ITemplateMetadataGenerator>(); _templateMetadataGenerator.Validate(Arg.Any <string>()).Returns(new ValidationResult()); _templateMetadataResolver = Substitute.For <ITemplateMetadataResolver>(); _templateMetadataResolver.GetService(Arg.Any <string>()).Returns(_templateMetadataGenerator); _templateValidationService = Substitute.For <IFundingTemplateValidationService>(); _templateValidationService.ValidateFundingTemplate(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), null).Returns(new FundingTemplateValidationResult { }); _templateRepository.GetTemplate(Arg.Is(_command.CloneFromTemplateId)).Returns(_sourceTemplate); _templateRepository.GetAllTemplates().Returns(new[] { _sourceTemplate }); _templateRepository.CreateDraft(Arg.Any <Template>()).Returns(HttpStatusCode.OK); _versionRepository = Substitute.For <ITemplateVersionRepository>(); _versionRepository.SaveVersion(Arg.Any <TemplateVersion>()).Returns(HttpStatusCode.OK); _policyRepository = Substitute.For <IPolicyRepository>(); _policyRepository.GetFundingPeriods().Returns(new[] { new FundingPeriod { Id = "2021", Name = "Test Period", Type = FundingPeriodType.FY }, new FundingPeriod { Id = _command.FundingPeriodId, Name = "Test Funding Period 2" } }); _policyRepository.GetFundingStreams().Returns(new[] { new FundingStream { Id = "XX", ShortName = "XX", Name = "FundingSteam" }, new FundingStream { Id = _command.FundingStreamId, Name = "Funding Stream 2", ShortName = "Stream 2" } }); _policyRepository.GetFundingConfigurations().Returns(new[] { new FundingConfiguration { FundingStreamId = _command.FundingStreamId, FundingPeriodId = _command.FundingPeriodId } }); _templateIndexer = Substitute.For <ISearchRepository <TemplateIndex> >(); _templateBlobService = Substitute.For <ITemplateBlobService>(); _templateBlobService.PublishTemplate(Arg.Any <Template>()).Returns(CommandResult.Success()); }