public async Task <ActionResult> Delete(int id) { var command = new DeleteIngredientCommand(id); await _mediator.Send(command); return(NoContent()); }
public async Task <ActionResult <string> > DeleteIngredient([FromBody] Guid id) { var deleteCommand = new DeleteIngredientCommand(id); var response = await _mediator.Send(deleteCommand); return(string.IsNullOrEmpty(response) ? (ActionResult <string>)Ok(id) : BadRequest(response)); }
public void IngredientDoesntExist_ShouldNotThrow() { // arrange this.MockIngredientRepository.Setup(m => m.Read(It.IsAny <int>())).Returns(() => throw new IngredientNotFoundException()); var command = new DeleteIngredientCommand(int.MaxValue); // act Action act = () => this.DomainServices.RunCommand(command); // assert act.Should().Throw <IngredientNotFoundException>(); }
public void HappyPath() { // arrange var createCommand = this.IngredientDataProvider.CreateCommand(); this.RunCommand(createCommand); var deleteCommand = new DeleteIngredientCommand(createCommand.Id.Value); // act this.RunCommand(deleteCommand); // assert Action actual = () => this.RunQuery(new GetIngredientByIdQuery(deleteCommand.IngredientId)); actual.Should().Throw <IngredientNotFoundException>(); }
public void SetUp() { _ingredientRepositoryMock = new Mock <IIngredientRepository>(); _eventPublisherMock = new Mock <IEventPublisher>(); _ingredientRepositoryMock.Setup(x => x.ExistByName(It.IsAny <string>())) .Returns(false); _recipeRepositoryMock = new Mock <IRecipeRepository>(); _command = new DeleteIngredientCommand(Guid.NewGuid()); _ingredient = FakeIngredientFactory.CreateValidIngredient( Guid.NewGuid(), "Ingredient", 0.2, 0.3, 0.4, _ingredientRepositoryMock.Object); _systemUnderTest = new DeleteIngredientCommandHandler(_ingredientRepositoryMock.Object, _eventPublisherMock.Object); }
public async Task <IActionResult> DeleteIngredient([FromRoute] DeleteIngredientCommand command) { var validationResult = _validators.ValidateDelete(command); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } var result = await _mediator.Command(command); if (!result.IsFailure) { return(Ok(result)); } if (result.ResultCode.Equals(ResultCode.NotFound)) { return(NotFound(result)); } return(BadRequest(result)); }
public ValidationResult ValidateDelete(DeleteIngredientCommand command) => _deleteValidator.Validate(command);