Ejemplo n.º 1
0
        public CalculationsController(
            ICalculationService calcsService,
            ICalculationsSearchService calcsSearchService,
            IPreviewService previewService,
            IBuildProjectsService buildProjectsService,
            IQueueReIndexSpecificationCalculationRelationships calculationRelationships,
            ICalculationFundingLineQueryService calculationFundingLineQueryService,
            ICodeContextCache codeContextCache)
        {
            Guard.ArgumentNotNull(calcsService, nameof(calcsService));
            Guard.ArgumentNotNull(calcsSearchService, nameof(calcsSearchService));
            Guard.ArgumentNotNull(previewService, nameof(previewService));
            Guard.ArgumentNotNull(buildProjectsService, nameof(buildProjectsService));
            Guard.ArgumentNotNull(calculationRelationships, nameof(calculationRelationships));
            Guard.ArgumentNotNull(calculationFundingLineQueryService, nameof(calculationFundingLineQueryService));
            Guard.ArgumentNotNull(codeContextCache, nameof(codeContextCache));

            _calcsService                       = calcsService;
            _previewService                     = previewService;
            _calcsSearchService                 = calcsSearchService;
            _buildProjectsService               = buildProjectsService;
            _calculationRelationships           = calculationRelationships;
            _calculationFundingLineQueryService = calculationFundingLineQueryService;
            _codeContextCache                   = codeContextCache;
        }
Ejemplo n.º 2
0
        public SoundVmFactory(
            IDownloadManager downloadManager,
            IMixMediaPlayerService player,
            ITelemetry telemetry,
            IPreviewService previewService,
            ISoundDataProvider soundDataProvider,
            ISoundMixService soundMixService,
            IUserSettings userSettings,
            IIapService iapService,
            IRenamer renamer,
            IServiceProvider serviceProvider)
        {
            Guard.IsNotNull(downloadManager, nameof(downloadManager));
            Guard.IsNotNull(soundDataProvider, nameof(soundDataProvider));
            Guard.IsNotNull(player, nameof(player));
            Guard.IsNotNull(telemetry, nameof(telemetry));
            Guard.IsNotNull(iapService, nameof(iapService));
            Guard.IsNotNull(previewService, nameof(previewService));
            Guard.IsNotNull(userSettings, nameof(userSettings));
            Guard.IsNotNull(soundMixService, nameof(soundMixService));
            Guard.IsNotNull(renamer, nameof(renamer));
            Guard.IsNotNull(serviceProvider, nameof(serviceProvider));

            _userSettings      = userSettings;
            _downloadManager   = downloadManager;
            _previewService    = previewService;
            _soundMixService   = soundMixService;
            _iapService        = iapService;
            _soundDataProvider = soundDataProvider;
            _player            = player;
            _renamer           = renamer;
            _telemetry         = telemetry;
            _serviceProvider   = serviceProvider;
        }
