コード例 #1
0
ファイル: EmailAddressesByTests.cs プロジェクト: sparg/tripod
        public void Query_IntCtor_SetsUserIdProperty()
        {
            var userId = FakeData.Id();
            var query  = new EmailAddressesBy(userId);

            query.UserId.ShouldEqual(userId);
        }
コード例 #2
0
        public void Handler_ReturnsNoEmailAddresses_WhenNotFound_ByUserId()
        {
            var userId = new Random().Next(3, int.MaxValue);
            var data   = new[]
            {
                new EmailAddress {
                    UserId = userId - 2, IsPrimary = true,
                },
                new EmailAddress {
                    UserId = userId - 2,
                },
                new EmailAddress {
                    UserId = userId - 2,
                },
                new EmailAddress {
                    UserId = userId - 1, IsPrimary = true,
                },
                new EmailAddress {
                    UserId = userId - 1,
                },
            }.AsQueryable();
            var query     = new EmailAddressesBy(userId);
            var dbSet     = new Mock <DbSet <EmailAddress> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <EmailAddress>(dbSet.Object, entities.Object);

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

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

            Assert.NotNull(result);
            result.Length.ShouldEqual(0);
            entities.Verify(x => x.Query <EmailAddress>(), Times.Once);
        }
コード例 #3
0
        public void Query_IntCtor_SetsUserIdProperty()
        {
            var userId = new Random().Next(int.MinValue, int.MaxValue);
            var query  = new EmailAddressesBy(userId);

            query.UserId.ShouldEqual(userId);
        }
コード例 #4
0
ファイル: EmailAddressesByTests.cs プロジェクト: sparg/tripod
        public void Handler_ReturnsEmailAddresses_WhenFound_ByUserId_AndIsVerifiedMatches(
            bool?queryIsVerified, bool entityIsVerified)
        {
            var userId       = FakeData.Id();
            var otherUserId1 = FakeData.Id(canNotBe: userId);
            var otherUserId2 = FakeData.Id(userId, otherUserId1);
            var data         = new[]
            {
                new EmailAddress {
                    UserId = otherUserId1, IsPrimary = true,
                },
                new EmailAddress {
                    UserId = otherUserId1,
                },
                new EmailAddress {
                    UserId = otherUserId1,
                },
                new EmailAddress {
                    UserId = otherUserId2, IsPrimary = true,
                },
                new EmailAddress {
                    UserId = otherUserId2,
                },
                new EmailAddress {
                    UserId = userId, IsVerified = entityIsVerified,
                },
                new EmailAddress {
                    UserId = userId, IsVerified = !entityIsVerified,
                },
            }.AsQueryable();
            var query = new EmailAddressesBy(userId)
            {
                IsVerified = queryIsVerified,
            };
            var dbSet     = new Mock <DbSet <EmailAddress> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <EmailAddress>(dbSet.Object, entities.Object);

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

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

            Assert.NotNull(result);
            result.Length.ShouldEqual(queryIsVerified.HasValue ? 1 : 2);
            entities.Verify(x => x.Query <EmailAddress>(), Times.Once);
            if (queryIsVerified.HasValue)
            {
                EmailAddress expectedEntity = data.Single(x => x.UserId == userId && x.IsVerified == entityIsVerified);
                result.Single().ShouldEqual(expectedEntity);
            }
        }
コード例 #5
0
        public Task <IQueryable <EmailAddress> > Handle(EmailAddressesBy query)
        {
            var queryable = _entities.Query <EmailAddress>()
                            .EagerLoad(query.EagerLoad)
                            .ByUserId(query.UserId);

            if (query.IsVerified.HasValue)
            {
                queryable = queryable.Where(x => x.IsVerified == query.IsVerified.Value);
            }

            return(Task.FromResult(queryable));
        }
コード例 #6
0
ファイル: EmailAddressesByTests.cs プロジェクト: sparg/tripod
        public void Handler_ReturnsNoEmailAddresses_WhenFound_ByUserId_ButIsVerifiedDoesNotMatch(bool isVerified)
        {
            var userId       = FakeData.Id();
            var otherUserId1 = FakeData.Id(userId);
            var otherUserId2 = FakeData.Id(userId, otherUserId1);
            var data         = new[]
            {
                new EmailAddress {
                    UserId = otherUserId1, IsPrimary = true,
                },
                new EmailAddress {
                    UserId = otherUserId1,
                },
                new EmailAddress {
                    UserId = otherUserId1,
                },
                new EmailAddress {
                    UserId = otherUserId2, IsPrimary = true,
                },
                new EmailAddress {
                    UserId = otherUserId2,
                },
                new EmailAddress {
                    UserId = userId, IsVerified = !isVerified,
                },
            }.AsQueryable();
            var query = new EmailAddressesBy(userId)
            {
                IsVerified = isVerified
            };
            var dbSet     = new Mock <DbSet <EmailAddress> >(MockBehavior.Strict).SetupDataAsync(data);
            var entities  = new Mock <IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet <EmailAddress>(dbSet.Object, entities.Object);

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

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

            Assert.NotNull(result);
            result.Length.ShouldEqual(0);
            entities.Verify(x => x.Query <EmailAddress>(), Times.Once);
        }