public void Validate_Should_Throw_Exception_When_ReadRepository_Is_Null()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand();

                this.read = null;

                UserCommandHandlerHelper.Validate(command, this.write, this.read);
            }
            public void Validate_Should_Not_Add_User_With_Invalid_Id_Length()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand("a".PadLeft(51, 'a'));

                string expectedInvalid = string.Format(MessagesModel.MaxLength, "50");

                UserCommandResult result = UserCommandHandlerHelper.Validate(command, this.write, this.read);

                Assert.IsFalse(result.Valid);
                Assert.AreEqual(expectedInvalid, result.InvalidId);
            }
            public void Validate_Should_Not_Add_User_With_Empty_Id()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand("");

                string expectedInvalid = MessagesModel.Required;

                UserCommandResult result = UserCommandHandlerHelper.Validate(command, this.write, this.read);

                Assert.IsFalse(result.Valid);
                Assert.AreEqual(expectedInvalid, result.InvalidId);
            }
            public void Validate_Should_Not_Add_User_With_Invalid_Email_Format()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand(null, null, null, "testatabc.comx");

                string expectedInvalid = MessagesModel.InvalidEmail;

                UserCommandResult result = UserCommandHandlerHelper.Validate(command, this.write, this.read);

                Assert.IsFalse(result.Valid);
                Assert.AreEqual(expectedInvalid, result.InvalidEmail);
            }
            public void Validate_Should_Not_Add_User_With_Invalid_Email_Length()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand(null, null, null, "a".PadLeft(256, 'a') + "@abc.comx");

                string expectedInvalid = string.Format(MessagesModel.MaxLength, "255");

                UserCommandResult result = UserCommandHandlerHelper.Validate(command, this.write, this.read);

                Assert.IsFalse(result.Valid);
                Assert.AreEqual(expectedInvalid, result.InvalidEmail);
            }
            public void Validate_Should_Not_Add_User_With_Duplicate_Id()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand();

                User user = new User(command.Id, command.DateAdded, command.Email, command.FirstName, command.LastName, command.Roles, command.Groups, command.IsEnabled);

                read.GetById("id1").Returns(user);

                string expectedInvalid = string.Format("A user already exists with the username {0}", command.Id);

                UserCommandResult result = UserCommandHandlerHelper.Validate(command, this.write, this.read);

                Assert.IsFalse(result.Valid);
                Assert.AreEqual(expectedInvalid, result.InvalidId);
            }
            public void Validate_Should_Not_Add_User_With_Duplicate_Email()
            {
                UserCommand command = UserCommandHandlerTestHelper.GetCommand();

                IList <User> users = Substitute.For <IList <User> >();

                users.Count.Returns(1);

                read.Where(x => x.Email == "*****@*****.**").ReturnsForAnyArgs(users);

                string expectedInvalid = string.Format("A user already exists with the email {0}", command.Email);

                UserCommandResult result = UserCommandHandlerHelper.Validate(command, this.write, this.read);

                Assert.IsFalse(result.Valid);
                Assert.AreEqual(expectedInvalid, result.InvalidEmail);
            }
            public void Validate_Should_Throw_Exception_When_Command_Is_Null()
            {
                UserCommand command = null;

                UserCommandHandlerHelper.Validate(command, this.write, this.read);
            }