private void SetupMocks()
            {
                _validatorFactory = Substitute.For <IIoCValidatorFactory>();
                _validatorFactory.Validate(Arg.Any <object>()).Returns(new ValidationResult());
                _templateRepository = Substitute.For <ITemplateRepository>();
                _templateRepository.CreateDraft(Arg.Any <Template>()).Returns(HttpStatusCode.OK);

                _versionRepository = Substitute.For <ITemplateVersionRepository>();
                _versionRepository.SaveVersion(Arg.Any <TemplateVersion>()).Returns(HttpStatusCode.OK);

                _searchRepository = Substitute.For <ISearchRepository <TemplateIndex> >();
                _searchRepository.Index(Arg.Any <IEnumerable <TemplateIndex> >()).Returns(Enumerable.Empty <IndexError>());

                _fundingPeriod = new FundingPeriod
                {
                    Id   = _command.FundingPeriodId,
                    Name = "Test Period",
                    Type = FundingPeriodType.FY
                };
                _fundingStream = new FundingStream
                {
                    Id        = _command.FundingStreamId,
                    ShortName = "XX",
                    Name      = "FundingSteam"
                };
                _policyRepository = Substitute.For <IPolicyRepository>();
                _policyRepository.GetFundingPeriods().Returns(new [] { _fundingPeriod });
                _policyRepository.GetFundingStreams().Returns(new [] { _fundingStream });
                _policyRepository.GetFundingConfigurations().Returns(new [] { new FundingConfiguration
                                                                              {
                                                                                  FundingStreamId = _fundingStream.Id,
                                                                                  FundingPeriodId = _fundingPeriod.Id
                                                                              } });
            }
            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());
            }