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_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_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);
        }
Exemple #4
0
        public void Handler_ReturnsNonNullLocalMembership_WhenFound_ByUserLoginInfo()
        {
            var loginProvider = Guid.NewGuid().ToString();
            var providerKey   = Guid.NewGuid().ToString();
            var userLoginInfo = new UserLoginInfo(loginProvider, providerKey);
            var user          = new User();

            user.RemoteMemberships.Add(new ProxiedRemoteMembership(
                                           loginProvider, providerKey));
            var data = new[]
            {
                new LocalMembership
                {
                    User         = user,
                    PasswordHash = "password hash",
                },
            }.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.ShouldNotBeNull();
            result.User.ShouldEqual(user);
            result.PasswordHash.ShouldEqual("password hash");
            entities.Verify(x => x.Query <LocalMembership>(), Times.Once);
        }
        public void Query_StringCtor_SetsUserNameProperty()
        {
            var userName = FakeData.String();
            var query    = new LocalMembershipByUser(userName);

            query.UserId.ShouldBeNull();
            query.UserName.ShouldEqual(userName);
            query.UserLoginInfo.ShouldBeNull();
        }
        public void Query_IntCtor_SetsUserIdProperty()
        {
            var userId = FakeData.Id();
            var query  = new LocalMembershipByUser(userId);

            query.UserId.ShouldEqual(userId);
            query.UserName.ShouldBeNull();
            query.UserLoginInfo.ShouldBeNull();
        }
Exemple #7
0
        public void Query_IntCtor_SetsUserIdProperty()
        {
            var userId = new Random().Next(int.MinValue, int.MaxValue);
            var query  = new LocalMembershipByUser(userId);

            query.UserId.ShouldEqual(userId);
            query.UserName.ShouldBeNull();
            query.UserLoginInfo.ShouldBeNull();
        }
        public void Query_UserLoginInfoCtor_SetsUserLoginInfoProperty()
        {
            var loginProvider = FakeData.String();
            var providerKey   = FakeData.String();
            var userLoginInfo = new UserLoginInfo(loginProvider, providerKey);
            var query         = new LocalMembershipByUser(userLoginInfo);

            query.UserId.ShouldBeNull();
            query.UserName.ShouldBeNull();
            query.UserLoginInfo.ShouldEqual(userLoginInfo);
            query.UserLoginInfo.LoginProvider.ShouldEqual(loginProvider);
            query.UserLoginInfo.ProviderKey.ShouldEqual(providerKey);
        }
        public async Task <LocalMembership> Handle(LocalMembershipByUser query)
        {
            var queryable = _entities.Query <LocalMembership>().EagerLoad(query.EagerLoad);
            Task <LocalMembership> entityTask;

            if (query.UserId.HasValue)
            {
                entityTask = queryable.ByUserIdAsync(query.UserId.Value);
            }
            else if (query.UserLoginInfo != null)
            {
                entityTask = queryable.ByUserLoginInfoAsync(query.UserLoginInfo);
            }
            else
            {
                entityTask = queryable.ByUserNameAsync(query.UserName);
            }

            return(await entityTask.ConfigureAwait(false));
        }