コード例 #1
0
        public async Task UsersControllerTests_CreateUser()
        {
            var user           = UserDummyGenerator.Generate();
            var userRepository = UserRepositoryMock.GetMock();
            var unitOfWork     = UnitOfWorkMock.GetMock();
            var userController = new UsersController(unitOfWork.Object, userRepository.Object);

            var result = await userController.CreateUser(user);

            Assert.NotNull(result);
            Assert.IsType <OkResult>(result);

            userRepository.Verify(x => x.AddAsync(It.Is <User>(y => y == user)));
            unitOfWork.Verify(x => x.CommitAsync());
        }
コード例 #2
0
        public async Task UsersControllerTests_GetAll()
        {
            var users          = UserDummyGenerator.GenerateCollection(5) as List <User>;
            var userRepository = UserRepositoryMock.GetMockAndSetUpAsync(users);
            var unitOfWork     = UnitOfWorkMock.GetMock();
            var userController = new UsersController(unitOfWork.Object, userRepository.Object);
            var result         = await userController.GetAll();

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);

            var resultUsers = (result as OkObjectResult).Value as List <User>;

            Assert.True(Enumerable.SequenceEqual(users.OrderBy(t => t.UserId), resultUsers.OrderBy(t => t.UserId), new UserComparer()));
        }