예제 #1
0
        public void Handler_ReturnsNoRemoteMemberships_WhenNotFound_ByUserId()
        {
            var userId            = FakeData.Id();
            var otherUserId1      = FakeData.Id(userId);
            var otherUserId2      = FakeData.Id(userId, otherUserId1);
            var remoteMemberships = new[]
            {
                new RemoteMembership {
                    UserId = otherUserId1,
                },
                new RemoteMembership {
                    UserId = otherUserId2,
                },
            };
            var data      = remoteMemberships.AsQueryable();
            var query     = new RemoteMembershipsByUser(userId);
            var dbSet     = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object);

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

            RemoteMembership[] result = handler.Handle(query).Result.ToArray();

            result.ShouldNotBeNull();
            result.Length.ShouldEqual(0);
            entities.Verify(x => x.Query <RemoteMembership>(), Times.Once);
        }
        public void Handler_ReturnsNoRemoteMemberships_WhenNotFound_ByUserName()
        {
            var userName       = Guid.NewGuid().ToString();
            var differentUser1 = new User {
                Name = Guid.NewGuid().ToString(),
            };
            var differentUser2 = new User {
                Name = Guid.NewGuid().ToString(),
            };
            var remoteMemberships = new[]
            {
                new RemoteMembership {
                    User = differentUser1,
                },
                new RemoteMembership {
                    User = differentUser2,
                },
            };
            var data      = remoteMemberships.AsQueryable();
            var query     = new RemoteMembershipsByUser(userName);
            var dbSet     = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object);

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

            RemoteMembership[] result = handler.Handle(query).Result.ToArray();

            result.ShouldNotBeNull();
            result.Length.ShouldEqual(0);
            entities.Verify(x => x.Query <RemoteMembership>(), Times.Once);
        }
예제 #3
0
        public void Query_StringCtor_SetsUserNameProperty()
        {
            var userName = FakeData.String();
            var query    = new RemoteMembershipsByUser(userName);

            query.UserId.ShouldBeNull();
            query.UserName.ShouldEqual(userName);
        }
예제 #4
0
        public void Query_IntCtor_SetsUserIdProperty()
        {
            var userId = FakeData.Id();
            var query  = new RemoteMembershipsByUser(userId);

            query.UserId.ShouldEqual(userId);
            query.UserName.ShouldBeNull();
        }
        public void Query_IntCtor_SetsUserIdProperty()
        {
            var userId = new Random().Next(1, int.MaxValue);
            var query  = new RemoteMembershipsByUser(userId);

            query.UserId.ShouldEqual(userId);
            query.UserName.ShouldBeNull();
        }
예제 #6
0
        public Task <IQueryable <RemoteMembership> > Handle(RemoteMembershipsByUser query)
        {
            var queryable = _entities.Query <RemoteMembership>().EagerLoad(query.EagerLoad);

            if (query.UserId.HasValue)
            {
                return(Task.FromResult(queryable.ByUserId(query.UserId.Value)));
            }
            return(Task.FromResult(queryable.ByUserName(query.UserName)));
        }
예제 #7
0
        public void Handler_ReturnsRemoteMemberships_WhenFound_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 remoteMemberships = new[]
            {
                new RemoteMembership {
                    User = otherUser1,
                },
                new RemoteMembership {
                    User = otherUser2,
                },
                new RemoteMembership {
                    User = user,
                },
                new RemoteMembership {
                    User = user,
                },
            };
            var data      = remoteMemberships.AsQueryable();
            var query     = new RemoteMembershipsByUser(userName);
            var dbSet     = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object);

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

            RemoteMembership[] result = handler.Handle(query).Result.ToArray();

            result.ShouldNotBeNull();
            result.Length.ShouldEqual(2);
            var expectedResults = data.Where(x => x.User.Name == userName);

            result.ShouldContain(expectedResults.First());
            result.ShouldContain(expectedResults.Skip(1).First());
            entities.Verify(x => x.Query <RemoteMembership>(), Times.Once);
        }
        public void Handler_ReturnsRemoteMemberships_WhenFound_ByUserId()
        {
            var userId            = new Random().Next(1, int.MaxValue - 3);
            var remoteMemberships = new[]
            {
                new RemoteMembership {
                    UserId = userId + 1,
                },
                new RemoteMembership {
                    UserId = userId - 1,
                },
                new RemoteMembership {
                    UserId = userId,
                },
                new RemoteMembership {
                    UserId = userId,
                },
            };
            var data      = remoteMemberships.AsQueryable();
            var query     = new RemoteMembershipsByUser(userId);
            var dbSet     = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object);

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

            RemoteMembership[] result = handler.Handle(query).Result.ToArray();

            result.ShouldNotBeNull();
            result.Length.ShouldEqual(2);
            var expectedResults = data.Where(x => x.UserId == userId);

            result.ShouldContain(expectedResults.First());
            result.ShouldContain(expectedResults.Skip(1).First());
            entities.Verify(x => x.Query <RemoteMembership>(), Times.Once);
        }