Exemplo n.º 1
0
            public void UpdatesPersonName_WhenFieldsHaveChanged()
            {
                const string principalIdentityName = "*****@*****.**";
                var principal = principalIdentityName.AsPrincipal();
                var user = new User
                {
                    Name = principalIdentityName,
                    Person = new Person(),
                };
                var command = new UpdateMyNameCommand
                {
                    Principal = principal,
                    DisplayName = "Display Name",
                    FirstName = "Display",
                    LastName = "Name",
                };
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<User>()).Returns(new[] { user }.AsQueryable);
                entities.Setup(m => m.Update(It.Is(PersonBasedOn(command))));
                var handler = new UpdateMyNameHandler(entities.Object);

                handler.Handle(command);

                entities.Verify(m => m.Update(It.Is(PersonBasedOn(command))), Times.Once());
            }
Exemplo n.º 2
0
            public void ThrowsArgumentNullException_WhenCommandArgIsNull()
            {
                ArgumentNullException exception = null;
                var handler = new UpdateMyNameHandler(null);
                try
                {
                    handler.Handle(null);
                }
                catch (ArgumentNullException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.ParamName.ShouldEqual("command");
                // ReSharper restore PossibleNullReferenceException
            }
Exemplo n.º 3
0
            public void ExecutesQuery_ToGetUserPerson_FromPrincipalIdentityName()
            {
                const string principalIdentityName = "*****@*****.**";
                var principal = principalIdentityName.AsPrincipal();
                var command = new UpdateMyNameCommand
                {
                    Principal = principal,
                };
                var user = new User
                {
                    Name = principalIdentityName,
                    Person = new Person(),
                };
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<User>()).Returns(new[] { user }.AsQueryable);
                var handler = new UpdateMyNameHandler(entities.Object);

                handler.Handle(command);

                entities.Verify(m => m.Get<User>(), Times.Once());
            }
Exemplo n.º 4
0
            public void IncrementsChangeCount_WhenSuffix_IsDifferent()
            {
                Person outPerson = null;
                const string principalIdentityName = "*****@*****.**";
                var principal = principalIdentityName.AsPrincipal();
                var user = new User
                {
                    Name = principalIdentityName,
                    Person = new Person
                    {
                        Suffix = "Jr",
                    },
                };
                var command = new UpdateMyNameCommand
                {
                    Principal = principal,
                    Suffix = "Jr.",
                };
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<User>()).Returns(new[] { user }.AsQueryable);
                entities.Setup(m => m.Update(It.Is(PersonBasedOn(command))))
                    .Callback((Entity entity) => outPerson = (Person)entity);
                var handler = new UpdateMyNameHandler(entities.Object);

                handler.Handle(command);

                command.ChangeCount.ShouldEqual(1);
                outPerson.Suffix.ShouldEqual(command.Suffix);
            }