Exemplo n.º 1
0
        public void ByUserLoginInfo_Enumerable_CanAllowNull()
        {
            var data = new[]
            {
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
            };

            foreach (var localMembership in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    string loginProvider    = FakeData.String();
                    string providerKey      = FakeData.String();
                    var    remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
                    localMembership.User.RemoteMemberships.Add(remoteMembership);
                }
            }
            var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());

            data.AsEnumerable().ByUserLoginInfo(userLoginInfo).ShouldBeNull();
        }
Exemplo n.º 2
0
        public void Handler_ReturnsNullUser_WhenNotFound_ByUserLoginInfo()
        {
            const string loginProvider      = "loginProvider";
            var          providerKey        = Guid.NewGuid().ToString();
            var          remoteMembershipId = new RemoteMembershipId
            {
                LoginProvider = loginProvider,
                ProviderKey   = Guid.NewGuid().ToString(),
            };
            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);
        }
Exemplo n.º 3
0
        public void ByUserLoginInfoAsync_Enumerable_CanAllowNull()
        {
            var data = new[]
            {
                new User {
                    Name = FakeData.String(),
                },
                new User {
                    Name = FakeData.String(),
                },
                new User {
                    Name = FakeData.String(),
                },
            };

            foreach (var user in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    string loginProvider    = FakeData.String();
                    string providerKey      = FakeData.String();
                    var    remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
                    user.RemoteMemberships.Add(remoteMembership);
                }
            }
            var dbSet         = new Mock <DbSet <User> >(MockBehavior.Strict).SetupDataAsync(data.AsQueryable());
            var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());

            dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo).Result.ShouldBeNull();
        }
Exemplo n.º 4
0
 public void ComponentProperties_DelegateTo_CompositeId()
 {
     var entity = new RemoteMembership
     {
         Id =
         {
             LoginProvider = "provider1",
             ProviderKey = "key1"
         }
     };
     entity.LoginProvider.ShouldEqual(entity.Id.LoginProvider);
     entity.ProviderKey.ShouldEqual(entity.Id.ProviderKey);
     entity = new ProxiedRemoteMembership("provider2", "key2");
     entity.LoginProvider.ShouldEqual(entity.Id.LoginProvider);
     entity.ProviderKey.ShouldEqual(entity.Id.ProviderKey);
 }
Exemplo n.º 5
0
        public void ByUserLoginInfoAsync_Enumerable_CanDisallowNull()
        {
            var data = new[]
            {
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
            };

            foreach (var localMembership in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    string loginProvider    = FakeData.String();
                    string providerKey      = FakeData.String();
                    var    remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
                    localMembership.User.RemoteMemberships.Add(remoteMembership);
                }
            }
            var dbSet = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data.AsQueryable());
            var existingRemoteMembership = data[0].User.RemoteMemberships.First();
            var userLoginInfo            = new UserLoginInfo(
                existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey);

            dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result.ShouldNotBeNull();

            userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());
            var exception = Assert.Throws <InvalidOperationException>(() =>
                                                                      dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result);

            Assert.NotNull(exception);
            exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
            .ShouldEqual(0);
        }
Exemplo n.º 6
0
        public void ComponentProperties_DelegateTo_CompositeId()
        {
            var entity = new RemoteMembership
            {
                Id =
                {
                    LoginProvider = "provider1",
                    ProviderKey   = "key1"
                }
            };

            entity.LoginProvider.ShouldEqual(entity.Id.LoginProvider);
            entity.ProviderKey.ShouldEqual(entity.Id.ProviderKey);
            entity = new ProxiedRemoteMembership("provider2", "key2");
            entity.LoginProvider.ShouldEqual(entity.Id.LoginProvider);
            entity.ProviderKey.ShouldEqual(entity.Id.ProviderKey);
        }
