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 EmailAddressViewsBy(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 HandleEmailAddressViewsByQuery(entities.Object);

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

            Assert.NotNull(result);
            result.Length.ShouldEqual(0);
            entities.Verify(x => x.Query<EmailAddress>(), Times.Once);
        }
        public void Handler_ReturnsRemoteMembershipViews_WhenFound_ByUserId()
        {
            var userId = FakeData.Id();
            var otherUserId1 = FakeData.Id(userId);
            var otherUserId2 = FakeData.Id(userId, otherUserId1);
            var remoteMemberships = new[]
            {
                new ProxiedRemoteMembership(FakeData.String(), FakeData.String())
                    { UserId = otherUserId1, },
                new ProxiedRemoteMembership(FakeData.String(), FakeData.String())
                    { UserId = otherUserId2, },
                new ProxiedRemoteMembership(FakeData.String(), FakeData.String())
                    { UserId = userId, },
            };
            var data = remoteMemberships.AsQueryable();
            var query = new RemoteMembershipViewsBy(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 HandleRemoteMembershipViewsByQuery(entities.Object);

            RemoteMembershipView[] results = handler.Handle(query).Result.ToArray();

            results.ShouldNotBeNull();
            results.Length.ShouldEqual(1);
            RemoteMembershipView result = results.Single();
            var expectedEntity = data.Single(x => x.UserId == userId);
            result.UserId.ShouldEqual(expectedEntity.UserId);
            result.Provider.ShouldEqual(expectedEntity.LoginProvider);
            result.Key.ShouldEqual(expectedEntity.ProviderKey);
            entities.Verify(x => x.Query<RemoteMembership>(), Times.Once);
        }
        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_ReturnsRemoteMemberships_WhenFound_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, },
                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);
        }
        public void Handler_ReturnsNonNullLocalMembership_WhenFound_ByUserId()
        {
            var userId = FakeData.Id();
            var user = new ProxiedUser(userId);
            var data = new[]
            {
                new LocalMembership
                {
                    User = user,
                    PasswordHash = "password hash",
                },
            }.AsQueryable();
            var query = new LocalMembershipByUser(userId);
            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 HandleLocalMembershipByUserQuery(entities.Object);

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

            result.ShouldNotBeNull();
            result.User.ShouldEqual(user);
            result.PasswordHash.ShouldEqual("password hash");
            entities.Verify(x => x.Query<LocalMembership>(), Times.Once);
        }
Beispiel #6
0
        public void Handler_ReturnsNonNullEmailAddress_WhenFound_ById_AndIsVerifiedMatches(
            bool? queryIsVerified, bool entityIsVerified)
        {
            var emailAddressId = FakeData.Id();
            var emailAddress = new ProxiedEmailAddress(emailAddressId)
            {
                IsVerified = entityIsVerified,
            };
            var data = new[] { emailAddress }.AsQueryable();
            var query = new EmailAddressBy(emailAddressId)
            {
                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 HandleEmailAddressByQuery(entities.Object);

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

            result.ShouldNotBeNull();
            result.ShouldEqual(data.Single());
            entities.Verify(x => x.Query<EmailAddress>(), Times.Once);
        }
        public void Handler_ReturnsNullLocalMembership_WhenNotFound_ByVerifiedEmail()
        {
            var emailAddress = FakeData.Email();
            var user = new User();
            user.EmailAddresses.Add(new EmailAddress
            {
                IsVerified = false,
                Value = emailAddress,
            });
            var data = new[]
            {
                new LocalMembership { User = user, },
            }.AsQueryable();
            var query = new LocalMembershipByVerifiedEmail(emailAddress);
            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 HandleLocalMembershipByVerifiedEmailQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<LocalMembership>(), Times.Once);
        }
        public void Test3()
        {
            var records = new[]
            {
                new Product("A", 1),
                new Product("A", 2)
            };

            var queryable = records.AsQueryable() as IQueryable;
            var results = queryable
                .GroupBy("new ( Name )", "it")
                .Select("new ( Key.Name AS ProductName, SUM(Quantity) as Total )");
        }
        public void GetUserByEmail_ExistingEmail_User()
        {
            var data = new[]
            {
                new UserDto { Email = "test" },
                new UserDto { Email = "*****@*****.**" }
            };

            IDbSet<UserDto> users = new FakeDbSet<UserDto>(data);
            A.CallTo(() => _context.Users).Returns(users);

            IUserDto user = _userRepository.GetUserByEmail("*****@*****.**").Result;

            Assert.Equal("*****@*****.**", user.Email);
        }
