public void Handler_ReturnsNullUser_WhenFound_ByUnverifiedEmail()
        {
            var nameOrEmail = FakeData.Email();
            var query       = new UserByNameOrVerifiedEmail(nameOrEmail);
            var queries     = new Mock <IProcessQueries>(MockBehavior.Strict);
            Expression <Func <UserBy, bool> > expectedUserQuery =
                x => x.Name == nameOrEmail;

            queries.Setup(x => x.Execute(It.Is(expectedUserQuery)))
            .Returns(Task.FromResult(null as User));
            var user = new User {
                Name = FakeData.String(),
            };
            var emailAddress = new EmailAddress
            {
                Value      = nameOrEmail,
                UserId     = user.Id,
                User       = user,
                IsVerified = false,
            };
            Expression <Func <EmailAddressBy, bool> > expectedEmailQuery =
                x => x.Value == nameOrEmail && x.IsVerified == true;

            queries.Setup(x => x.Execute(It.Is(expectedEmailQuery)))
            .Returns(Task.FromResult(emailAddress));
            var handler = new HandleUserByNameOrVerifiedEmailQuery(queries.Object);

            User result = handler.Handle(query).Result;

            result.ShouldBeNull();
            queries.Verify(x => x.Execute(It.Is(expectedUserQuery)), Times.Once);
            queries.Verify(x => x.Execute(It.Is(expectedEmailQuery)), Times.Once);
        }
        public void Query_Ctor_SetsNameOrEmailProperty()
        {
            var nameOrEmail = FakeData.Email();
            var query       = new UserByNameOrVerifiedEmail(nameOrEmail);

            query.NameOrEmail.ShouldEqual(nameOrEmail);
        }
Пример #3
0
        public void Query_Ctor_SetsNameOrEmailProperty()
        {
            var nameOrEmail = string.Format("{0}@domain.tld", Guid.NewGuid());
            var query       = new UserByNameOrVerifiedEmail(nameOrEmail);

            query.NameOrEmail.ShouldEqual(nameOrEmail);
        }
Пример #4
0
        public void Handler_ReturnsNonNullUser_WhenFound_ByVerifiedEmail()
        {
            var nameOrEmail = string.Format("{0}@domain.tld", Guid.NewGuid());
            var query       = new UserByNameOrVerifiedEmail(nameOrEmail);
            var queries     = new Mock <IProcessQueries>(MockBehavior.Strict);
            Expression <Func <UserBy, bool> > expectedUserQuery =
                x => x.Name == nameOrEmail;

            queries.Setup(x => x.Execute(It.Is(expectedUserQuery)))
            .Returns(Task.FromResult(null as User));
            var user = new User {
                Name = Guid.NewGuid().ToString(),
            };
            var emailAddress = new EmailAddress
            {
                Value      = nameOrEmail,
                UserId     = user.Id,
                User       = user,
                IsVerified = true,
            };
            Expression <Func <EmailAddressBy, bool> > expectedEmailQuery =
                x => x.Value == nameOrEmail && x.IsVerified == true;

            queries.Setup(x => x.Execute(It.Is(expectedEmailQuery)))
            .Returns(Task.FromResult(emailAddress));
            var handler = new HandleUserByNameOrVerifiedEmailQuery(queries.Object);

            User result = handler.Handle(query).Result;

            result.ShouldNotBeNull();
            result.Name.ShouldEqual(user.Name);
            queries.Verify(x => x.Execute(It.Is(expectedUserQuery)), Times.Once);
            queries.Verify(x => x.Execute(It.Is(expectedEmailQuery)), Times.Once);
        }
Пример #5
0
        public Task <User> Handle(UserByNameOrVerifiedEmail query)
        {
            var user = _queries.Execute(new UserBy(query.NameOrEmail)).Result;

            if (user != null)
            {
                return(Task.FromResult(user));
            }

            var email = _queries.Execute(new EmailAddressBy(query.NameOrEmail)
            {
                IsVerified = true,
                EagerLoad  = new Expression <Func <EmailAddress, object> >[]
                {
                    x => x.User,
                },
            }).Result;

            user = email != null && email.IsVerified ? email.User : null;
            return(Task.FromResult(user));
        }
        public void Handler_ReturnsNonNullUser_WhenFound_ByUserName()
        {
            var nameOrEmail = FakeData.Email();
            var query       = new UserByNameOrVerifiedEmail(nameOrEmail);
            var queries     = new Mock <IProcessQueries>(MockBehavior.Strict);
            var user        = new User {
                Name = nameOrEmail,
            };
            Expression <Func <UserBy, bool> > expectedUserQuery =
                x => x.Name == nameOrEmail;

            queries.Setup(x => x.Execute(It.Is(expectedUserQuery)))
            .Returns(Task.FromResult(user));
            queries.Setup(x => x.Execute(It.IsAny <EmailAddressBy>()))
            .Returns(Task.FromResult(null as EmailAddress));
            var handler = new HandleUserByNameOrVerifiedEmailQuery(queries.Object);

            User result = handler.Handle(query).Result;

            result.ShouldNotBeNull();
            result.Name.ShouldEqual(nameOrEmail);
            queries.Verify(x => x.Execute(It.Is(expectedUserQuery)), Times.Once);
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressBy>()), Times.Never);
        }