Exemple #1
0
            public void CreatesPerson_WithFirstName()
            {
                var command = new CreatePersonCommand
                {
                    FirstName = "Adam",
                };
                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.FirstName.ShouldEqual(command.FirstName);
                entities.Verify(m => m.Create(It.Is <Person>(p =>
                                                             p.FirstName == command.FirstName)), Times.Once());
            }
Exemple #2
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());
            }