Beispiel #10
0
        public void Handler_ReturnsNullEmailAddress_WhenNotFound_ById()
        {
            var emailAddressId = FakeData.Id();
            var data = new[] { new ProxiedEmailAddress(FakeData.Id(canNotBe: emailAddressId)) }.AsQueryable();
            var query = new EmailAddressBy(emailAddressId);
            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 HandleEmailAddressByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<EmailAddress>(), Times.Once);
        }
Beispiel #11
0
        public void Handler_ReturnsNullUser_WhenNotFound_ById()
        {
            var userId = FakeData.Id();
            var otherUserId = FakeData.Id(userId);
            var data = new[] { new ProxiedUser(otherUserId) }.AsQueryable();
            var query = new UserBy(userId);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            entities.Setup(x => x.Query<User>()).Returns(entitySet);
            var handler = new HandleUserByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
Beispiel #12
0
        public void Handler_ReturnsNonNullUser_WhenFound_ByName()
        {
            var userName = FakeData.String();
            var data = new[] { new User { Name = userName } }.AsQueryable();
            var query = new UserBy(userName);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            entities.Setup(x => x.Query<User>()).Returns(entitySet);
            var handler = new HandleUserByQuery(entities.Object);

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

            result.ShouldNotBeNull();
            result.ShouldEqual(data.Single());
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
        public void Handler_ReturnsNullEmailVerification_WhenNotFound_ByTicket()
        {
            var ticket = FakeData.String();
            var emailVerification = new EmailVerification
            {
                Ticket = FakeData.String(),
            };
            var data = new[] { emailVerification }.AsQueryable();
            var query = new EmailVerificationBy(ticket);
            var dbSet = new Mock<DbSet<EmailVerification>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<EmailVerification>(dbSet.Object, entities.Object);
            entities.Setup(x => x.Query<EmailVerification>()).Returns(entitySet);
            var handler = new HandleEmailVerificationByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<EmailVerification>(), Times.Once);
        }
Beispiel #14
0
        public void Handler_ReturnsNullUserView_WhenNotFound_ById()
        {
            var userId = FakeData.Id();
            var otherUserId = FakeData.Id(canNotBe: userId);
            var user = new ProxiedUser(otherUserId) { Name = FakeData.String(), };
            var primaryEmail = new EmailAddress
            {
                Value = FakeData.Email(),
                HashedValue = FakeData.String(),
                IsPrimary = true,
                IsVerified = true,
            };
            var secondaryEmail1 = new EmailAddress
            {
                Value = FakeData.Email(),
                HashedValue = FakeData.String(),
                IsVerified = true,
            };
            var secondaryEmail2 = new EmailAddress
            {
                Value = FakeData.Email(),
                HashedValue = FakeData.String(),
            };
            user.EmailAddresses.Add(secondaryEmail1);
            user.EmailAddresses.Add(secondaryEmail2);
            user.EmailAddresses.Add(primaryEmail);
            var data = new[] { user }.AsQueryable();
            var query = new UserViewBy(userId);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            IQueryable<User> toBeReturned = entitySet;
            entities.Setup(x => x.Query<User>()).Returns(toBeReturned);
            var handler = new HandleUserViewByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
Beispiel #15
0
        public void Handler_ReturnsNullUser_WhenNotFound_ByUserLoginInfo()
        {
            var loginProvider = FakeData.String();
            var providerKey = FakeData.String();
            var remoteMembershipId = new RemoteMembershipId
            {
                LoginProvider = loginProvider,
                ProviderKey = FakeData.String(),
            };
            var remoteMembership = new ProxiedRemoteMembership(remoteMembershipId);
            var user = new User();
            user.RemoteMemberships.Add(remoteMembership);
            var data = new[] { user }.AsQueryable();
            var query = new UserBy(new UserLoginInfo(loginProvider, providerKey));
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            entities.Setup(x => x.Query<User>()).Returns(entitySet);
            var handler = new HandleUserByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
Beispiel #16
0
        public void Handler_ReturnsNullUser_WhenAuthenticatedButNotFound_ByPrincipal()
        {
            var userId = FakeData.Id();
            var otherUserId = FakeData.Id(userId);
            var claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, userId.ToString(CultureInfo.InvariantCulture)),
            };
            var identity = new ClaimsIdentity(claims, "authenticationType");
            var principal = new GenericPrincipal(identity, null);
            var data = new[] { new ProxiedUser(otherUserId) }.AsQueryable();
            var query = new UserBy(principal);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            entities.Setup(x => x.Query<User>()).Returns(entitySet);
            var handler = new HandleUserByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
Beispiel #17
0
        public void Handler_ReturnsNonNullUserView_WhenFound_ByPrincipal()
        {
            var userId = FakeData.Id();
            var user = new ProxiedUser(userId) { Name = FakeData.String(), };
            var primaryEmail = new EmailAddress
            {
                Value = FakeData.Email(),
                HashedValue = FakeData.String(),
                IsPrimary = true,
                IsVerified = true,
            };
            var secondaryEmail1 = new EmailAddress
            {
                Value = FakeData.Email(),
                HashedValue = FakeData.String(),
                IsVerified = true,
            };
            var secondaryEmail2 = new EmailAddress
            {
                Value = FakeData.Email(),
                HashedValue = FakeData.String(),
            };
            user.EmailAddresses.Add(secondaryEmail1);
            user.EmailAddresses.Add(secondaryEmail2);
            user.EmailAddresses.Add(primaryEmail);
            var data = new[] { user }.AsQueryable();
            var claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, userId.ToString(CultureInfo.InvariantCulture)), 
            };
            var identity = new ClaimsIdentity(claims, "authentication type");
            var principal = new GenericPrincipal(identity, null);
            var query = new UserViewBy(principal);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            IQueryable<User> toBeReturned = entitySet;
            entities.Setup(x => x.Query<User>()).Returns(toBeReturned);
            var handler = new HandleUserViewByQuery(entities.Object);

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

            result.ShouldNotBeNull();
            result.UserId.ShouldEqual(user.Id);
            result.UserName.ShouldEqual(user.Name);
            result.PrimaryEmailAddress.ShouldEqual(primaryEmail.Value);
            result.PrimaryEmailHash.ShouldEqual(primaryEmail.HashedValue);
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
Beispiel #18
0
        public void Handler_ReturnsNullUserView_WhenPrincipalIdentity_HasNoNameIdentifierClaim()
        {
            var userId = FakeData.Id();
            var user = new ProxiedUser(userId) { Name = FakeData.String(), };
            var data = new[] { user }.AsQueryable();
            var claims = new[]
            {
                new Claim(ClaimTypes.Name, userId.ToString(CultureInfo.InvariantCulture)), 
            };
            var identity = new ClaimsIdentity(claims, "authentication type");
            var principal = new GenericPrincipal(identity, null);
            var query = new UserViewBy(principal);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            IQueryable<User> toBeReturned = entitySet;
            entities.Setup(x => x.Query<User>()).Returns(toBeReturned);
            var handler = new HandleUserViewByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
Beispiel #19
0
        public void Handler_ReturnsNullUserView_WhenPrincipalIsNull()
        {
            var userId = FakeData.Id();
            var user = new ProxiedUser(userId) { Name = FakeData.String(), };
            var data = new[] { user }.AsQueryable();
            var query = new UserViewBy(null as IPrincipal);
            var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<User>(dbSet.Object, entities.Object);
            IQueryable<User> toBeReturned = entitySet;
            entities.Setup(x => x.Query<User>()).Returns(toBeReturned);
            var handler = new HandleUserViewByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<User>(), Times.Once);
        }
        public void Handler_ReturnsNullLocalMembership_WhenNotFound_ByUserName()
        {
            var userName = FakeData.String();
            var user = new User { Name = FakeData.String(), };
            var data = new[]
            {
                new LocalMembership { User = user, },
            }.AsQueryable();
            var query = new LocalMembershipByUser(userName);
            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 HandleLocalMembershipByUserQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<LocalMembership>(), Times.Once);
        }
        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);
        }
