예제 #1
0
        public void UserLoginStoreInterface_FindAsync_ThrowsArgumentNullException_WhenUserLoginInfoIsNull()
        {
            var instance  = new SecurityStore(null) as IUserLoginStore <User, int>;
            var exception = Assert.Throws <ArgumentNullException>(() =>
                                                                  instance.FindAsync(null).GetAwaiter().GetResult());

            exception.ShouldNotBeNull();
            exception.ParamName.ShouldEqual("login");
        }
예제 #2
0
        public void UserLoginStoreInterface_FindAsync_ThrowsWhenDisposed()
        {
            var instance = new SecurityStore(null) as IUserLoginStore <User, int>;

            instance.Dispose();
            var exception = Assert.Throws <ObjectDisposedException>(() =>
                                                                    instance.FindAsync(new UserLoginInfo("provider", "key")).GetAwaiter().GetResult());

            exception.ShouldNotBeNull();
            exception.ObjectName.ShouldEqual(instance.GetType().Name);
        }
예제 #3
0
        public void UserLoginStoreInterface_FindAsync_FindsMatchingRemoteMemberships()
        {
            using (var dbContext = new EntityDbContext())
            {
                var user = new User {
                    Name = Guid.NewGuid().ToString()
                };
                var remote1 = new RemoteMembership
                {
                    Id =
                    {
                        LoginProvider = Guid.NewGuid().ToString(),
                        ProviderKey   = Guid.NewGuid().ToString()
                    }
                };
                var remote2 = new RemoteMembership
                {
                    Id =
                    {
                        LoginProvider = Guid.NewGuid().ToString(),
                        ProviderKey   = Guid.NewGuid().ToString()
                    }
                };
                var remote3 = new RemoteMembership
                {
                    Id =
                    {
                        LoginProvider = Guid.NewGuid().ToString(),
                        ProviderKey   = Guid.NewGuid().ToString()
                    }
                };
                user.RemoteMemberships.Add(remote1);
                user.RemoteMemberships.Add(remote2);
                user.RemoteMemberships.Add(remote3);
                dbContext.Create(user);
                dbContext.SaveChangesAsync().GetAwaiter().GetResult();

                var securityStore = new SecurityStore(dbContext);
                var result        = securityStore.FindAsync(new UserLoginInfo(remote2.LoginProvider, remote2.ProviderKey)).Result;

                result.ShouldNotBeNull();
                result.ShouldEqual(user);
            }
        }
예제 #4
0
        public void UserLoginStoreInterface_FindAsync_DelegatesToDataDependency(string provider, string key, bool expectFound)
        {
            var entities = new Mock <IWriteEntities>(MockBehavior.Strict);
            var instance = new SecurityStore(entities.Object) as IUserLoginStore <User, int>;
            var data     = new[]
            {
                new User {
                    Name = "user1"
                },
            }.AsQueryable();

            data.Single().RemoteMemberships.Add(new RemoteMembership
            {
                Id = { LoginProvider = Guid.NewGuid().ToString(), ProviderKey = Guid.NewGuid().ToString() }
            });
            data.Single().RemoteMemberships.Add(new RemoteMembership
            {
                Id = { LoginProvider = "provider1", ProviderKey = "key1" }
            });
            data.Single().RemoteMemberships.Add(new RemoteMembership
            {
                Id = { LoginProvider = Guid.NewGuid().ToString(), ProviderKey = Guid.NewGuid().ToString() }
            });
            var dbSet = new Mock <DbSet <User> >(MockBehavior.Strict).SetupDataAsync(data);

            entities.Setup(x => x.Get <User>()).Returns(dbSet.Object);
            Expression <Func <IQueryable <User>, bool> > expectedData = x => ReferenceEquals(x, dbSet.Object);

            entities.Setup(x => x.EagerLoad(It.Is(expectedData), It.IsAny <Expression <Func <User, object> > >())).Returns(dbSet.Object);

            var result = instance.FindAsync(new UserLoginInfo(provider, key)).Result;

            (result != null).ShouldEqual(expectFound);
            if (expectFound)
            {
                result.ShouldEqual(data.Single());
            }
            entities.Verify(x => x.Get <User>(), Times.Once);
        }