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 async Task <IActionResult> UpdateParameter(long scriptId, long parId, [FromBody] UpdateParameterCommand command) { command.ScriptId = scriptId; await Mediator.Send(command); return(NoContent()); }
public void WhenExecuteCommandWithoutRegisteredKeyAndValue_CommandManager_ShouldUpdate() { string key = "my.param"; string value = "my new value"; var storedDataService = new StoredDataServiceMock() { ReturnBoolExistsParameter = true }; var commandDefinition = new UpdateParameterCommand(storedDataService); var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock); instance.RegisterCommand(commandDefinition); var inputRequest = new InputRequest( commandDefinition.GetInvocationCommandName(), commandDefinition.CommandKeyParameter.GetInvokeName(), key, commandDefinition.CommandValueParameter.GetInvokeName(), value); instance.ExecuteInputRequest(inputRequest); var expectedKey = key; var actualKey = storedDataService.UpdatedParameterKey; Assert.Equal(expectedKey, actualKey); var expectedValue = value; var actualValue = storedDataService.UpdatedParameterValue; Assert.Equal(expectedValue, actualValue); }
private async void OnCommitCreateParameter() { if (!(SelectedEventParameter.Id == 0 && SelectedEventParameter.IsValid())) { MessageBox.Show("Error. Make sure that the new parameter is selected and that Property Name and Variable fields have values.", AppName, MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBoxResult messageBoxResult = MessageBox.Show("Proceed with creation? Click Cancel to continue editing or No to discard changes.", AppName, MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (messageBoxResult == MessageBoxResult.Cancel) { return; } else if (messageBoxResult == MessageBoxResult.No) { OnCancelCreateParameter(); } else { //Create Event Parameter if Yes string result = await _eventParameterService.CreateEventParameter(SelectedEvent.Id, SelectedEventParameter); MessageBox.Show(result, AppName, MessageBoxButton.OK, MessageBoxImage.Information); GetEventParameters(SelectedEvent.Id); } CreatingItem = false; CreateParameterCommand.RaiseCanExecuteChanged(); UpdateParameterCommand.RaiseCanExecuteChanged(); DeleteParameterCommand.RaiseCanExecuteChanged(); RefreshParametersCommand.RaiseCanExecuteChanged(); }
private void OnCancelCreateParameter() { GetEventParameters(SelectedEvent.Id); CreatingItem = false; CreateParameterCommand.RaiseCanExecuteChanged(); UpdateParameterCommand.RaiseCanExecuteChanged(); DeleteParameterCommand.RaiseCanExecuteChanged(); RefreshParametersCommand.RaiseCanExecuteChanged(); }
//Parameter commands private void OnCreateParameter() { //Adds a blank entry to the EventParameters collection EventParameter eventParameter = new EventParameter(); eventParameter.PropertyName = ""; eventParameter.MappedTo_Input_X = ""; eventParameter.WFProfileId = 0; EventParameters.Add(eventParameter); SelectedEventParameter = eventParameter; CreatingItem = true; CreateParameterCommand.RaiseCanExecuteChanged(); UpdateParameterCommand.RaiseCanExecuteChanged(); DeleteParameterCommand.RaiseCanExecuteChanged(); RefreshParametersCommand.RaiseCanExecuteChanged(); }
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); }
public void WhenExecuteCommandWithoutCommandKey_CommandManager_ShouldThrowException() { string value = "my value"; var storedDataService = new StoredDataServiceMock(); var commandDefinition = new UpdateParameterCommand(storedDataService); var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock); instance.RegisterCommand(commandDefinition); var inputRequest = new InputRequest( commandDefinition.GetInvocationCommandName(), commandDefinition.CommandValueParameter.GetInvokeName(), value); Assert.Throws <InvalidParamsException>(() => { instance.ExecuteInputRequest(inputRequest); }); }
public async Task <ViewCommand> ProcessRelationActionAsync(UsageType usageType, string collectionAlias, IEntity relatedEntity, string id, EditContext editContext, string actionId, object?customData) { var collection = _collectionProvider.GetCollection(collectionAlias); var button = collection.FindButton(actionId); if (button == null) { throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}"); } await EnsureAuthorizedUserAsync(editContext, button); EnsureValidEditContext(editContext, button); var relationContainer = editContext.GenerateRelationContainer(); // since the id is known, get the entity variant from the entity var entityVariant = collection.GetEntityVariant(editContext.Entity); ViewCommand viewCommand; var context = new ButtonContext(null, customData); switch (await button.ButtonClickBeforeRepositoryActionAsync(editContext, context)) { case CrudType.View: viewCommand = new NavigateCommand { Uri = UriHelper.Node(Constants.View, collectionAlias, entityVariant, null, id) }; break; case CrudType.Edit: viewCommand = new NavigateCommand { Uri = UriHelper.Node(Constants.Edit, collectionAlias, entityVariant, null, id) }; break; case CrudType.Update: await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalUpdateAsync(id, null, editContext.Entity, relationContainer)); viewCommand = new ReloadCommand(id); break; case CrudType.Insert: var insertedEntity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalInsertAsync(null, editContext.Entity, relationContainer)); if (insertedEntity == null) { throw new Exception("Inserting the new entity failed."); } editContext.SwapEntity(insertedEntity); await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalAddAsync(relatedEntity, editContext.Entity.Id)); viewCommand = new UpdateParameterCommand { Action = Constants.New, CollectionAlias = collectionAlias, VariantAlias = entityVariant.Alias, ParentId = null, Id = editContext.Entity.Id }; break; case CrudType.Delete: await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalDeleteAsync(id, null)); viewCommand = new ReloadCommand(); break; case CrudType.Pick: await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalAddAsync(relatedEntity, id)); viewCommand = new ReloadCommand(); break; case CrudType.Remove: await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalRemoveAsync(relatedEntity, id)); viewCommand = new ReloadCommand(); break; case CrudType.None: viewCommand = new NoOperationCommand(); break; case CrudType.Refresh: viewCommand = new ReloadCommand(); break; default: throw new InvalidOperationException(); } await button.ButtonClickAfterRepositoryActionAsync(editContext, context); return(viewCommand); }
public async Task <ViewCommand> ProcessRelationActionAsync(UsageType usageType, string collectionAlias, IEntity relatedEntity, IEnumerable <EditContext> editContexts, string actionId, object?customData) { var collection = _collectionProvider.GetCollection(collectionAlias); var button = collection.FindButton(actionId); if (button == null) { throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}"); } var rootEditContext = await GetRootEditContextAsync(usageType, collectionAlias, null); var newEntity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalNewAsync(null, collection.EntityVariant.Type)); await EnsureAuthorizedUserAsync(rootEditContext, button); ViewCommand viewCommand; var context = new ButtonContext(null, customData); switch (await button.ButtonClickBeforeRepositoryActionAsync(rootEditContext, context)) { case CrudType.Create: if (button.EntityVariant == null) { throw new InvalidOperationException(); } if (usageType.HasFlag(UsageType.List)) { viewCommand = new NavigateCommand { Uri = UriHelper.Node(Constants.New, collectionAlias, button.EntityVariant, null, null) }; } else { viewCommand = new UpdateParameterCommand { Action = Constants.New, CollectionAlias = collectionAlias, VariantAlias = button.EntityVariant.Alias, ParentId = null, Id = null }; } break; case CrudType.Update: var contextsToProcess = editContexts.Where(x => x.IsModified()).Where(x => button.RequiresValidForm(x) ? x.IsValid() : true); var affectedEntities = new List <IEntity>(); foreach (var editContext in contextsToProcess) { try { var updatedEntity = editContext.Entity; await EnsureAuthorizedUserAsync(editContext, button); EnsureValidEditContext(editContext, button); var relationContainer = editContext.GenerateRelationContainer(); await EnsureCorrectConcurrencyAsync(() => collection.Repository.InternalUpdateAsync(updatedEntity.Id, null, updatedEntity, relationContainer)); affectedEntities.Add(updatedEntity); } catch (Exception) { // do not care about exceptions here } } viewCommand = new ReloadCommand(affectedEntities.Select(x => x.Id)); break; case CrudType.Add: viewCommand = new UpdateParameterCommand { Action = Constants.Add, CollectionAlias = collectionAlias, VariantAlias = null, ParentId = null, Id = null }; break; case CrudType.None: viewCommand = new NoOperationCommand(); break; case CrudType.Refresh: viewCommand = new ReloadCommand(); break; case CrudType.Return: viewCommand = new ReturnCommand(); break; default: throw new InvalidOperationException(); } await button.ButtonClickAfterRepositoryActionAsync(rootEditContext, context); return(viewCommand); }
public async Task <ViewCommand> ProcessListActionAsync(UsageType usageType, string collectionAlias, ParentPath?parentPath, IEnumerable <EditContext> editContexts, string actionId, object?customData) { var collection = _collectionProvider.GetCollection(collectionAlias); var button = collection.FindButton(actionId); if (button == null) { throw new Exception($"Cannot determine which button triggered action for collection {collectionAlias}"); } var parent = await _parentService.GetParentAsync(parentPath); var rootEditContext = await GetRootEditContextAsync(usageType, collectionAlias, parent); var entity = await EnsureCorrectConcurrencyAsync(() => collection.Repository.NewAsync(parent, collection.EntityVariant.Type)); await EnsureAuthorizedUserAsync(rootEditContext, button); ViewCommand viewCommand; var context = new ButtonContext(parent, customData); switch (await button.ButtonClickBeforeRepositoryActionAsync(rootEditContext, context)) { case CrudType.Create: if (button.EntityVariant == null) { throw new InvalidOperationException($"Button of type {CrudType.Create} must an {nameof(button.EntityVariant)}."); } if (usageType.HasFlag(UsageType.List)) { viewCommand = new NavigateCommand { Uri = UriHelper.Node(Constants.New, collectionAlias, button.EntityVariant, parentPath, null) }; } else { viewCommand = new UpdateParameterCommand { Action = Constants.New, CollectionAlias = collectionAlias, VariantAlias = button.EntityVariant.Alias, ParentPath = parentPath?.ToPathString(), Id = null }; } break; case CrudType.Update: var contextsToProcess = editContexts.Where(x => x.IsModified()).Where(x => button.RequiresValidForm(x) ? x.IsValid() : true); var affectedEntities = new List <IEntity>(); foreach (var editContext in contextsToProcess) { try { await EnsureAuthorizedUserAsync(editContext, button); EnsureValidEditContext(editContext, button); await EnsureCorrectConcurrencyAsync(() => collection.Repository.UpdateAsync(editContext)); affectedEntities.Add(editContext.Entity); } catch (Exception) { // do not care about any exception in this case } } viewCommand = new ReloadCommand(affectedEntities.SelectNotNull(x => x.Id)); break; case CrudType.None: viewCommand = new NoOperationCommand(); break; case CrudType.Refresh: viewCommand = new ReloadCommand(); break; case CrudType.Return: viewCommand = new NavigateCommand { Uri = UriHelper.Collection(Constants.Edit, collectionAlias, parentPath) }; break; case CrudType.Up: var(newParentPath, parentCollectionAlias, parentId) = ParentPath.RemoveLevel(parentPath); if (parentCollectionAlias == null) { return(new NoOperationCommand()); } var parentCollection = _collectionProvider.GetCollection(parentCollectionAlias); viewCommand = new NavigateCommand { Uri = UriHelper.Node( usageType.HasFlag(UsageType.Edit) ? Constants.Edit : Constants.List, parentCollectionAlias, parentCollection.EntityVariant, newParentPath, parentId) }; break; default: throw new InvalidOperationException(); } await button.ButtonClickAfterRepositoryActionAsync(rootEditContext, context); return(viewCommand); }
private void OnTargetParameterUpdated(Object sender, EventArgs e) { UpdateParameterCommand.RaiseCanExecuteChanged(); }