public override void Init()
        {
            base.Init();

            MockData();

            _createCommandValidator = new CreateTodoListCommandValidator(_dbMock.Object);

            _handler = new CreateTodoListCommandHandler(_dbMock.Object);
        }
        public void IsValid_ShouldBeTrue_WhenListTitleIsUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Bucket List"
            };

            var validator = new CreateTodoListCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Death List Five"
            };

            var validator = new CreateTodoListCommandValidator(_context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBeFalse();
        }
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Todo List"
            };

            var validator = new CreateTodoListCommandValidator(_context);

            var result = validator.TestValidate(command);

            result.ShouldHaveValidationErrorFor(e => e.Title).WithErrorCode("IsUniqueTitle");
        }
        public void IsValid_ShouldBeTrue_WhenListTitleIsUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Bucket List"
            };

            var validator = new CreateTodoListCommandValidator(_context);

            var result = validator.TestValidate(command);

            result.ShouldNotHaveValidationErrorFor(p => p.Title);
        }
Ejemplo n.º 6
0
        public void IsValid_ShouldBeTrue_WhenListTitleIsUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Bucket List",
            };

            var validator = new CreateTodoListCommandValidator(_context);

            var result = validator.Validate(command);

            // TODO: Need to check that the unique title rule is valid, even though other rules may have failed.
            result.IsValid.ShouldBe(true);
        }
        public void ShouldBeInvalid_WhenTitleIsNotUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Todo List"
            };

            var validator = new CreateTodoListCommandValidator(_context);

            var result = validator.TestValidate(command);

            result.ShouldHaveValidationErrorFor(p => p.Title)
                .WithErrorCode("UniqueTitle");
        }
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Todo List"
            };

            var validator = new CreateTodoListCommandValidator(_context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
            result.Errors[0].PropertyName.ShouldBe("Title");
            result.Errors[0].ErrorMessage.ShouldBe("The specified title already exists.");
        }
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            Context.TodoLists.Add(new TodoList { Title = "Shopping" });
            Context.SaveChanges();

            var command = new CreateTodoListCommand
            {
                Title = "Shopping"
            };

            var validator = new CreateTodoListCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            var command = new CreateTodoListCommand
            {
                Title = "Todo List"
            };

            var validator = new CreateTodoListCommandValidator(Context);

            var result = validator.Validate(command);

            // NOTE: An assumption is made that this has failed, because the title is not unique.
            result.IsValid.ShouldBe(false);

            //result.Errors
            //    .Any(e => e.PropertyName == "Title" && e.ErrorMessage == "The specified 'Title' already exists.")
            //    .ShouldBeTrue();
        }