Пример #1
0
        public void Handler_ReturnsNullUserView_WhenPrincipalIsNull()
        {
            var userId = new Random().Next(1, int.MaxValue - 3);
            var user   = new ProxiedUser(userId)
            {
                Name = Guid.NewGuid().ToString(),
            };
            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);
        }
Пример #2
0
        public void Handler_ReturnsNullUserView_WhenPrincipalIdentity_IsNotClaimsIdentity()
        {
            var userId = FakeData.Id();
            var user   = new ProxiedUser(userId)
            {
                Name = FakeData.String(),
            };
            var data = new[] { user }.AsQueryable();
            var identity  = new GenericIdentity(user.Name, "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);
        }