Example #1
0
        public async Task GetAllUsers_ListOfUsers_Ok()
        {
            // Arrange
            var service = new MockUserService
            {
                MGetAllUsersOrderedByNameAsync = () => new[]
                {
                    MockApplicationUserDto.Get(0),
                    MockApplicationUserDto.Get(1)
                }
            };
            var controller = new UserController(service);

            // Act
            var result = await controller.GetAllUsers() as OkObjectResult;

            var list = result?.Value as ApplicationUserDto[];

            // Assert
            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(list);
            Assert.Equal(2, list.Count());
            Assert.Equal(MockApplicationUserDto.Get(0).Id, list[0].Id);
            Assert.Equal(MockApplicationUserDto.Get(0).Email, list[0].Email);
            Assert.Equal(MockApplicationUserDto.Get(0).Name, list[0].Name);
            Assert.Equal(MockApplicationUserDto.Get(1).Id, list[1].Id);
            Assert.Equal(MockApplicationUserDto.Get(1).Email, list[1].Email);
            Assert.Equal(MockApplicationUserDto.Get(1).Name, list[1].Name);
        }
        public void ApplicationUserDto_Setter_Modifies()
        {
            // Arrange
            var user = MockApplicationUserDto.Get(1);

            // Act
            user.Id    = "1317f39e-6265-44e5-ae62-0d537ab650f7";
            user.Email = "*****@*****.**";
            user.Name  = "George Nada";

            // Assert
            Assert.Equal("1317f39e-6265-44e5-ae62-0d537ab650f7", user.Id);
            Assert.Equal("*****@*****.**", user.Email);
            Assert.Equal("George Nada", user.Name);
        }
Example #3
0
        public async Task GetUserById_ExistingUser_UserDto()
        {
            // Arrange
            var service = new MockUserService
            {
                MGetUserByIdAsync = (userId) => MockApplicationUserDto.Get(0)
            };
            var controller = new UserController(service);

            // Act
            var result = await controller.GetUserById(MockApplicationUserDto.Get(0).Id) as OkObjectResult;

            var dto = result?.Value as ApplicationUserDto;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(dto);
            Assert.Equal(MockApplicationUserDto.Get(0).Id, dto.Id);
            Assert.Equal(MockApplicationUserDto.Get(0).Email, dto.Email);
            Assert.Equal(MockApplicationUserDto.Get(0).Name, dto.Name);
        }