Esempio n. 1
0
        public void SetUp()
        {
            _jobs     = new Mock <IJobManagement>();
            _features = new Mock <ICalculationsFeatureFlag>();

            _features.Setup(_ => _.IsGraphEnabled())
            .ReturnsAsync(true);

            _jobs.Setup(_ => _.QueueJob(It.IsAny <JobCreateModel>()))
            .ReturnsAsync(new Job());

            _instructionAllocationJobCreation = new InstructionAllocationJobCreation(new Mock <ICalculationsRepository>().Object,
                                                                                     new ResiliencePolicies
            {
                CalculationsRepository = Policy.NoOpAsync()
            },
                                                                                     Logger.None,
                                                                                     _features.Object,
                                                                                     _jobs.Object);
        }
        private static CalculationService CreateCalculationService(
            ICalculationsRepository calculationsRepository = null,
            ILogger logger = null,
            ISearchRepository <CalculationIndex> searchRepository = null,
            IBuildProjectsService buildProjectsService            = null,
            IPoliciesApiClient policiesApiClient        = null,
            ICacheProvider cacheProvider                = null,
            ICalcsResiliencePolicies resiliencePolicies = null,
            IVersionRepository <CalculationVersion> calculationVersionRepository = null,
            IJobManagement jobManagement                     = null,
            ISourceCodeService sourceCodeService             = null,
            IFeatureToggle featureToggle                     = null,
            IBuildProjectsRepository buildProjectsRepository = null,
            ICalculationCodeReferenceUpdate calculationCodeReferenceUpdate      = null,
            IValidator <CalculationCreateModel> calculationCreateModelValidator = null,
            IValidator <CalculationEditModel> calculationEditModelValidator     = null,
            ISpecificationsApiClient specificationsApiClient = null,
            IGraphRepository graphRepository = null,
            ICalculationsFeatureFlag calculationsFeatureFlag = null,
            ICodeContextCache codeContextCache         = null,
            ISourceFileRepository sourceFileRepository = null,
            IResultsApiClient resultsApiClient         = null,
            IDatasetsApiClient datasetsApiClient       = null,
            IApproveAllCalculationsJobAction approveAllCalculationsJobAction = null)
        {
            CalculationNameInUseCheck calculationNameInUseCheck = new CalculationNameInUseCheck(calculationsRepository ?? CreateCalculationsRepository(),
                                                                                                specificationsApiClient ?? CreateSpecificationsApiClient(),
                                                                                                resiliencePolicies ?? CalcsResilienceTestHelper.GenerateTestPolicies());

            InstructionAllocationJobCreation instructionAllocationJobCreation =
                new InstructionAllocationJobCreation(
                    calculationsRepository ?? CreateCalculationsRepository(),
                    resiliencePolicies ?? CalcsResilienceTestHelper.GenerateTestPolicies(),
                    logger ?? CreateLogger(),
                    calculationsFeatureFlag ?? CreateCalculationsFeatureFlag(),
                    jobManagement ?? CreateJobManagement());

            return(new CalculationService
                   (
                       calculationsRepository ?? CreateCalculationsRepository(),
                       logger ?? CreateLogger(),
                       searchRepository ?? CreateSearchRepository(),
                       buildProjectsService ?? CreateBuildProjectsService(),
                       policiesApiClient ?? CreatePoliciesApiClient(),
                       cacheProvider ?? CreateCacheProvider(),
                       resiliencePolicies ?? CalcsResilienceTestHelper.GenerateTestPolicies(),
                       calculationVersionRepository ?? CreateCalculationVersionRepository(),
                       sourceCodeService ?? CreateSourceCodeService(),
                       featureToggle ?? CreateFeatureToggle(),
                       buildProjectsRepository ?? CreateBuildProjectsRepository(),
                       calculationCodeReferenceUpdate ?? CreateCalculationCodeReferenceUpdate(),
                       calculationCreateModelValidator ?? CreateCalculationCreateModelValidator(),
                       calculationEditModelValidator ?? CreateCalculationEditModelValidator(),
                       specificationsApiClient ?? CreateSpecificationsApiClient(),
                       calculationNameInUseCheck,
                       instructionAllocationJobCreation,
                       new CreateCalculationService(calculationNameInUseCheck,
                                                    calculationsRepository ?? CreateCalculationsRepository(),
                                                    calculationVersionRepository ?? CreateCalculationVersionRepository(),
                                                    resiliencePolicies ?? CalcsResilienceTestHelper.GenerateTestPolicies(),
                                                    calculationCreateModelValidator ?? CreateCalculationCreateModelValidator(),
                                                    cacheProvider ?? CreateCacheProvider(),
                                                    searchRepository ?? CreateSearchRepository(),
                                                    logger ?? CreateLogger(),
                                                    instructionAllocationJobCreation),
                       graphRepository ?? CreateGraphRepository(),
                       CreateJobManagement(),
                       codeContextCache ?? Substitute.For <ICodeContextCache>(),
                       resultsApiClient ?? Substitute.For <IResultsApiClient>(),
                       datasetsApiClient ?? Substitute.For <IDatasetsApiClient>(),
                       approveAllCalculationsJobAction ?? CreateApproveAllCalculationsJobAction()));
        }