Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }