Exemple #1
0
        public async void DoesValidatorAllowCorrectRequest()
        {
            var request   = new DeleteRecipe(new Guid("447EA0EF-F828-486A-91A9-0EDBC01D0B89"));
            var validator = new DeleteRecipeValidator(MockBuilder.BuildFakeRepository(), MockBuilder.BuildFakeCurrentUserService());

            var result = await validator.ValidateAsync(request);

            result.IsValid.Should().BeTrue();
        }
Exemple #2
0
        public async void DoesValidatorPreventFromDeletingNotExistingRecipe()
        {
            var request   = new DeleteRecipe(new Guid("E9AFD20D-C83C-493B-827B-2220433E4D5E"));
            var validator = new DeleteRecipeValidator(MockBuilder.BuildFakeRepository(), MockBuilder.BuildFakeCurrentUserService());

            var result = await validator.ValidateAsync(request);

            result.IsValid.Should().BeFalse();
        }
Exemple #3
0
        public async void ShouldCreateRecipeCorrectly()
        {
            var command = new CreateRecipe
            {
                Name        = "sample-name",
                Description = "sample-description",
                PictureUrl  = "https://example.com/sample-image.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 CreateRecipeHandler(eventStore.Object, MockBuilder.BuildFakeRecipeEventsMapper(), MockBuilder.BuildFakeCurrentUserService(), MockBuilder.BuildFakeDateTimeService());

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

            var expected = new RecipeCreated
            {
                EntityId    = new Guid("7ADC9EF0-6A2A-4DE5-9C27-D4C2A4D9D5B6"),
                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-image.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 <RecipeCreated>(y
                                                                    => y.WithDeepEqual(expected).IgnoreSourceProperty(z => z.EntityId).Compare()
                                                                    )));
        }
        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())));
        }
        public async Task ShouldRestoreRecipeCorrectly()
        {
            var request = new RestoreRecipe
            {
                EntityId = Guid.Parse("21552e39-3c5a-42e6-a116-e9f54643e57c")
            };
            var handler = new RestoreRecipeHandler(_eventStore.Object, MockBuilder.BuildFakeRecipeEventsMapper(), MockBuilder.BuildFakeDateTimeService(), MockBuilder.BuildFakeCurrentUserService());

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

            var expected = new RecipeRestored
            {
                EntityId  = Guid.Parse("21552e39-3c5a-42e6-a116-e9f54643e57c"),
                Published = new DateTime(2010, 1, 1),
                AuthorId  = "edb4a387-260e-43c1-aed8-eec4dbd0fc31"
            };

            _eventStore.Verify(x => x.AddEvent(It.Is <RecipeRestored>(y => y.WithDeepEqual(expected).Compare())));
        }
        public async void DoesValidatorPreventFromUpdatingRecipeWithNoDescription()
        {
            var request = new UpdateRecipe
            {
                EntityId    = new Guid("447EA0EF-F828-486A-91A9-0EDBC01D0B89"),
                Name        = "sample-name",
                Description = string.Empty,
                PictureUrl  = "https://example.com/sample-image.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 validator = new UpdateRecipeValidator(MockBuilder.BuildFakeRepository(), MockBuilder.BuildFakeCurrentUserService());

            var result = await validator.ValidateAsync(request);

            result.IsValid.Should().BeFalse();
        }
        public async void DoesValidatorPreventFromUpdatingNotExistingRecipe()
        {
            var request = new UpdateRecipe
            {
                EntityId    = new Guid("1FED1A46-D5FF-4259-B838-08CA7C95F264"),
                Name        = "sample-name",
                Description = "sample-description",
                PictureUrl  = "https://example.com/sample-image.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 validator = new UpdateRecipeValidator(MockBuilder.BuildFakeRepository(), MockBuilder.BuildFakeCurrentUserService());

            var result = await validator.ValidateAsync(request);

            result.IsValid.Should().BeFalse();
        }
        public async void DoesValidatorPreventFromUpdatingRecipeWithoutSteps()
        {
            var request = new UpdateRecipe
            {
                EntityId    = new Guid("447EA0EF-F828-486A-91A9-0EDBC01D0B89"),
                Name        = "sample-name",
                Description = "sample-description",
                PictureUrl  = "https://example.com/sample-image.png",
                Calories    = 1234,
                MealTypes   = new[] { MealType.Snack }
            };
            var validator = new UpdateRecipeValidator(MockBuilder.BuildFakeRepository(), MockBuilder.BuildFakeCurrentUserService());

            var result = await validator.ValidateAsync(request);

            result.IsValid.Should().BeFalse();
        }
        public async void ShouldDeleteRecipeCorrectly()
        {
            // "62CB0EE2-0CF7-4C72-9C51-80A90E8E420E" - sample recipe id to delete
            var command    = new DeleteRecipe(new Guid("62CB0EE2-0CF7-4C72-9C51-80A90E8E420E"));
            var eventStore = new Mock <IEventStore <Recipe> >();
            var handler    = new DeleteRecipeHandler(eventStore.Object, MockBuilder.BuildFakeRecipeEventsMapper(), MockBuilder.BuildFakeCurrentUserService(), MockBuilder.BuildFakeDateTimeService());

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

            var expected = new RecipeRemoved
            {
                EntityId  = new Guid("62CB0EE2-0CF7-4C72-9C51-80A90E8E420E"),
                Version   = 0,
                Published = new DateTime(2010, 1, 1),
                AuthorId  = "9E09950B-47DE-4BAB-AA79-C29414312ECB"
            };

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