コード例 #1
0
        public void UpdateRecipeShouldBeValid()
        {
            // Should be valid
            var test1 = new UpdateRecipe
            {
                Id          = "test",
                Title       = "test",
                Description = "test",
                Notes       = "test"
            };

            var test1Validator = new UpdateRecipeValidator();

            Assert.True(test1Validator.Validate(test1).IsValid);

            // Should require title
            var test2 = new UpdateRecipe
            {
                Id          = "test",
                Description = "test",
                Notes       = "test"
            };

            var test2Validator = new UpdateRecipeValidator();

            test2Validator.ShouldHaveValidationErrorFor(c => c.Title, test2);

            var longTitle = "test";

            while (longTitle.Length <= 100)
            {
                longTitle += $"{longTitle}{longTitle}{longTitle}{longTitle}";
            }

            // title should be 100 in length
            var test3 = new UpdateRecipe
            {
                Id          = "test",
                Description = longTitle,
                Notes       = "test"
            };

            var test3Validator = new UpdateRecipeValidator();

            test3Validator.ShouldHaveValidationErrorFor(c => c.Title, test2);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
        }