Beispiel #1
0
        public void Get_For_Invalid_Repository_Must_Return_NULL()
        {
            //
            // Arrange
            //
            var mockedList = Enumerable.Range(1, 10).Select(x =>
            {
                var mockModel = new Mock<IModel>();
                mockModel.Setup(y => y.Id).Returns(x);

                return mockModel.Object;
            }).AsQueryable();

            var mockRepository = new Mock<IRepository<IModel>>();
            mockRepository.Setup(x => x.GetAll()).Returns(mockedList);

            var mockContext = new Mock<EFDbContext>();
            var mockRepoFactory = new Mock<IRepositoryFactory>();
            mockRepoFactory.Setup(x => x.GetRepository<IModel>()).Returns<IModel>(null);

            var mockedUoW = new UoW(mockContext.Object, mockRepoFactory.Object);
            Expression<Func<IModel, bool>> filterExpression = x => x.Id == 1;

            //
            // Act
            //
            var results = mockedUoW.Get(filterExpression);
            //
            // Assert
            //
            Assert.IsNull(results);
        }
Beispiel #2
0
        public void Get_For_A_NULL_Filter_Must_Return_All()
        {
            //
            // Arrange
            //
            var mockedList = Enumerable.Range(1, 10).Select(x =>
            {
                var mockModel = new Mock<IModel>();
                mockModel.Setup(y => y.Id).Returns(x);

                return mockModel.Object;
            }).AsQueryable();

            var mockRepository = new Mock<IRepository<IModel>>();
            mockRepository.Setup(x => x.GetAll()).Returns(mockedList);

            var mockContext = new Mock<EFDbContext>();
            var mockRepoFactory = new Mock<IRepositoryFactory>();
            mockRepoFactory.Setup(x => x.GetRepository<IModel>()).Returns(mockRepository.Object);

            var mockedUoW = new UoW(mockContext.Object, mockRepoFactory.Object);
            Expression<Func<IModel, bool>> filterExpression = null;

            //
            // Act
            //
            var results = mockedUoW.Get(filterExpression);
            //
            // Assert
            //
            Assert.IsNotNull(results);
            Assert.AreEqual(results.Count(), 10);
            Assert.AreEqual(results.First().Id, 1);
        }