public async Task SetParameterTranslation(string languageCode, ParameterResource parameterResource, Language defaultLanguage)
        {
            if (Languages.ContainsKey(languageCode) && Languages[languageCode] != defaultLanguage)
            {
                var parameterTranslation = await _translationRepository.GetParameterTranslation(parameterResource.Id, Languages[languageCode]);

                if (parameterTranslation == null)
                {
                    return;
                }
                if (parameterTranslation.Description != null)
                {
                    parameterResource.Description = parameterTranslation.Description;
                }
                if (parameterTranslation.Notes != null)
                {
                    parameterResource.Notes = parameterTranslation.Notes;
                }
                if (parameterTranslation.GroupName != null)
                {
                    parameterResource.GroupName = parameterTranslation.GroupName;
                }
                foreach (var valueOption in parameterResource.ValueOptions)
                {
                    await SetValueOptionTranslation(languageCode, valueOption, defaultLanguage);
                }
            }
            return;
        }
        public void UpdateParameterTest_NoneParameter_Success()
        {
            var parameterResource = new ParameterResource();
            var script            = new Script();

            _scriptRepository.Setup(sr => sr.GetAsync(1))
            .Returns(Task.FromResult(script));
            _parameterRepository.Setup(pr => pr.GetParameterWithAllDependanciesAsync(2))
            .Returns(Task.FromResult(default(Parameter)));

            var scriptMappingProfile = new Mock <IScriptMappingProfile>();

            var dateTime = new Mock <IDateTime>();

            dateTime.Setup(dt => dt.Now).Returns(new System.DateTime());

            var updateParameterCommand = new UpdateParameterCommand.Handler(
                _scriptRepository.Object, _parameterRepository.Object,
                _unitOfWork.Object, scriptMappingProfile.Object, dateTime.Object);

            var cancellationToken = CancellationToken.None;
            var command           = new UpdateParameterCommand
            {
                ScriptId     = 1,
                Name         = "new",
                ValueOptions = new List <ValueOptionResource>(),
                Id           = 2
            };

            Assert.ThrowsAsync <NotFoundException>(() => updateParameterCommand.Handle(command, cancellationToken));
        }
        public void CreateParameterTest_NoScript_Success()
        {
            var parameterResource = new ParameterResource();

            _scriptRepository.Setup(sr => sr.GetAsync(1)).Returns(Task.Run(() => default(Script)));

            var scriptMappingProfile = new Mock <IScriptMappingProfile>();

            var dateTime = new Mock <IDateTime>();

            dateTime.Setup(dt => dt.Now).Returns(new System.DateTime());

            var createParameterCommand = new CreateParameterCommand.Handler(
                _scriptRepository.Object, _parameterRepository.Object,
                _unitOfWork.Object, scriptMappingProfile.Object, dateTime.Object);

            var command = new CreateParameterCommand
            {
                ScriptId     = 1,
                Name         = "new",
                ValueOptions = new List <ValueOptionResource>()
            };

            Assert.ThrowsAsync <NotFoundException>(() => createParameterCommand.Handle(command, CancellationToken.None));
        }
Example #4
0
        private void RemoveNotAddedValueOptions(ParameterResource parameterResource, Parameter parameter)
        {
            var removedValueOptions = parameter.ValueOptions.Where(vo =>
                                                                   !parameterResource.ValueOptions.Select(vor => vor.Id).Contains(vo.Id)).ToList();

            foreach (var valueOption in removedValueOptions)
            {
                parameter.ValueOptions.Remove(valueOption);
            }
        }
Example #5
0
        private void RemoveNotAddedPhotos(ParameterResource parameterResource, Parameter parameter)
        {
            var removedFigures = parameter.ParameterFigures
                                 .Where(pp => !parameterResource.Figures.Select(pr => pr.Id).Contains(pp.FigureId)).ToList();

            foreach (var figure in removedFigures)
            {
                parameter.ParameterFigures.Remove(figure);
            }
        }
Example #6
0
        private void AddNewPhotos(ParameterResource parameterResource, Parameter parameter)
        {
            var addedFigures = parameterResource.Figures
                               .Where(pr => !parameter.ParameterFigures.Any(pp => pp.FigureId == pr.Id))
                               .Select(pr => new ParameterFigure {
                FigureId = pr.Id
            }).ToList();

            foreach (var figure in addedFigures)
            {
                parameter.ParameterFigures.Add(figure);
            }
        }
Example #7
0
 private void UpdateValueOptions(ParameterResource parameterResource, Parameter parameter)
 {
     foreach (var valueOptionResource in parameterResource.ValueOptions)
     {
         var valueOption = parameter.ValueOptions.FirstOrDefault(vo => vo.Id == valueOptionResource.Id);
         if (valueOption == null)
         {
             continue;
         }
         valueOption.Name        = valueOptionResource.Name;
         valueOption.Value       = valueOptionResource.Value;
         valueOption.Description = valueOptionResource.Description;
     }
 }
Example #8
0
        private void AddNewValueOptions(ParameterResource parameterResource, Parameter parameter)
        {
            var addedValueOptions = parameterResource.ValueOptions
                                    .Where(vor => !parameter.ValueOptions.Any(vo => vo.Id == vor.Id))
                                    .Select(vor =>
                                            new ValueOption {
                Name = vor.Name, Description = vor.Description, Value = vor.Value
            }
                                            ).ToList();

            foreach (var valueOption in addedValueOptions)
            {
                parameter.ValueOptions.Add(valueOption);
            }
        }
        public void UpdateParameterTest_Success()
        {
            var script            = new Script();
            var parameterResource = new ParameterResource();
            var parameter         = new Parameter {
                Name = "a"
            };

            _scriptRepository.Setup(sr => sr.GetAsync(1))
            .Returns(Task.FromResult(script));
            _parameterRepository.Setup(pr => pr.GetParameterWithAllDependanciesAsync(2))
            .Returns(Task.FromResult(parameter));
            _unitOfWork.Setup(uow => uow.CompleteAsync())
            .Returns(Task.FromResult(1));

            var scriptMappingProfile = new Mock <IScriptMappingProfile>();

            var dateTime = new Mock <IDateTime>();

            dateTime.Setup(dt => dt.Now).Returns(new System.DateTime());

            var updateParameterCommand = new UpdateParameterCommand.Handler(
                _scriptRepository.Object, _parameterRepository.Object,
                _unitOfWork.Object, scriptMappingProfile.Object, dateTime.Object);

            var cancellationToken = CancellationToken.None;
            var command           = new UpdateParameterCommand
            {
                ScriptId     = 1,
                Name         = "new",
                ValueOptions = new List <ValueOptionResource>(),
                Id           = 2
            };
            var result = updateParameterCommand.Handle(command, cancellationToken).Result;

            _scriptRepository.Verify(sr => sr.GetAsync(1));
            _parameterRepository.Verify(pr => pr.GetParameterWithAllDependanciesAsync(2));
            _unitOfWork.Verify(uow => uow.CompleteAsync());
            scriptMappingProfile.Verify(smp => smp.UpdateValueOptions(command.ValueOptions, It.IsAny <Parameter>()));
            scriptMappingProfile.Verify(smp => smp.RemoveNotAddedValueOptions(command.ValueOptions, It.IsAny <Parameter>()));
            scriptMappingProfile.Verify(smp => smp.AddNewValueOptions(command.ValueOptions, It.IsAny <Parameter>()));
            dateTime.Verify(dt => dt.Now);
            Assert.That(result, Is.Not.Null);
        }