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