public SharedLibraryAnalyzer( ISourceCodeService sourceCodeService, IProjectFileReader projectFileReader) { this.sourceCodeService = sourceCodeService; this.projectFileReader = projectFileReader; }
public SharedPersistenceAnalyzer( ISourceCodeService sourceCodeService, IProjectFileReader projectFileReader) { this.sourceCodeService = sourceCodeService; this.projectFileReader = projectFileReader; }
private static CalculationService CreateCalculationService( ICalculationsRepository calculationsRepository = null, ILogger logger = null, ISearchRepository <CalculationIndex> searchRepository = null, IValidator <Calculation> calcValidator = null, IBuildProjectsService buildProjectsService = null, ISpecificationRepository specificationRepository = null, ICacheProvider cacheProvider = null, ICalcsResiliencePolicies resiliencePolicies = null, IVersionRepository <CalculationVersion> calculationVersionRepository = null, IJobsApiClient jobsApiClient = null, ISourceCodeService sourceCodeService = null, IFeatureToggle featureToggle = null, IBuildProjectsRepository buildProjectsRepository = null, ICalculationCodeReferenceUpdate calculationCodeReferenceUpdate = null) { return(new CalculationService (calculationsRepository ?? CreateCalculationsRepository(), logger ?? CreateLogger(), searchRepository ?? CreateSearchRepository(), calcValidator ?? CreateCalculationValidator(), buildProjectsService ?? CreateBuildProjectsService(), specificationRepository ?? CreateSpecificationRepository(), cacheProvider ?? CreateCacheProvider(), resiliencePolicies ?? CalcsResilienceTestHelper.GenerateTestPolicies(), calculationVersionRepository ?? CreateCalculationVersionRepository(), jobsApiClient ?? CreateJobsApiClient(), sourceCodeService ?? CreateSourceCodeService(), featureToggle ?? CreateFeatureToggle(), buildProjectsRepository ?? CreateBuildProjectsRepository(), calculationCodeReferenceUpdate ?? CreateCalculationCodeReferenceUpdate())); }
public static bool IsAspNetProject( this Service service, ISourceCodeService sourceCodeService, IProjectFileReader projectFileReader) { var path = sourceCodeService.GetProjectFile(service.ProjectPath); var projectFile = projectFileReader.ParseProjectFile(path); return(projectFile.Sdk == "Microsoft.NET.Sdk.Web"); }
public SourceCodeController(ISourceCodeRepository sourceCodeRepository, IConfigurationSettingRepository configurationSettingRepository, ISessionContext sessionContext, ISettings settings, ISourceCodeService sourceCodeService, IValidator <SourceCodeItemWiseDiscountEditModel> sourceCodeItemWiseValidator, IEventRepository eventRepository) { _configurationSettingRepository = configurationSettingRepository; _sourceCodeRepository = sourceCodeRepository; _sourceCodeItemWiseValidator = sourceCodeItemWiseValidator; _sessionContext = sessionContext; _sourceCodeService = sourceCodeService; _pageSize = settings.DefaultPageSizeForReports; _eventRepository = eventRepository; }
public BuildProjectsService( ILogger logger, ITelemetry telemetry, IProviderResultsRepository providerResultsRepository, ISpecificationRepository specificationsRepository, ICacheProvider cacheProvider, ICalculationsRepository calculationsRepository, IFeatureToggle featureToggle, IJobsApiClient jobsApiClient, ICalcsResiliencePolicies resiliencePolicies, EngineSettings engineSettings, ISourceCodeService sourceCodeService, IDatasetRepository datasetRepository, IBuildProjectsRepository buildProjectsRepository) { Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(telemetry, nameof(telemetry)); Guard.ArgumentNotNull(providerResultsRepository, nameof(providerResultsRepository)); Guard.ArgumentNotNull(specificationsRepository, nameof(specificationsRepository)); Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider)); Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); Guard.ArgumentNotNull(jobsApiClient, nameof(jobsApiClient)); Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies)); Guard.ArgumentNotNull(engineSettings, nameof(engineSettings)); Guard.ArgumentNotNull(sourceCodeService, nameof(sourceCodeService)); Guard.ArgumentNotNull(datasetRepository, nameof(datasetRepository)); Guard.ArgumentNotNull(buildProjectsRepository, nameof(buildProjectsRepository)); _logger = logger; _telemetry = telemetry; _providerResultsRepository = providerResultsRepository; _specificationsRepository = specificationsRepository; _cacheProvider = cacheProvider; _calculationsRepository = calculationsRepository; _featureToggle = featureToggle; _jobsApiClient = jobsApiClient; _jobsApiClientPolicy = resiliencePolicies.JobsApiClient; _engineSettings = engineSettings; _sourceCodeService = sourceCodeService; _datasetRepository = datasetRepository; _datasetRepositoryPolicy = resiliencePolicies.DatasetsRepository; _buildProjectsRepository = buildProjectsRepository; _buildProjectsRepositoryPolicy = resiliencePolicies.BuildProjectRepositoryPolicy; }
public CodeContextBuilder(IBuildProjectsService buildProjects, ICalculationsRepository calculations, ISourceCodeService compiler, ICalcsResiliencePolicies resiliencePolicies, ILogger logger) { Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(buildProjects, nameof(buildProjects)); Guard.ArgumentNotNull(calculations, nameof(calculations)); Guard.ArgumentNotNull(compiler, nameof(compiler)); Guard.ArgumentNotNull(resiliencePolicies?.CalculationsRepository, nameof(resiliencePolicies.CalculationsRepository)); _buildProjects = buildProjects; _calculations = calculations; _calculationsResilience = resiliencePolicies.CalculationsRepository; _compiler = compiler; _logger = logger; }
public PreviewService( ILogger logger, IBuildProjectsService buildProjectsService, IValidator <PreviewRequest> previewRequestValidator, ICalculationsRepository calculationsRepository, IDatasetRepository datasetRepository, IFeatureToggle featureToggle, ICacheProvider cacheProvider, ISourceCodeService sourceCodeService, ITokenChecker tokenChecker) { _logger = logger; _buildProjectsService = buildProjectsService; _previewRequestValidator = previewRequestValidator; _calculationsRepository = calculationsRepository; _datasetRepository = datasetRepository; _featureToggle = featureToggle; _cacheProvider = cacheProvider; _sourceCodeService = sourceCodeService; _tokenChecker = tokenChecker; }
public PreviewService( ILogger logger, IBuildProjectsService buildProjectsService, IValidator <PreviewRequest> previewRequestValidator, ICalculationsRepository calculationsRepository, IDatasetsApiClient datasetsApiClient, ICacheProvider cacheProvider, ISourceCodeService sourceCodeService, ICalcsResiliencePolicies resiliencePolicies, IMapper mapper, ICalcEngineApiClient calcEngineApiClient) { Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(buildProjectsService, nameof(buildProjectsService)); Guard.ArgumentNotNull(previewRequestValidator, nameof(previewRequestValidator)); Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository)); Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider)); Guard.ArgumentNotNull(sourceCodeService, nameof(sourceCodeService)); Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(resiliencePolicies.DatasetsApiClient, nameof(resiliencePolicies.DatasetsApiClient)); Guard.ArgumentNotNull(resiliencePolicies.CalcEngineApiClient, nameof(resiliencePolicies.CalcEngineApiClient)); Guard.ArgumentNotNull(calcEngineApiClient, nameof(calcEngineApiClient)); _logger = logger; _buildProjectsService = buildProjectsService; _previewRequestValidator = previewRequestValidator; _calculationsRepository = calculationsRepository; _datasetsApiClient = datasetsApiClient; _cacheProvider = cacheProvider; _sourceCodeService = sourceCodeService; _datasetsApiClientPolicy = resiliencePolicies.DatasetsApiClient; _mapper = mapper; _calcEngineApiClient = calcEngineApiClient; _calcEngineApiClientPolicy = resiliencePolicies.CalcEngineApiClient; _typeIdentifierGenerator = new VisualBasicTypeIdentifierGenerator(); }
public MonitoringAnalyzer(ISourceCodeService sourceCodeService) { this.sourceCodeService = sourceCodeService; }
public CachedSourceCodeService(ISourceCodeService sourceCodeService) { this.sourceCodeService = sourceCodeService; }
public BuildProjectsService( ILogger logger, ITelemetry telemetry, IProvidersApiClient providersApiClient, ICacheProvider cacheProvider, ICalculationsRepository calculationsRepository, IFeatureToggle featureToggle, ICalcsResiliencePolicies resiliencePolicies, EngineSettings engineSettings, ISourceCodeService sourceCodeService, IDatasetsApiClient datasetsApiClient, IBuildProjectsRepository buildProjectsRepository, ICalculationEngineRunningChecker calculationEngineRunningChecker, IJobManagement jobManagement, IGraphRepository graphRepository, IMapper mapper, ISpecificationsApiClient specificationsApiClient, IPoliciesApiClient policiesApiClient, ISourceFileRepository sourceFileRepository) : base(jobManagement, logger) { Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(telemetry, nameof(telemetry)); Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider)); Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies)); Guard.ArgumentNotNull(engineSettings, nameof(engineSettings)); Guard.ArgumentNotNull(sourceCodeService, nameof(sourceCodeService)); Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(buildProjectsRepository, nameof(buildProjectsRepository)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(calculationEngineRunningChecker, nameof(calculationEngineRunningChecker)); Guard.ArgumentNotNull(jobManagement, nameof(jobManagement)); Guard.ArgumentNotNull(graphRepository, nameof(graphRepository)); Guard.ArgumentNotNull(resiliencePolicies?.DatasetsApiClient, nameof(resiliencePolicies.DatasetsApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.ProvidersApiClient, nameof(resiliencePolicies.ProvidersApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.BuildProjectRepositoryPolicy, nameof(resiliencePolicies.BuildProjectRepositoryPolicy)); Guard.ArgumentNotNull(resiliencePolicies?.CalculationsRepository, nameof(resiliencePolicies.CalculationsRepository)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient)); Guard.ArgumentNotNull(policiesApiClient, nameof(policiesApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.PoliciesApiClient, nameof(resiliencePolicies.PoliciesApiClient)); Guard.ArgumentNotNull(sourceFileRepository, nameof(sourceFileRepository)); _logger = logger; _telemetry = telemetry; _providersApiClient = providersApiClient; _providersApiClientPolicy = resiliencePolicies.ProvidersApiClient; _cacheProvider = cacheProvider; _calculationsRepository = calculationsRepository; _calculationsRepositoryPolicy = resiliencePolicies.CalculationsRepository; _featureToggle = featureToggle; _engineSettings = engineSettings; _sourceCodeService = sourceCodeService; _datasetsApiClient = datasetsApiClient; _jobManagement = jobManagement; _graphRepository = graphRepository; _datasetsApiClientPolicy = resiliencePolicies.DatasetsApiClient; _buildProjectsRepository = buildProjectsRepository; _buildProjectsRepositoryPolicy = resiliencePolicies.BuildProjectRepositoryPolicy; _calculationEngineRunningChecker = calculationEngineRunningChecker; _mapper = mapper; _specificationsApiClient = specificationsApiClient; _specificationsApiClientPolicy = resiliencePolicies.SpecificationsApiClient; _policiesApiClient = policiesApiClient; _policiesApiClientPolicy = resiliencePolicies.PoliciesApiClient; _sourceFileRepository = sourceFileRepository; _typeIdentifierGenerator = new VisualBasicTypeIdentifierGenerator(); }
public ApiVersioningAnalyzer(ISourceCodeService service) { this.sourceCodeService = service; }
public async Task ResetCalculationForFieldDefinitionChanges_GivenCalculationRequiresReset_UpdatesCalculationsAndDeletesAssembly() { //Arrange const string specificationId = "spec-id"; IEnumerable <DatasetSpecificationRelationshipViewModel> relationships = new[] { new DatasetSpecificationRelationshipViewModel { Name = "Test Name" } }; IEnumerable <string> currentFieldDefinitionNames = new[] { "Test Field" }; ILogger logger = CreateLogger(); CalculationVersion calculationVersion = new CalculationVersion { SourceCode = "return Datasets.TestName.TestField", Date = DateTimeOffset.Now }; IEnumerable <Calculation> calculations = new[] { new Calculation { Current = calculationVersion, SpecificationId = specificationId, CalculationSpecification = new Reference("calc-spac-id", "calc spec name"), FundingPeriod = new Reference("fp1", "fp 1"), FundingStream = new Reference("fs1", "fs 1"), Policies = new List <Reference> { new Reference { Id = "policy-1", Name = "policy 1" } } } }; IEnumerable <Models.Specs.Calculation> calculationSpecifications = new[] { new Models.Specs.Calculation { Id = "calc-spec-id" } }; BuildProject buildProject = new BuildProject(); Build build = new Build { SourceFiles = new List <SourceFile>() }; Models.Specs.SpecificationSummary specificationSummary = new Models.Specs.SpecificationSummary(); ICalculationsRepository calculationsRepository = CreateCalculationsRepository(); calculationsRepository .GetCalculationsBySpecificationId(Arg.Is(specificationId)) .Returns(calculations); calculationsRepository .UpdateCalculation(Arg.Any <Calculation>()) .Returns(HttpStatusCode.OK); ISpecificationRepository specificationRepository = CreateSpecificationRepository(); specificationRepository .GetCalculationSpecificationsForSpecification(Arg.Is(specificationId)) .Returns(calculationSpecifications); specificationRepository .GetSpecificationSummaryById(Arg.Is(specificationId)) .Returns(specificationSummary); IBuildProjectsService buildProjectsService = CreateBuildProjectsService(); buildProjectsService .GetBuildProjectForSpecificationId(Arg.Is(specificationId)) .Returns(buildProject); ISourceCodeService sourceCodeService = CreateSourceCodeService(); sourceCodeService .Compile(Arg.Is(buildProject), Arg.Any <IEnumerable <Calculation> >(), Arg.Any <CompilerOptions>()) .Returns(build); IVersionRepository <CalculationVersion> calculationVersionRepository = CreateCalculationVersionRepository(); calculationVersionRepository .CreateVersion(Arg.Any <CalculationVersion>(), Arg.Any <CalculationVersion>()) .Returns(calculationVersion); ICacheProvider cacheProvider = CreateCacheProvider(); CalculationService calculationService = CreateCalculationService( logger: logger, calculationsRepository: calculationsRepository, specificationRepository: specificationRepository, buildProjectsService: buildProjectsService, sourceCodeService: sourceCodeService, calculationVersionRepository: calculationVersionRepository, cacheProvider: cacheProvider); //Act await calculationService.ResetCalculationForFieldDefinitionChanges(relationships, specificationId, currentFieldDefinitionNames); //Assert await sourceCodeService .Received(1) .DeleteAssembly(Arg.Is(specificationId)); await cacheProvider .Received(1) .RemoveAsync <List <DatasetSchemaRelationshipModel> >(Arg.Is($"{CacheKeys.DatasetRelationshipFieldsForSpecification}{specificationId}")); }
public async Task CreateCalculation_GivenValidCalculationWithNullFundingStream_AndSavesLogs() { //Arrange Calculation calculation = CreateCalculation(); calculation.FundingStream = null; IEnumerable <Calculation> calculations = new[] { calculation }; IEnumerable <Models.Specs.Calculation> calculationSpecifications = new[] { new Models.Specs.Calculation { Id = calculation.CalculationSpecification.Id } }; string json = JsonConvert.SerializeObject(calculation); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties.Add("user-id", UserId); message.UserProperties.Add("user-name", Username); ICalculationsRepository repository = CreateCalculationsRepository(); repository .CreateDraftCalculation(Arg.Any <Calculation>()) .Returns(HttpStatusCode.Created); repository .GetCalculationsBySpecificationId(Arg.Is("any-spec-id")) .Returns(calculations); Models.Specs.SpecificationSummary specificationSummary = new Models.Specs.SpecificationSummary() { Id = calculation.SpecificationId, Name = "Test Spec Name", }; ISpecificationRepository specificationRepository = CreateSpecificationRepository(); specificationRepository .GetSpecificationSummaryById(Arg.Is(calculation.SpecificationId)) .Returns(specificationSummary); specificationRepository .GetCalculationSpecificationsForSpecification(Arg.Is(calculation.SpecificationId)) .Returns(calculationSpecifications); ILogger logger = CreateLogger(); ISearchRepository <CalculationIndex> searchRepository = CreateSearchRepository(); Build build = new Build { SourceFiles = new List <SourceFile> { new SourceFile() } }; ISourceCodeService sourceCodeService = CreateSourceCodeService(); sourceCodeService .Compile(Arg.Any <BuildProject>(), Arg.Any <IEnumerable <Models.Calcs.Calculation> >(), Arg.Any <CompilerOptions>()) .Returns(build); CalculationService service = CreateCalculationService( calculationsRepository: repository, logger: logger, searchRepository: searchRepository, specificationRepository: specificationRepository, sourceCodeService: sourceCodeService); //Act await service.CreateCalculation(message); //Assert logger .Received(1) .Information($"Calculation with id: {calculation.Id} was successfully saved to Cosmos Db"); await repository .Received(1) .CreateDraftCalculation(Arg.Is <Calculation>(m => m.Id == CalculationId && m.Current.PublishStatus == PublishStatus.Draft && m.Current.Author.Id == UserId && m.Current.Author.Name == Username && m.Current.Date.Date == DateTimeOffset.Now.Date && m.Current.Version == 1 && m.Current.DecimalPlaces == 6 )); await searchRepository .Received(1) .Index(Arg.Is <List <CalculationIndex> >( m => m.First().Id == CalculationId && m.First().Name == "Test Calc Name" && m.First().CalculationSpecificationId == "any-calc-id" && m.First().CalculationSpecificationName == "Test Calc Name" && m.First().SpecificationId == "any-spec-id" && m.First().SpecificationName == "Test Spec Name" && m.First().FundingPeriodId == "18/19" && m.First().FundingPeriodName == "2018/2019" && m.First().FundingStreamId == string.Empty && m.First().FundingStreamName == "No funding stream set" && m.First().AllocationLineId == "test-alloc-id" && m.First().AllocationLineName == "test-alloc-name" && m.First().PolicySpecificationIds.First() == "policy-id" && m.First().PolicySpecificationNames.First() == "policy-name" )); }
public async Task UpdateCalculationCodeOnCalculationChange_WhenCalculationsFoundReferencingCalculationToBeUpdated_ThenSourceCodeUpdated() { // Arrange ICalculationsRepository calculationsRepository = CreateCalculationsRepository(); ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient(); IVersionRepository <CalculationVersion> versionRepository = CreateCalculationVersionRepository(); IBuildProjectsService buildProjectsService = CreateBuildProjectsService(); ISourceCodeService sourceCodeService = CreateSourceCodeService(); CalculationService service = CreateCalculationService(calculationsRepository: calculationsRepository, specificationsApiClient: specificationsApiClient, calculationVersionRepository: versionRepository, buildProjectsService: buildProjectsService, sourceCodeService: sourceCodeService); const string specificationId = "specId"; const string calculationId = "updatedCalc"; const string originalCodeUpdate = @"Dim test as OriginalNameOptions? OriginalNameOptions.enumName Return Calculations.OriginalName()"; const string newCodeUpdated = @"Dim test as CalculationToUpdateOptions? CalculationToUpdateOptions.enumName Return Calculations.CalculationToUpdate()"; const string originalCodeIgnore = "Return 10"; const string fundingStreamId = "fundingstreamid"; CalculationVersionComparisonModel comparison = new CalculationVersionComparisonModel() { CalculationId = calculationId, CurrentName = "Calculation To Update", PreviousName = "Original Name", SpecificationId = specificationId, CalculationDataType = CalculationDataType.Enum, Namespace = "Calculations" }; Reference user = new Reference("userId", "User Name"); List <Calculation> calculations = new List <Calculation> { new Calculation { Id = calculationId, SpecificationId = specificationId, FundingStreamId = fundingStreamId, Current = new CalculationVersion { SourceCode = originalCodeIgnore, Name = "Calculation to Update", CalculationType = CalculationType.Template, Description = "Calculation Description", DataType = CalculationDataType.Enum } }, new Calculation { Id = "referenceCalc", SpecificationId = specificationId, FundingStreamId = fundingStreamId, Current = new CalculationVersion { SourceCode = originalCodeUpdate, Name = "Calling Calculation To Update", CalculationType = CalculationType.Template, Description = "Calculation Description" } } }; calculationsRepository .GetCalculationsBySpecificationId(Arg.Is(specificationId)) .Returns(calculations); calculationsRepository .UpdateCalculation(Arg.Any <Calculation>()) .Returns(HttpStatusCode.OK); calculationsRepository .GetCalculationById(Arg.Is(calculations[0].Id)) .Returns(calculations[0]); SpecModel.SpecificationSummary specification = new SpecModel.SpecificationSummary() { Id = specificationId, Name = "Specification Name", FundingStreams = new [] { new Reference(fundingStreamId, "fundingStreamName"), } }; specificationsApiClient .GetSpecificationSummaryById(Arg.Is(specificationId)) .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, specification)); CalculationVersion calculationVersion = new CalculationVersion { SourceCode = newCodeUpdated, Version = 2 }; versionRepository .CreateVersion(Arg.Is <CalculationVersion>(_ => _.SourceCode == newCodeUpdated), Arg.Any <CalculationVersion>()) .Returns(calculationVersion); buildProjectsService .GetBuildProjectForSpecificationId(specificationId) .Returns(new BuildProject()); sourceCodeService .Compile(Arg.Any <BuildProject>(), Arg.Any <IEnumerable <Calculation> >(), Arg.Any <CompilerOptions>()) .Returns(new Build()); // Act IEnumerable <Calculation> updatedCalculations = await service.UpdateCalculationCodeOnCalculationChange(comparison, user); // Assert updatedCalculations .Should() .HaveCount(1); Calculation calculation = updatedCalculations.Single(); calculation.Current.SourceCode .Should() .Be(newCodeUpdated); calculation.Current.Version .Should() .Be(2); calculation.Id .Should() .Be("referenceCalc"); }
public MegaServiceAnalyzer(ISourceCodeService sourceCodeService) { this.sourceCodeService = sourceCodeService; }
public async Task EditCalculationStatus_GivenNewStatusOfUpdated_UpdatesSearchReturnsOK() { //Arrange EditStatusModel CalculationEditStatusModel = new EditStatusModel { PublishStatus = PublishStatus.Updated }; string json = JsonConvert.SerializeObject(CalculationEditStatusModel); 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> { { "calculationId", new StringValues(CalculationId) }, }); request .Query .Returns(queryStringValues); request .Body .Returns(stream); request .HttpContext .Returns(context); ILogger logger = CreateLogger(); Calculation calculation = CreateCalculation(); calculation.Current.PublishStatus = PublishStatus.Approved; CalculationVersion calculationVersion = calculation.Current.Clone() as CalculationVersion; calculationVersion.PublishStatus = PublishStatus.Updated; ICalculationsRepository CalculationsRepository = CreateCalculationsRepository(); CalculationsRepository .GetCalculationById(Arg.Is(CalculationId)) .Returns(calculation); CalculationsRepository .UpdateCalculation(Arg.Any <Calculation>()) .Returns(HttpStatusCode.OK); ISearchRepository <CalculationIndex> searchRepository = CreateSearchRepository(); Models.Specs.SpecificationSummary specificationSummary = new Models.Specs.SpecificationSummary(); ISpecificationRepository specificationRepository = CreateSpecificationRepository(); specificationRepository .GetSpecificationSummaryById(Arg.Is(calculation.SpecificationId)) .Returns(specificationSummary); IVersionRepository <CalculationVersion> versionRepository = CreateCalculationVersionRepository(); versionRepository .CreateVersion(Arg.Any <CalculationVersion>(), Arg.Any <CalculationVersion>()) .Returns(calculationVersion); Build build = new Build { SourceFiles = new List <SourceFile> { new SourceFile() } }; BuildProject buildProject = new BuildProject(); IBuildProjectsService buildProjectsService = CreateBuildProjectsService(); buildProjectsService .GetBuildProjectForSpecificationId(Arg.Is(calculation.SpecificationId)) .Returns(buildProject); ISourceCodeService sourceCodeService = CreateSourceCodeService(); sourceCodeService .Compile(Arg.Any <BuildProject>(), Arg.Any <IEnumerable <Models.Calcs.Calculation> >(), Arg.Any <CompilerOptions>()) .Returns(build); CalculationService service = CreateCalculationService( logger: logger, calculationsRepository: CalculationsRepository, searchRepository: searchRepository, specificationRepository: specificationRepository, calculationVersionRepository: versionRepository, sourceCodeService: sourceCodeService, buildProjectsService: buildProjectsService); //Act IActionResult result = await service.UpdateCalculationStatus(request); //Arrange result .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeOfType <PublishStatusResultModel>() .Which .PublishStatus .Should() .Be(PublishStatus.Updated); calculation .Current .PublishStatus .Should() .Be(PublishStatus.Updated); await searchRepository .Received(1) .Index(Arg.Is <IEnumerable <CalculationIndex> >(m => m.First().Status == "Updated")); }
public static IEnumerable <Service> GetDotnetProjects( this IEnumerable <Service> services, ISourceCodeService sourceCodeService ) => services.Where(s => sourceCodeService.IsDotnetProject(s.ProjectPath));
public HardcodedEndpointsAnalyzer(ISourceCodeService sourceCodeService) { this.sourceCodeService = sourceCodeService; }
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())); }
public async Task EditCalculationStatus_GivenNewStatusOfUpdated_UpdatesSearchReturnsOK() { //Arrange EditStatusModel CalculationEditStatusModel = new EditStatusModel { PublishStatus = PublishStatus.Updated }; ILogger logger = CreateLogger(); Calculation calculation = CreateCalculation(); calculation.Current.PublishStatus = PublishStatus.Approved; CalculationVersion calculationVersion = calculation.Current.Clone() as CalculationVersion; calculationVersion.PublishStatus = PublishStatus.Updated; ICalculationsRepository CalculationsRepository = CreateCalculationsRepository(); CalculationsRepository .GetCalculationById(Arg.Is(CalculationId)) .Returns(calculation); CalculationsRepository .UpdateCalculation(Arg.Any <Calculation>()) .Returns(HttpStatusCode.OK); ISearchRepository <CalculationIndex> searchRepository = CreateSearchRepository(); SpecModel.SpecificationSummary specificationSummary = new SpecModel.SpecificationSummary() { Id = calculation.SpecificationId, Name = "spec name", FundingStreams = new[] { new Reference(calculation.FundingStreamId, "funding stream name") } }; ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient(); specificationsApiClient .GetSpecificationSummaryById(Arg.Is(calculation.SpecificationId)) .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, specificationSummary)); IVersionRepository <CalculationVersion> versionRepository = CreateCalculationVersionRepository(); versionRepository .CreateVersion(Arg.Any <CalculationVersion>(), Arg.Any <CalculationVersion>()) .Returns(calculationVersion); Build build = new Build { SourceFiles = new List <SourceFile> { new SourceFile() } }; BuildProject buildProject = new BuildProject(); IBuildProjectsService buildProjectsService = CreateBuildProjectsService(); buildProjectsService .GetBuildProjectForSpecificationId(Arg.Is(calculation.SpecificationId)) .Returns(buildProject); ISourceCodeService sourceCodeService = CreateSourceCodeService(); sourceCodeService .Compile(Arg.Any <BuildProject>(), Arg.Any <IEnumerable <Models.Calcs.Calculation> >(), Arg.Any <CompilerOptions>()) .Returns(build); CalculationService service = CreateCalculationService( logger: logger, calculationsRepository: CalculationsRepository, searchRepository: searchRepository, specificationsApiClient: specificationsApiClient, calculationVersionRepository: versionRepository, sourceCodeService: sourceCodeService, buildProjectsService: buildProjectsService); //Act IActionResult result = await service.UpdateCalculationStatus(CalculationId, CalculationEditStatusModel); //Arrange result .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeOfType <PublishStatusResultModel>() .Which .PublishStatus .Should() .Be(PublishStatus.Updated); calculation .Current .PublishStatus .Should() .Be(PublishStatus.Updated); }