Ejemplo n.º 3
0
        public OnlineSoundViewModel(
            Sound s,
            IDownloadManager downloadManager,
            ISoundDataProvider soundDataProvider,
            ITelemetry telemetry,
            IPreviewService previewService,
            IIapService iapService,
            IDialogService dialogService)
        {
            Guard.IsNotNull(s, nameof(s));
            Guard.IsNotNull(downloadManager, nameof(downloadManager));
            Guard.IsNotNull(soundDataProvider, nameof(soundDataProvider));
            Guard.IsNotNull(telemetry, nameof(telemetry));
            Guard.IsNotNull(iapService, nameof(iapService));
            Guard.IsNotNull(previewService, nameof(previewService));
            Guard.IsNotNull(dialogService, nameof(dialogService));
            _sound             = s;
            _downloadManager   = downloadManager;
            _previewService    = previewService;
            _iapService        = iapService;
            _soundDataProvider = soundDataProvider;
            _telemetry         = telemetry;
            _dialogService     = dialogService;

            _downloadProgress = new Progress <double>();
            _downloadProgress.ProgressChanged    += OnProgressChanged;
            _soundDataProvider.LocalSoundDeleted += OnSoundDeleted;
            _iapService.ProductPurchased         += OnProductPurchased;

            DownloadCommand = new AsyncRelayCommand(DownloadAsync);
            LoadCommand     = new AsyncRelayCommand(LoadAsync);
            DeleteCommand   = new AsyncRelayCommand(DeleteSound);
            BuyCommand      = new AsyncRelayCommand(BuySoundAsync);
            PreviewCommand  = new RelayCommand(Preview);
        }
        public async Task ValidateAsync_WhenSourceCodeDoesNotCompile_ValidIsFalse()
        {
            //Arrange
            CalculationEditModel model = CreateModel();

            PreviewResponse previewResponse = new PreviewResponse
            {
                CompilerOutput = new Build
                {
                    CompilerMessages = new List <CompilerMessage>
                    {
                        new CompilerMessage {
                            Message = "Failed"
                        }
                    }
                }
            };

            IPreviewService previewService = CreatePreviewService(previewResponse);

            CalculationEditModelValidator validator = CreateValidator(previewService: previewService);

            //Act
            ValidationResult result = await validator.ValidateAsync(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();
        }
 private static CalculationEditModelValidator CreateValidator(
     ICalculationsRepository calculationRepository = null,
     IPreviewService previewService = null)
 {
     return(new CalculationEditModelValidator(
                previewService ?? CreatePreviewService(),
                calculationRepository ?? CreateCalculationRepository()));
 }
Ejemplo n.º 6
0
        public async Task ValidateAsync_WhenSourceCodeDoesNotCompile__ValidIsFalse()
        {
            //Arrange
            CalculationCreateModel model = CreateModel();

            model.CalculationType = CalculationType.Additional;

            ICalculationsRepository calculationsRepository = CreateCalculationRepository();

            calculationsRepository
            .GetCalculationsBySpecificationIdAndCalculationName(Arg.Is(model.SpecificationId), Arg.Is(model.Name))
            .Returns((Calculation)null);

            SpecModel.SpecificationSummary specificationSummary = new SpecModel.SpecificationSummary
            {
                Name           = "spec name",
                FundingStreams = new[] { new Reference(model.FundingStreamId, "funding stream name") }
            };

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(model.SpecificationId))
            .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, specificationSummary));

            PreviewResponse previewResponse = new PreviewResponse
            {
                CompilerOutput = new Build
                {
                    CompilerMessages = new List <CompilerMessage>
                    {
                        new CompilerMessage {
                            Message = "Failed"
                        }
                    }
                }
            };

            IPreviewService previewService = CreatePreviewService(previewResponse);

            CalculationCreateModelValidator validator = CreateValidator(
                calculationsRepository, previewService: previewService, specificationsApiClient: specificationsApiClient);

            //Act
            ValidationResult result = await validator.ValidateAsync(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result.Errors
            .Should()
            .Contain(_ => _.ErrorMessage == "There are errors in the source code provided");
        }
Ejemplo n.º 7
0
 private static CalculationCreateModelValidator CreateValidator(
     ICalculationsRepository calculationRepository = null,
     IPreviewService previewService = null,
     ISpecificationsApiClient specificationsApiClient = null)
 {
     return(new CalculationCreateModelValidator(
                calculationRepository ?? CreateCalculationRepository(),
                previewService ?? CreatePreviewService(),
                specificationsApiClient ?? CreateSpecificationsApiClient(),
                CalcsResilienceTestHelper.GenerateTestPolicies()));
 }
Ejemplo n.º 8
0
 public CalculationsController(
     ICalculationService calcsService,
     ICalculationsSearchService calcsSearchService,
     IPreviewService previewService,
     IBuildProjectsService buildProjectsService)
 {
     _calcsService         = calcsService;
     _previewService       = previewService;
     _calcsSearchService   = calcsSearchService;
     _buildProjectsService = buildProjectsService;
 }
Ejemplo n.º 9
0
        public PreviewServiceTests()
        {
            Host.Run(new[] { "install y" }).Wait();

            Scaffold.Run();

            // even though it's not being used, this needs to stay
            _mocker           = new ContextMocker();
            _previewService   = new PreviewService();
            _tasksService     = new TasksService();
            _instancesService = new InstancesService();
        }
Ejemplo n.º 10
0
        public async Task ValidateAsync_WhenSourceCodeDoesCompile__ValidIsTrue()
        {
            //Arrange
            CalculationCreateModel model = CreateModel();

            model.CalculationType = CalculationType.Additional;

            ICalculationsRepository calculationsRepository = CreateCalculationRepository();

            calculationsRepository
            .GetCalculationsBySpecificationIdAndCalculationName(Arg.Is(model.SpecificationId), Arg.Is(model.Name))
            .Returns((Calculation)null);

            SpecModel.SpecificationSummary specificationSummary = new SpecModel.SpecificationSummary
            {
                Name           = "spec name",
                FundingStreams = new[] { new Reference(model.FundingStreamId, "funding stream name") }
            };

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(model.SpecificationId))
            .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, specificationSummary));

            IPreviewService previewService = CreatePreviewService();

            CalculationCreateModelValidator validator = CreateValidator(
                calculationsRepository, previewService: previewService, specificationsApiClient: specificationsApiClient);

            //Act
            ValidationResult result = await validator.ValidateAsync(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeTrue();

            previewService
            .Received(1);
        }
