Esempio n. 1
0
        public void Handler_ReturnsClientCookie_WhenUserById_Exists()
        {
            var userId   = new Random().Next(3, int.MaxValue);
            var userName = Guid.NewGuid().ToString();
            var query    = new ClientCookieBy(userId);
            var user     = new ProxiedUser(userId)
            {
                Name = userName
            };

            user.EmailAddresses.Add(new EmailAddress
            {
                HashedValue = "Email 0 hashed value",
            });
            user.EmailAddresses.Add(new EmailAddress
            {
                IsPrimary   = true,
                HashedValue = "Email 1 hashed value",
            });
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            Expression <Func <UserBy, bool> > expectedQuery = x => x.Id == query.UserId;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(user as User));
            var handler = new HandleClientCookieByQuery(queries.Object);

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

            Assert.NotNull(result);
            result.UserId.ShouldEqual(userId);
            result.UserName.ShouldEqual(userName);
            result.GravatarHash.ShouldEqual(user.EmailAddresses.Single(x => x.IsPrimary).HashedValue);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
        }
Esempio n. 2
0
        public void Handler_ReturnsNull_WhenUserId_IsNull()
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var query   = new ClientCookieBy(null);
            var handler = new HandleClientCookieByQuery(queries.Object);

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

            result.ShouldBeNull();
        }
Esempio n. 3
0
        public void Handler_ReturnsNull_WhenUserById_DoesNotExist()
        {
            const int userId  = 456;
            var       query   = new ClientCookieBy(userId);
            var       queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            Expression <Func <UserBy, bool> > expectedQuery = x => x.Id == query.UserId;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(null as User));
            var handler = new HandleClientCookieByQuery(queries.Object);

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

            result.ShouldBeNull();
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
        }
Esempio n. 4
0
        public async Task <ClientCookie> Handle(ClientCookieBy query)
        {
            ClientCookie clientCookie = null;

            if (query.UserId.HasValue)
            {
                var user = await _queries.Execute(new UserBy(query.UserId.Value))
                           .ConfigureAwait(false);

                if (user != null)
                {
                    clientCookie = new ClientCookie
                    {
                        UserId       = user.Id,
                        UserName     = user.Name,
                        GravatarHash = user.EmailAddresses.First(y => y.IsPrimary).HashedValue,
                    };
                }
            }

            return(clientCookie);
        }
Esempio n. 5
0
        public void Query_Ctor_SetsUserIdProperty(int?userId)
        {
            var query = new ClientCookieBy(userId);

            query.UserId.ShouldEqual(userId);
        }