public void InvalidModel_ShouldThrow() { // arrange var command = new CreateIngredientCommand(); // act Action act = () => this.RunCommand(command); // assert act.Should().Throw <ValidationException>(); }
public void SetUp() { _ingredientRepositoryMock = new Mock <IIngredientRepository>(); _ingredientFactoryMock = new Mock <IIngredientFactory>(); _eventPublisherMock = new Mock <IEventPublisher>(); _validators = new List <ICommandValidator <CreateIngredientCommand> > { new UniqueIngredientByNameValidator(_ingredientRepositoryMock.Object) }; _command = CommandFactory.EmptyCreateIngredientCommand(); _systemUnderTest = new CreateIngredientCommandHandler( _ingredientFactoryMock.Object, _eventPublisherMock.Object, _validators); }
public async Task <IActionResult> CreateIngredient([FromBody] CreateIngredientCommand command) { var validationResult = _validators.ValidateCreate(command); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } var result = await _mediator.Command(command); if (result.IsSuccess) { return(Created($"api/ingredient{command.Id.ToString()}", result)); } return(BadRequest(result)); }
public ValidationResult ValidateCreate(CreateIngredientCommand command) => _createValidator.Validate(command);
public async Task <IActionResult> Create([FromBody] CreateIngredientCommand command) { return(Ok(await mediator.Send(command))); }
public async Task <IActionResult> CreateIngredient(CreateIngredientCommand command) { await Mediator.Send(command); return(NoContent()); }