Пример #1
0
        public void Handler_ReturnsTrue_WhenFound_ByUserId()
        {
            var userId           = FakeData.Id();
            var otherUserId1     = FakeData.Id(userId);
            var otherUserId2     = FakeData.Id(userId, otherUserId1);
            var user             = new ProxiedUser(userId);
            var otherUser1       = new ProxiedUser(otherUserId1);
            var otherUser2       = new ProxiedUser(otherUserId2);
            var localMemberships = new[]
            {
                new LocalMembership {
                    User = otherUser1,
                },
                new LocalMembership {
                    User = user,
                },
                new LocalMembership {
                    User = otherUser2,
                },
            };
            var data      = localMemberships.AsQueryable();
            var query     = new UserHasLocalMembership(user.Id);
            var dbSet     = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <LocalMembership>(dbSet.Object, entities.Object);

            entities.Setup(x => x.Query <LocalMembership>()).Returns(entitySet);
            var handler = new HandleUserHasLocalMembershipQuery(entities.Object);

            bool result = handler.Handle(query).Result;

            result.ShouldBeTrue();
            entities.Verify(x => x.Query <LocalMembership>(), Times.Once);
        }
        public void Handler_ReturnsFalse_WhenNotFound_ByPrincipal()
        {
            var userId           = new Random().Next(1, int.MaxValue);
            var user             = new ProxiedUser(userId);
            var differentUser1   = new ProxiedUser(userId + 1);
            var differentUser2   = new ProxiedUser(userId - 1);
            var localMemberships = new[]
            {
                new LocalMembership {
                    User = differentUser1,
                },
                new LocalMembership {
                    User = differentUser2,
                },
            };
            var identity = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(CultureInfo.InvariantCulture)),
            });
            var principal = new GenericPrincipal(identity, null);
            var data      = localMemberships.AsQueryable();
            var query     = new UserHasLocalMembership(principal);
            var dbSet     = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <LocalMembership>(dbSet.Object, entities.Object);

            entities.Setup(x => x.Query <LocalMembership>()).Returns(entitySet);
            var handler = new HandleUserHasLocalMembershipQuery(entities.Object);

            bool result = handler.Handle(query).Result;

            result.ShouldBeFalse();
            entities.Verify(x => x.Query <LocalMembership>(), Times.Once);
        }
Пример #3
0
        public void Handler_ReturnsFalse_WhenNotFound_ByUserName()
        {
            var userName = FakeData.String();
            var user     = new User {
                Name = userName,
            };
            var otherUser1 = new User {
                Name = FakeData.String(),
            };
            var otherUser2 = new User {
                Name = FakeData.String(),
            };
            var localMemberships = new[]
            {
                new LocalMembership {
                    User = otherUser1,
                },
                new LocalMembership {
                    User = otherUser2,
                },
            };
            var data      = localMemberships.AsQueryable();
            var query     = new UserHasLocalMembership(user.Name);
            var dbSet     = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <LocalMembership>(dbSet.Object, entities.Object);

            entities.Setup(x => x.Query <LocalMembership>()).Returns(entitySet);
            var handler = new HandleUserHasLocalMembershipQuery(entities.Object);

            bool result = handler.Handle(query).Result;

            result.ShouldBeFalse();
            entities.Verify(x => x.Query <LocalMembership>(), Times.Once);
        }
        public void Handler_ReturnsFalse_WhenNotFound_ByUserId()
        {
            var userId           = new Random().Next(3, int.MaxValue - 3);
            var user             = new ProxiedUser(userId);
            var differentUser1   = new ProxiedUser(userId + 1);
            var differentUser2   = new ProxiedUser(userId - 1);
            var localMemberships = new[]
            {
                new LocalMembership {
                    User = differentUser1,
                },
                new LocalMembership {
                    User = differentUser2,
                },
            };
            var data      = localMemberships.AsQueryable();
            var query     = new UserHasLocalMembership(user.Id);
            var dbSet     = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <LocalMembership>(dbSet.Object, entities.Object);

            entities.Setup(x => x.Query <LocalMembership>()).Returns(entitySet);
            var handler = new HandleUserHasLocalMembershipQuery(entities.Object);

            bool result = handler.Handle(query).Result;

            result.ShouldBeFalse();
            entities.Verify(x => x.Query <LocalMembership>(), Times.Once);
        }
Пример #5
0
        public void Handler_ReturnsTrue_WhenFound_ByPrincipal()
        {
            var userId       = FakeData.Id();
            var otherUserId1 = FakeData.Id(userId);
            var otherUserId2 = FakeData.Id(userId, otherUserId1);
            var user         = new ProxiedUser(userId)
            {
                Name = FakeData.String(),
            };
            var otherUser1 = new ProxiedUser(otherUserId1)
            {
                Name = FakeData.String(),
            };
            var otherUser2 = new ProxiedUser(otherUserId2)
            {
                Name = FakeData.String(),
            };
            var localMemberships = new[]
            {
                new LocalMembership {
                    User = otherUser1,
                },
                new LocalMembership {
                    User = user,
                },
                new LocalMembership {
                    User = otherUser2,
                },
            };
            var identity = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(CultureInfo.InvariantCulture)),
            });
            var principal = new GenericPrincipal(identity, null);
            var data      = localMemberships.AsQueryable();
            var query     = new UserHasLocalMembership(principal);
            var dbSet     = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <LocalMembership>(dbSet.Object, entities.Object);

            entities.Setup(x => x.Query <LocalMembership>()).Returns(entitySet);
            var handler = new HandleUserHasLocalMembershipQuery(entities.Object);

            bool result = handler.Handle(query).Result;

            result.ShouldBeTrue();
            entities.Verify(x => x.Query <LocalMembership>(), Times.Once);
        }