Example #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());
        }
Example #2
0
        public async Task UserRepositoryEFTest_GetAll()
        {
            var users     = UserDummyGenerator.GenerateCollection(5);
            var mockDbSet = DbSetMock <User> .GetMockAndSetUpQueryble(users);

            var mockDbContext = DbContextMock <DbContext> .GetMockAndSetUpDbSet(mockDbSet);

            var mockUnitOfWork   = UnitOfWorkMock.GetMockAndSetUpContext(mockDbContext);
            var userRepositoryEF = new UserRepositoryEF(mockUnitOfWork.Object);
            var resultUsers      = await userRepositoryEF.GetAllAsync();

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