Exemplo n.º 1
0
        public void Users_GivenUserManagerReturnsUsers_ReturnUserListMessage()
        {
            // Arrange
            List <User> usersList = new List <User>
            {
                new User
                {
                    UserName     = "******",
                    Email        = "*****@*****.**",
                    CreationDate = DateTime.Now,
                    UpdateDate   = DateTime.Now
                }
            };

            _userManagerMock.Setup(mock => mock.Users).Returns(usersList.AsQueryable());

            // Act
            UsersListMessage resultMessage = _identityService.Users;

            // Assert
            Assert.NotNull(resultMessage);
            Assert.True(resultMessage.OperationStatus);
            Assert.NotEmpty(resultMessage.Users);
            Assert.True(resultMessage.Users.Select(u => u.Login).SequenceEqual(usersList.Select(u => u.UserName)));
            Assert.True(resultMessage.Users.Select(u => u.Email).SequenceEqual(usersList.Select(u => u.Email)));
        }
Exemplo n.º 2
0
        public void GetAllUsers_WhenIdentityServiceSucceeds_ReturnUsersListMessage()
        {
            // Arrange
            UsersListMessage usersListMessage = new UsersListMessage
            {
                OperationStatus = true,
                Users           = new List <UserResult>
                {
                    new UserResult
                    {
                        Login        = "******",
                        Email        = "*****@*****.**",
                        CreationDate = DateTime.Now,
                        UpdateDate   = DateTime.Now
                    }
                }
            };

            _identityServiceMock.Setup(mock => mock.Users).Returns(usersListMessage);

            // Act
            OkObjectResult result = _usersController.GetAllUsers() as OkObjectResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(usersListMessage, result.Value);
        }
Exemplo n.º 3
0
        public void GetAllUsers_WhenIdentityServiceFails_ReturnErrorMessage()
        {
            // Arrange
            _identityServiceMock.Setup(mock => mock.Users).Throws(new Exception());

            // Act
            ObjectResult result = _usersController.GetAllUsers() as ObjectResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(500, result.StatusCode);
            UsersListMessage resultValue = result.Value as UsersListMessage;

            Assert.False(resultValue.OperationStatus);
            Assert.Equal(MessageResources.FetchingAllUsersFailed, resultValue.ErrorMessages.First());
        }