private void OnRecipeUpdated(RecipeUpdated @event)
        {
            var recipe = Recipes.FirstOrDefault(x => x.Id == @event.Recipe.Id);

            if (recipe == null)
            {
                return;
            }
            // Ugly but true
            recipe.Title          = @event.Recipe.Title;
            recipe.Category       = @event.Recipe.Category.Title;
            recipe.CookingMinutes = @event.Recipe.CookingMinutes;
            recipe.CookingSteps   = @event.Recipe.CookingSteps
                                    .Select((x, i) => new CookingStepDisplayViewModel {
                Position = i + 1, Text = x
            })
                                    .ToList();
            recipe.ImageUri    = @event.Recipe.ImageUri;
            recipe.Ingredients = @event.Recipe.Ingredients
                                 .Select((x, i) => new IngredientDisplayViewModel
            {
                Measure  = x.Measure,
                Title    = x.Title,
                Quantity = x.Quantity,
                Position = i + 1
            })
                                 .ToList();
            recipe.Notes = @event.Recipe.Notes;
        }
        public void Does_Map_Update_Recipe_Work_Correctly()
        {
            var dto = new UpdateRecipe
            {
                EntityId    = Guid.Parse("be3dc63e-8f22-4d05-84b1-5fa6f4f652c4"),
                Name        = "Pizza Hawajska",
                Calories    = 1200,
                Description = "Smaczna i zdrowa!",
                MealTypes   = new[] { MealType.Snack, MealType.Lunch },
                PictureUrl  = "https://localhost:5001/img/pizza_hawajska.png",
                Steps       = new[] { "Go into website and order it via phone!", "Wait for pizza boy to come and collect it from him." },
                Ingredients = new[] { "1x Phone" }
            };
            var expected = new RecipeUpdated
            {
                EntityId    = Guid.Parse("be3dc63e-8f22-4d05-84b1-5fa6f4f652c4"),
                Name        = "Pizza Hawajska",
                Calories    = 1200,
                Description = "Smaczna i zdrowa!",
                MealTypes   = new[] { MealType.Snack, MealType.Lunch },
                PictureUrl  = "https://localhost:5001/img/pizza_hawajska.png",
                Steps       = new[] { "Go into website and order it via phone!", "Wait for pizza boy to come and collect it from him." },
                Ingredients = new[] { "1x Phone" },
                AuthorId    = "7f7dfc41-3b52-4c43-aef9-b82099a7beb2",
                Published   = new DateTime(2020, 10, 10, 5, 2, 1),
            };
            var userId = "7f7dfc41-3b52-4c43-aef9-b82099a7beb2";
            var date   = new DateTime(2020, 10, 10, 5, 2, 1);

            var result = _mapper.Map(dto, date, userId);

            result.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 3
0
        private void OnRecipeUpdated(RecipeUpdated @event)
        {
            var old = _recipes.FirstOrDefault(x => x.Id == @event.Recipe.Id);

            if (old == null)
            {
                return;
            }
            var index = _recipes.IndexOf(old);

            Recipes[index] = @event.Recipe.ToRecipeListItemViewModel(_messenger);
        }
        public async void ShouldUpdateRecipeCorrectly()
        {
            // "051F13A0-4796-4B1C-9797-EC99F08CF25E" - sample recipe id to update
            var command = new UpdateRecipe
            {
                EntityId    = new Guid("051F13A0-4796-4B1C-9797-EC99F08CF25E"),
                Name        = "sample-name",
                Description = "sample-description",
                PictureUrl  = "https://example.com/sample-picture.png",
                Calories    = 1234,
                MealTypes   = new[] { MealType.Snack },
                Steps       = new[] { "1. Sample first step.", "2. Sample second step." },
                Ingredients = new[] { "Sample first ingredient", "Sample second ingredient" }
            };
            var eventStore = new Mock <IEventStore <Recipe> >();
            var handler    = new UpdateRecipeHandler(eventStore.Object, MockBuilder.BuildFakeRecipeEventsMapper(), MockBuilder.BuildFakeCurrentUserService(), MockBuilder.BuildFakeDateTimeService());

            await handler.Handle(command, CancellationToken.None);

            var expected = new RecipeUpdated
            {
                EntityId    = new Guid("051F13A0-4796-4B1C-9797-EC99F08CF25E"),
                Published   = new DateTime(2010, 1, 1),
                Version     = 0,
                AuthorId    = "9E09950B-47DE-4BAB-AA79-C29414312ECB",
                Name        = "sample-name",
                Description = "sample-description",
                PictureUrl  = "https://example.com/sample-picture.png",
                Calories    = 1234,
                MealTypes   = new[] { MealType.Snack },
                Steps       = new[] { "1. Sample first step.", "2. Sample second step." },
                Ingredients = new[] { "Sample first ingredient", "Sample second ingredient" }
            };

            eventStore.Verify(x => x.AddEvent(It.Is <RecipeUpdated>(y => y.WithDeepEqual(expected).Compare())));
        }