Ejemplo n.º 11
0
        private static IPreviewService CreatePreviewService(PreviewResponse previewResponse = null)
        {
            if (previewResponse == null)
            {
                previewResponse = new PreviewResponse
                {
                    CompilerOutput = new Build
                    {
                        CompilerMessages = new List <CompilerMessage>()
                    }
                };
            }

            OkObjectResult okObjectResult = new OkObjectResult(previewResponse);

            IPreviewService previewService = Substitute.For <IPreviewService>();

            previewService
            .Compile(Arg.Any <PreviewRequest>())
            .Returns(okObjectResult);

            return(previewService);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetContentVersionCommand" /> class.
 /// </summary>
 /// <param name="previewService">The preview service.</param>
 public GetContentVersionCommand(IPreviewService previewService)
 {
     this.previewService = previewService;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PreviewWidgetCommand" /> class.
 /// </summary>
 /// <param name="previewService">The preview service.</param>
 public PreviewWidgetCommand(IPreviewService previewService)
 {
     this.previewService = previewService;
 }
Ejemplo n.º 14
0
 public OfflinePreviewController()
 {
     _previewService = new PreviewService();
 }
Ejemplo n.º 15
0
        public CalculationCreateModelValidator(
            ICalculationsRepository calculationRepository,
            IPreviewService previewService,
            ISpecificationsApiClient specificationsApiClient,
            ICalcsResiliencePolicies calcsResiliencePolicies)
        {
            Guard.ArgumentNotNull(calculationRepository, nameof(calculationRepository));
            Guard.ArgumentNotNull(previewService, nameof(previewService));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(calcsResiliencePolicies, nameof(calcsResiliencePolicies));
            Guard.ArgumentNotNull(calcsResiliencePolicies?.SpecificationsApiClient, nameof(calcsResiliencePolicies.SpecificationsApiClient));

            _calculationRepository         = calculationRepository;
            _previewService                = previewService;
            _specificationsApiClient       = specificationsApiClient;
            _specificationsApiClientPolicy = calcsResiliencePolicies.SpecificationsApiClient;

            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(model => model.SpecificationId)
            .NotEmpty()
            .NotNull()
            .WithMessage("Null or empty specification id provided.");

            RuleFor(model => model.ValueType)
            .NotNull()
            .WithMessage("Null value type was provided.");

            RuleFor(model => model.Name)
            .Custom((name, context) =>
            {
                CalculationCreateModel calculationCreateModel = context.ParentContext.InstanceToValidate as CalculationCreateModel;
                if (string.IsNullOrWhiteSpace(calculationCreateModel.Name))
                {
                    context.AddFailure("Null or empty calculation name provided.");
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(calculationCreateModel.SpecificationId))
                    {
                        Calculation calculation = _calculationRepository.GetCalculationsBySpecificationIdAndCalculationName(calculationCreateModel.SpecificationId, calculationCreateModel.Name).Result;

                        if (calculation != null)
                        {
                            context.AddFailure($"A calculation already exists with the name: '{calculationCreateModel.Name}' for this specification");
                        }
                    }
                }
            });

            RuleFor(model => model.SourceCode)
            .Custom((sc, context) =>
            {
                CalculationCreateModel calculationCreateModel = context.ParentContext.InstanceToValidate as CalculationCreateModel;
                if (string.IsNullOrWhiteSpace(calculationCreateModel.SourceCode))
                {
                    context.AddFailure("Null or empty source code provided.");
                }
                else
                {
                    if (calculationCreateModel.CalculationType == CalculationType.Additional)
                    {
                        PreviewRequest previewRequest = new PreviewRequest
                        {
                            SpecificationId = calculationCreateModel.SpecificationId,
                            CalculationId   = calculationCreateModel.Id,
                            Name            = calculationCreateModel.Name,
                            SourceCode      = calculationCreateModel.SourceCode
                        };

                        IActionResult result = _previewService.Compile(previewRequest).Result;

                        OkObjectResult okObjectResult = result as OkObjectResult;

                        PreviewResponse response = okObjectResult.Value as PreviewResponse;

                        if (response != null)
                        {
                            if (!response.CompilerOutput.CompilerMessages.IsNullOrEmpty())
                            {
                                context.AddFailure("There are errors in the source code provided");
                            }
                        }
                    }
                }
            });

            RuleFor(model => model.FundingStreamId)
            .Custom((fs, context) =>
            {
                CalculationCreateModel calculationCreateModel = context.ParentContext.InstanceToValidate as CalculationCreateModel;

                //only validate funding stream id for template calcs
                var isTemplateCalculation = calculationCreateModel.CalculationType == CalculationType.Template;

                if (isTemplateCalculation &&
                    string.IsNullOrWhiteSpace(calculationCreateModel.FundingStreamId))
                {
                    context.AddFailure("Null or empty funding stream id provided.");
                }
                else
                {
                    ApiResponse <SpecModel.SpecificationSummary> specificationApiResponse = _specificationsApiClientPolicy.ExecuteAsync(() => _specificationsApiClient.GetSpecificationSummaryById(calculationCreateModel.SpecificationId)).GetAwaiter().GetResult();

                    if (specificationApiResponse == null || !specificationApiResponse.StatusCode.IsSuccess() || specificationApiResponse.Content == null)
                    {
                        context.AddFailure("Failed to find specification for provided specification id.");
                    }
                    else
                    {
                        SpecModel.SpecificationSummary specificationSummary = specificationApiResponse.Content;

                        //I don't want to have to fetch the spec summary again outside of this method to get the name and funding stream so we set them on input model here
                        calculationCreateModel.SpecificationName = specificationSummary.Name;

                        //only validate funding stream ids for template calcs
                        if (!isTemplateCalculation)
                        {
                            return;
                        }

                        Reference fundingStream = specificationSummary.FundingStreams.FirstOrDefault(m => m.Id == calculationCreateModel.FundingStreamId);

                        if (fundingStream == null)
                        {
                            context.AddFailure("The funding stream id provided is not associated with the provided specification.");
                        }
                        else
                        {
                            calculationCreateModel.FundingStreamName = fundingStream.Name;
                        }
                    }
                }
            });
        }
        public CalculationEditModelValidator(
            IPreviewService previewService,
            ICalculationsRepository calculationRepository)
        {
            Guard.ArgumentNotNull(previewService, nameof(previewService));
            Guard.ArgumentNotNull(calculationRepository, nameof(calculationRepository));

            _previewService        = previewService;
            _calculationRepository = calculationRepository;

            RuleFor(model => model.SpecificationId)
            .NotEmpty()
            .NotNull()
            .WithMessage("Null or empty specification id provided.");

            RuleFor(model => model.ValueType)
            .NotNull()
            .WithMessage("Null value type was provided.");

            RuleFor(model => model.CalculationId)
            .NotEmpty()
            .NotNull()
            .WithMessage("Null or empty calculation id provided.");

            RuleFor(model => model.Name)
            .Custom((name, context) =>
            {
                CalculationEditModel calculationEditModel = context.ParentContext.InstanceToValidate as CalculationEditModel;
                if (string.IsNullOrWhiteSpace(calculationEditModel.Name))
                {
                    context.AddFailure("Null or empty calculation name provided.");
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(calculationEditModel.SpecificationId))
                    {
                        Calculation calculation = _calculationRepository.GetCalculationsBySpecificationIdAndCalculationName(calculationEditModel.SpecificationId, calculationEditModel.Name).Result;

                        if (calculation != null && calculation.Id != calculationEditModel.CalculationId)
                        {
                            context.AddFailure($"A calculation already exists with the name: '{calculationEditModel.Name}' for this specification");
                        }
                    }
                }
            });

            RuleFor(model => model.SourceCode)
            .Custom((sc, context) =>
            {
                CalculationEditModel calculationEditModel = context.ParentContext.InstanceToValidate as CalculationEditModel;
                if (string.IsNullOrWhiteSpace(calculationEditModel.SourceCode))
                {
                    context.AddFailure("Null or empty source code provided.");
                }
                else
                {
                    PreviewRequest previewRequest = new PreviewRequest
                    {
                        SpecificationId = calculationEditModel.SpecificationId,
                        CalculationId   = calculationEditModel.CalculationId,
                        Name            = calculationEditModel.Name,
                        SourceCode      = calculationEditModel.SourceCode,
                        DataType        = calculationEditModel.DataType
                    };

                    IActionResult result = _previewService.Compile(previewRequest).Result;

                    OkObjectResult okObjectResult = result as OkObjectResult;

                    if (okObjectResult.Value is PreviewResponse response)
                    {
                        if (!response.CompilerOutput.CompilerMessages.IsNullOrEmpty())
                        {
                            context.AddFailure("There are errors in the source code provided");
                        }
                    }
                }
            });
        }