Example #1
0
        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");
        }
Example #2
0
        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();
        }
Example #3
0
        public async Task <IActionResult> Add(CreateRecipeModel model)
        {
            await _mediator.Send(model.Map());

            return(Ok());
        }
Example #4
0
        public async Task <ActionResult <string> > CreateRecipeAsync([BindRequired, FromBody] CreateRecipeModel model)
        {
            var result = await Mediator.Send(new CreateRecipeCommand { RecipeModel = model });

            return(Item(result));
        }