コード例 #1
0
            public void DoesNotUpdatePersonName_WhenFieldsHaveNotChanged()
            {
                const string principalIdentityName = "*****@*****.**";
                var          principal             = principalIdentityName.AsPrincipal();
                var          user = new User
                {
                    Name   = principalIdentityName,
                    Person = new Person
                    {
                        DisplayName = "Display Name",
                        FirstName   = "Display",
                        LastName    = "Name",
                    }
                };
                var command = new UpdateMyNameCommand
                {
                    Principal   = principal,
                    DisplayName = user.Person.DisplayName,
                    FirstName   = user.Person.FirstName,
                    LastName    = user.Person.LastName,
                };

                var entities = new Mock <ICommandEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(x => x.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.IsAny <Entity>()), Times.Never());
            }
コード例 #2
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);
            }
コード例 #3
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
            }
コード例 #4
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());
            }