示例#1
0
            public void IsValidWhen_UserName_IsWhiteSpace()
            {
                const string personDisplayName = "Adam West";
                var          command           = new CreatePersonCommand
                {
                    DisplayName = personDisplayName,
                    UserName    = "******",
                };
                var validator = new CreatePersonValidator(null);
                var results   = validator.Validate(command);
                var error     = results.Errors.SingleOrDefault(e => e.PropertyName == "UserName");

                error.ShouldBeNull();
            }
示例#2
0
            public void IsInvalidWhen_DisplayName_IsWhiteSpace()
            {
                var command = new CreatePersonCommand {
                    DisplayName = " "
                };
                var validator = new CreatePersonValidator(null);
                var results   = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "DisplayName");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(ValidatePerson.FailedBecauseDisplayNameWasEmpty);
                // ReSharper restore PossibleNullReferenceException
            }
示例#3
0
            public void IsValidWhen_UserName_DoesNotMatchExistingUser()
            {
                const string userName          = "******";
                const string personDisplayName = "Adam West";
                var          command           = new CreatePersonCommand
                {
                    DisplayName = personDisplayName,
                    UserName    = userName,
                };
                var queryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

                queryProcessor.Setup(m => m.Execute(It.Is <GetUserByNameQuery>(q => q.Name == command.UserName)))
                .Returns(null as User);
                var validator = new CreatePersonValidator(queryProcessor.Object);
                var results   = validator.Validate(command);
                var error     = results.Errors.SingleOrDefault(e => e.PropertyName == "UserName");

                error.ShouldBeNull();
            }
示例#4
0
            public void CreatesPerson_WithLastName()
            {
                var command = new CreatePersonCommand
                {
                    LastName = "West",
                };
                var    entities  = new Mock <ICommandEntities>(MockBehavior.Strict);
                Person outPerson = null;

                entities.Setup(m => m.Create(It.IsAny <Person>()))
                .Callback((Entity entity) => outPerson = (Person)entity);
                var handler = new CreatePersonHandler(entities.Object);

                handler.Handle(command);

                outPerson.ShouldNotBeNull();
                outPerson.LastName.ShouldEqual(command.LastName);
                entities.Verify(m => m.Create(It.Is <Person>(p =>
                                                             p.LastName == command.LastName)), Times.Once());
            }
示例#5
0
            public void CreatesPerson_AndRegisteredUser()
            {
                var command = new CreatePersonCommand
                {
                    UserName         = "******",
                    UserIsRegistered = true,
                };
                var    entities  = new Mock <ICommandEntities>(MockBehavior.Strict);
                Person outPerson = null;

                entities.Setup(m => m.Create(It.IsAny <Person>()))
                .Callback((Entity entity) => outPerson = (Person)entity);
                var handler = new CreatePersonHandler(entities.Object);

                handler.Handle(command);

                outPerson.ShouldNotBeNull();
                outPerson.ShouldEqual(command.CreatedPerson);
                outPerson.User.ShouldNotBeNull();
                outPerson.User.IsRegistered.ShouldBeTrue();
                entities.Verify(m => m.Create(It.Is <Person>(p =>
                                                             p.User.IsRegistered == command.UserIsRegistered)), Times.Once());
            }