public void ShouldMapCorrectly() { var model = new CreateRecipeModel { Name = "sample-name", Description = "sample-description", PictureUrl = "https://example.com/sample-picture.png", Calories = 1234, Steps = new[] { "sample-step" }, Ingredients = new[] { "sample-ingredient" } }; var command = model.Map(); command.Name.Should().BeEquivalentTo("sample-name"); command.Description.Should().BeEquivalentTo("sample-description"); command.PictureUrl.Should().BeEquivalentTo("https://example.com/sample-picture.png"); command.Calories.Should().Be(1234); command.Steps .Should().HaveCount(1) .And.ContainSingle(x => x == "sample-step"); command.Ingredients .Should().HaveCount(1) .And.ContainSingle(x => x == "sample-ingredient"); }
public async void ShouldAddCorrectly() { var mediatorMock = new Mock <IMediator>(); var controller = new RecipeController(mediatorMock.Object); var model = new CreateRecipeModel { Name = "sample-name", Description = "sample-description", PictureUrl = "https://example.com/sample-picture.png", Calories = 1234, MealTypes = new[] { MealType.Snack }, Steps = new[] { "sample-step" }, Ingredients = new[] { "sample-ingredient" } }; await controller.Add(model); mediatorMock.Verify(x => x.Send( It.Is <CreateRecipe>(y => y.IsDeepEqual(model.Map())), It.IsAny <CancellationToken>() ), Times.Once); mediatorMock.VerifyNoOtherCalls(); }
public async Task <IActionResult> Add(CreateRecipeModel model) { await _mediator.Send(model.Map()); return(Ok()); }
public async Task <ActionResult <string> > CreateRecipeAsync([BindRequired, FromBody] CreateRecipeModel model) { var result = await Mediator.Send(new CreateRecipeCommand { RecipeModel = model }); return(Item(result)); }