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