Ejemplo n.º 1
0
        public async Task UserRepositoryEFTest_Add()
        {
            var user          = UserDummyGenerator.Generate();
            var mockDbSet     = new Mock <DbSet <User> >();
            var mockDbContext = DbContextMock <DbContext> .GetMockAndSetUpDbSet(mockDbSet);

            var mockUnitOfWork = UnitOfWorkMock.GetMockAndSetUpContext(mockDbContext);

            var repositoryUser = new UserRepositoryEF(mockUnitOfWork.Object);
            await repositoryUser.AddAsync(user);

            mockDbSet.Verify(m => m.AddAsync(It.Is <User>(y => y == user), It.IsAny <System.Threading.CancellationToken>()), Times.Once());
        }
Ejemplo n.º 2
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());
        }