示例#1
0
        public async void ShouldUpdateCorrectly()
        {
            var mediatorMock = new Mock <IMediator>();
            var controller   = new RecipeController(mediatorMock.Object);

            var model = new UpdateRecipeModel
            {
                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.Update(new Guid("F3583BB5-DCD4-4161-990F-CF97D7156B97"), model);

            mediatorMock.Verify(
                x => x.Send(
                    It.Is <UpdateRecipe>(y
                                         => y.WithDeepEqual(model.Map(new Guid("F3583BB5-DCD4-4161-990F-CF97D7156B97")))
                                         .IgnoreSourceProperty(z => z.EntityId)
                                         .Compare()
                                         ),
                    It.IsAny <CancellationToken>()), Times.Once);

            mediatorMock.VerifyNoOtherCalls();
        }
示例#2
0
        public void ShouldMapCorrectlyWithoutPictureUrl()
        {
            var model = new UpdateRecipeModel
            {
                Name        = "sample-name",
                Description = "sample-description",
                Calories    = 1234,
                Steps       = new[] { "sample-step" },
                Ingredients = new[] { "sample-ingredient" }
            };

            var command = model.Map(new Guid("90DC09C8-F746-4886-BB58-45AE361D3FB7"));

            command.EntityId.Should().Be(new Guid("90DC09C8-F746-4886-BB58-45AE361D3FB7"));
            command.Name.Should().BeEquivalentTo("sample-name");
            command.Description.Should().BeEquivalentTo("sample-description");
            command.PictureUrl.Should().BeNullOrEmpty();
            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");
        }
示例#3
0
        public async Task <IActionResult> Update(Guid id, UpdateRecipeModel model)
        {
            await _mediator.Send(model.Map(id));

            return(Ok());
        }