Ejemplo 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);
        }
Ejemplo 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();
        }
Ejemplo 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);
        }