public void Update_Category_With_No_Name_Throws_Exception()
 {
     using (var context = GetContextWithData())
     {
         var validator = new UpdateCategoryCommandValidator(context);
         validator.ShouldHaveValidationErrorFor(x => x.Name, string.Empty);
     }
 }
        public void IsValid_ShouldBeTrue_WhenListTitleIsUnique()
        {
            var command = new UpdateCategoryCommand
            {
                Id           = 1,
                CategoryName = "Shopping"
            };

            var validator = new UpdateCategoryCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            Context.Categories.Add(new Category {
                CategoryName = "Shopping"
            });
            Context.SaveChanges();

            var command = new UpdateCategoryCommand
            {
                Id           = 2,
                CategoryName = "Shopping"
            };

            var validator = new UpdateCategoryCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public void Update_Category_With_Title_That_Already_Exists_Throws_Exception()
        {
            using (var context = GetContextWithData())
            {
                var category = context.Categories.FirstOrDefault(b => b.Name == "Action");

                if (category != null)
                {
                    category.UpdateCategory("Technical");

                    var validator = new UpdateCategoryCommandValidator(context);
                    var result    = validator.TestValidate(new UpdateCategoryCommand
                    {
                        Id   = category.Id,
                        Name = category.Name
                    });
                    result.ShouldHaveValidationErrorFor(x => x);
                }
            }
        }
Exemplo n.º 5
0
 public TestUpdateCategoryCommand() : base()
 {
     this._validator = new UpdateCategoryCommandValidator(this.MockRepositoryFactory.Object);
 }