Beispiel #22
0
        public void Handler_ReturnsNullEmailAddress_WhenFound_ByValue_ButIsVerifiedDoesNotMatch(bool isVerified)
        {
            var emailAddressValue = FakeData.Email();
            var emailAddress = new EmailAddress
            {
                Value = emailAddressValue,
                IsVerified = !isVerified,
            };
            var data = new[] { emailAddress }.AsQueryable();
            var query = new EmailAddressBy(emailAddressValue)
            {
                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 HandleEmailAddressByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<EmailAddress>(), Times.Once);
        }
Beispiel #23
0
        public void Handler_ReturnsNullEmailAddress_WhenClaimType_IsNotEmail_ByClaim()
        {
            var emailAddressValue = FakeData.Email();
            var claim = new Claim(ClaimTypes.NameIdentifier, emailAddressValue);
            var emailAddress = new EmailAddress
            {
                Value = emailAddressValue,
            };
            var data = new[] { emailAddress }.AsQueryable();
            var query = new EmailAddressBy(claim);
            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 HandleEmailAddressByQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<EmailAddress>(), Times.Once);
        }
Beispiel #24
0
        public void Handler_ReturnsNonNullEmailAddress_WhenFound_ByClaim_AndIsVerified_IsEqual(
            bool? isQueryVerified, bool isEntityVerified)
        {
            var emailAddressValue = FakeData.Email();
            var claim = new Claim(ClaimTypes.Email, emailAddressValue);
            var emailAddress = new EmailAddress
            {
                Value = emailAddressValue,
                IsVerified = isEntityVerified,
            };
            var data = new[] { emailAddress }.AsQueryable();
            var query = new EmailAddressBy(claim)
            {
                IsVerified = isQueryVerified,
            };
            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 HandleEmailAddressByQuery(entities.Object);

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

            result.ShouldNotBeNull();
            result.ShouldEqual(data.Single());
            entities.Verify(x => x.Query<EmailAddress>(), Times.Once);
        }
        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 WhenGenerateListOptionsViewModel_ThenCategoryFilterListPopulated()
        {
            EducationSecurityPrincipal user = new EducationSecurityPrincipal(new UserRepository(EducationContext).Items.Where(s => s.UserKey == "Bob").Include("UserRoles.Role").Single());
            var expected = new[] { "Basic Needs", "Consumer Services", "Criminal Justice and Legal Services", "Education", "Environmental Quality", "Health Care", "Income Support and Employment", "Individual and Family Life", "Mental Health Care and Counseling", "Organizational/Community Services", "Support Groups", "Target Populations", "Test Category," };

            ServiceTypeListOptionsModel actual = Target.GenerateListOptionsViewModel(user);

            CollectionAssert.AreEquivalent(expected, actual.CategoryFilterList.ToList());
        }
        public void Handler_ReturnsNoRemoteMemberships_WhenNotFound_ByUserName()
        {
            var userName = FakeData.String();
            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, },
            };
            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);
        }
        public void Handler_ReturnsNullLocalMembership_WhenNotFound_ByUserLoginInfo()
        {
            var loginProvider = FakeData.String();
            var providerKey = FakeData.String();
            var userLoginInfo = new UserLoginInfo(loginProvider, providerKey);
            var user = new User();
            user.RemoteMemberships.Add(new ProxiedRemoteMembership(
                FakeData.String(), FakeData.String()));
            var data = new[]
            {
                new LocalMembership { User = user, },
            }.AsQueryable();
            var query = new LocalMembershipByUser(userLoginInfo);
            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 HandleLocalMembershipByUserQuery(entities.Object);

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

            result.ShouldBeNull();
            entities.Verify(x => x.Query<LocalMembership>(), Times.Once);
        }
        public void Handler_ReturnsEmailAddresses_WhenFound_ByUserId_AndIsVerifiedMatches(
            bool? queryIsVerified, bool entityIsVerified)
        {
            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 ProxiedEmailAddress(664)
                {
                    UserId = userId,
                    Value = FakeData.Email(),
                    HashedValue = "hashed email value",
                    IsVerified = entityIsVerified,
                    IsPrimary = entityIsVerified,
                },
                new EmailAddress { UserId = userId, IsVerified = !entityIsVerified, },
            }.AsQueryable();
            var query = new EmailAddressViewsBy(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 HandleEmailAddressViewsByQuery(entities.Object);

            EmailAddressView[] 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);
                EmailAddressView actualView = result.Single();
                actualView.EmailAddressId.ShouldEqual(expectedEntity.Id);
                actualView.UserId.ShouldEqual(expectedEntity.UserId);
                actualView.Value.ShouldEqual(expectedEntity.Value);
                actualView.HashedValue.ShouldEqual(expectedEntity.HashedValue);
                actualView.IsPrimary.ShouldEqual(expectedEntity.IsPrimary);
                actualView.IsVerified.ShouldEqual(expectedEntity.IsVerified);
            }
        }
        public JsonResult GetAdUnits(int? id)
        {
            var adUnits = new { items = ViewModel.GetAdUnits(id) };

            return Json(adUnits, JsonRequestBehavior.AllowGet);
        }