Inheritance: RevisableEntity
示例#1
0
 public void HasGetSet()
 {
     var value = new List<RoleGrant> { new RoleGrant() };
     var entity = new User { Grants = value };
     entity.ShouldNotBeNull();
     entity.Grants.ShouldEqual(value);
 }
            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());
            }
示例#3
0
 public void HasGetSet()
 {
     var value = new User();
     var entity = new RoleGrant { User = value };
     entity.ShouldNotBeNull();
     entity.User.ShouldEqual(value);
 }
示例#4
0
        protected internal Preference(User user)
        {
            if (user == null) throw new ArgumentNullException("user");

            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            User = user;
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
            UserId = user.RevisionId;
            Owner = user.RevisionId.ToString(CultureInfo.InvariantCulture);
        }
示例#5
0
        public static bool IdentityNameMatchesUser(IPrincipal principal, IQueryEntities entities, IEnumerable<Expression<Func<User, object>>> eagerLoad, out User entity)
        {
            if (entities == null)
            {
                entity = null;
                return false;
            }

            entity = entities.Query<User>()
                .EagerLoad(entities, eagerLoad)
                .ByName(principal.Identity.Name);

            // return true (valid) if there is an entity
            return entity != null;
        }
示例#6
0
        public static bool NameMatchesEntity(string name, IProcessQueries queryProcessor,
            IEnumerable<Expression<Func<User, object>>> eagerLoad, out User entity)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                entity = null;
                return false;
            }

            entity = queryProcessor.Execute(
                new GetUserByNameQuery
                {
                    Name = name,
                    EagerLoad = eagerLoad,
                }
            );

            // return true (valid) if there is an entity
            return entity != null;
        }
            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());
            }
示例#8
0
        public static bool NameMatchesNoEntity(string name, IProcessQueries queryProcessor,
            IEnumerable<Expression<Func<User, object>>> eagerLoad, out User entity)
        {
            return !NameMatchesEntity(name, queryProcessor, eagerLoad, out entity);
            //if (string.IsNullOrWhiteSpace(name))
            //{
            //    entity = null;
            //    return true;
            //}

            //entity = queryProcessor.Execute(
            //    new GetUserByNameQuery
            //    {
            //        Name = name,
            //        EagerLoad = eagerLoad,
            //    }
            //);

            //// return true (valid) if there is no entity
            //return entity == null;
        }
            public void IsValidWhen_PrincipalIdentityName_MatchesUser()
            {
                const string principalIdentityName = "*****@*****.**";
                var principal = principalIdentityName.AsPrincipal();
                var command = new UpdateMyNameCommand
                {
                    Principal = principal,
                };
                var user = new User
                {
                    Name = principal.Identity.Name,
                };
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<User>()).Returns(new[] { user }.AsQueryable);
                var validator = new UpdateMyNameValidator(entities.Object);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Principal");
                error.ShouldBeNull();
            }
            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);
            }
示例#11
0
 public static bool NameMatchesNoEntity(string name, IProcessQueries queryProcessor, out User entity)
 {
     return !NameMatchesEntity(name, queryProcessor, null, out entity);
 }
示例#12
0
 public static bool EduPersonTargetedIdIsEmpty(User entity)
 {
     return entity != null && string.IsNullOrWhiteSpace(entity.EduPersonTargetedId);
 }
示例#13
0
 public static bool IdentityNameMatchesUser(IPrincipal principal, IQueryEntities entities, out User entity)
 {
     return IdentityNameMatchesUser(principal, entities, null, out entity);
 }
            public void IsValidWhen_IdentityName_IsNotEmpty_AndMatchesUser()
            {
                const string principalIdentityName = "*****@*****.**";
                var principal = principalIdentityName.AsPrincipal();
                var command = new UpdateMyEmailValueCommand { Principal = principal };
                var user = new User { Name = principal.Identity.Name };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<User>()).Returns(new[] { user }.AsQueryable);
                entities.Setup(m => m.Query<EmailAddress>()).Returns(new EmailAddress[] { }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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