public async Task Hanlde_DeletePropertyCommand_RemovesPropertyDefinitionFromProjectAsync() { // arrange var project = CreateProject(); var entity = project.Schema.Entities.First(); var property = entity.Properties.First(); var command = new DeletePropertyCommand { Id = project.Id, PropertyId = property.Id }; var session = new Mock <ISession>(); session.Setup(s => s.Get <Project>(project.Id, command.ExpectedVersion, It.IsAny <CancellationToken>())).Returns(Task.FromResult(project)); var target = new ProjectCommandHandler(session.Object); // act await target.Handle(command); // assert var entityDefinition = entity.Properties.FirstOrDefault(e => e.Id == property.Id); Assert.Null(entityDefinition); session.Verify(s => s.Commit(It.IsAny <CancellationToken>())); }
internal override DeleteEFElementCommand GetDeleteCommand() { DeleteEFElementCommand cmd = new DeletePropertyCommand(this); if (cmd == null) { // shouldn't happen, just to be safe throw new InvalidOperationException(); } return(cmd); }
public async Task <IActionResult> DeleteProperty(Guid projectId, Guid entityId, Guid id) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var currentProject = await this.dbContext.Projects .Include(p => p.Entities) .ThenInclude(p => p.Properties) .SingleOrDefaultAsync(p => p.Id == projectId); if (currentProject == null) { return(this.NoContent()); } var currentEntity = currentProject.Entities.FirstOrDefault(p => p.Id == entityId); if (currentEntity == null) { return(this.NoContent()); } var currentProperty = currentEntity.Properties.FirstOrDefault(p => p.Id == id); if (currentProperty == null) { return(this.NoContent()); } var command = new DeletePropertyCommand { Id = projectId, ExpectedVersion = currentProject.Version, PropertyId = id }; await this.commandSender.Send(command); return(this.NoContent()); }
public async Task <IActionResult> RemoveProperty(DeletePropertyCommand command) { var result = await _mediator.Send(command); return(Ok(result)); }