Exemplo n.º 7
0
        public void ByUserLoginInfo_Enumerable_CanDisallowNull()
        {
            var data = new[]
            {
                new User {
                    Name = FakeData.String(),
                },
                new User {
                    Name = FakeData.String(),
                },
                new User {
                    Name = FakeData.String(),
                },
            };

            foreach (var user in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    string loginProvider    = FakeData.String();
                    string providerKey      = FakeData.String();
                    var    remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
                    user.RemoteMemberships.Add(remoteMembership);
                }
            }
            var existingRemoteMembership = data[0].RemoteMemberships.First();
            var userLoginInfo            = new UserLoginInfo(
                existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey);

            data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false).ShouldNotBeNull();

            userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());
            var exception = Assert.Throws <InvalidOperationException>(() =>
                                                                      data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false));

            Assert.NotNull(exception);
            exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
            .ShouldEqual(0);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public void ByUserLoginInfoAsync_Enumerable_CanDisallowNull()
        {
            var data = new[]
            {
                new LocalMembership { User = new User { Name = FakeData.String() }, },
                new LocalMembership { User = new User { Name = FakeData.String() }, },
                new LocalMembership { User = new User { Name = FakeData.String() }, },
            };
            foreach (var localMembership in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    string loginProvider = FakeData.String();
                    string providerKey = FakeData.String();
                    var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
                    localMembership.User.RemoteMemberships.Add(remoteMembership);
                }
            }
            var dbSet = new Mock<DbSet<LocalMembership>>(MockBehavior.Strict).SetupDataAsync(data.AsQueryable());
            var existingRemoteMembership = data[0].User.RemoteMemberships.First();
            var userLoginInfo = new UserLoginInfo(
                existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey);
            dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result.ShouldNotBeNull();

            userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());
            var exception = Assert.Throws<InvalidOperationException>(() =>
                dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result);
            Assert.NotNull(exception);
            exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
                .ShouldEqual(0);
        }
Exemplo n.º 10
0
 public void ByUserLoginInfoAsync_Enumerable_CanAllowNull()
 {
     var data = new[]
     {
         new LocalMembership { User = new User { Name = FakeData.String() }, },
         new LocalMembership { User = new User { Name = FakeData.String() }, },
         new LocalMembership { User = new User { Name = FakeData.String() }, },
     };
     foreach (var localMembership in data)
     {
         for (var i = 0; i < 3; i++)
         {
             string loginProvider = FakeData.String();
             string providerKey = FakeData.String();
             var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
             localMembership.User.RemoteMemberships.Add(remoteMembership);
         }
     }
     var dbSet = new Mock<DbSet<LocalMembership>>(MockBehavior.Strict).SetupDataAsync(data.AsQueryable());
     var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());
     dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo).Result.ShouldBeNull();
 }
Exemplo n.º 11
0
 public void ByUserLoginInfo_Enumerable_CanAllowNull()
 {
     var data = new[]
     {
         new LocalMembership { User = new User { Name = FakeData.String() }, },
         new LocalMembership { User = new User { Name = FakeData.String() }, },
         new LocalMembership { User = new User { Name = FakeData.String() }, },
     };
     foreach (var localMembership in data)
     {
         for (var i = 0; i < 3; i++)
         {
             string loginProvider = FakeData.String();
             string providerKey = FakeData.String();
             var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
             localMembership.User.RemoteMemberships.Add(remoteMembership);
         }
     }
     var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());
     data.AsEnumerable().ByUserLoginInfo(userLoginInfo).ShouldBeNull();
 }
Exemplo n.º 12
0
        public void ByUserLoginInfo_Enumerable_CanDisallowNull()
        {
            var data = new[]
            {
                new User { Name = FakeData.String(), },
                new User { Name = FakeData.String(), },
                new User { Name = FakeData.String(), },
            };
            foreach (var user in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    string loginProvider = FakeData.String();
                    string providerKey = FakeData.String();
                    var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey);
                    user.RemoteMemberships.Add(remoteMembership);
                }
            }
            var existingRemoteMembership = data[0].RemoteMemberships.First();
            var userLoginInfo = new UserLoginInfo(
                existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey);
            data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false).ShouldNotBeNull();

            userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String());
            var exception = Assert.Throws<InvalidOperationException>(() =>
                data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false));
            Assert.NotNull(exception);
            exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
                .ShouldEqual(0);
        }