Example #1
0
        public void MockDataList()
        {
            //var customerList = CustomerList().AsQueryable();
            var customerDbSetMock = new Mock <DbSet <Customer> >();

            customerDbSetMock.As <IQueryable <Customer> >()
            .Setup(m => m.Provider);
            //.Returns(customerList.Provider);

            customerDbSetMock.As <IQueryable <Customer> >()
            .Setup(m => m.Expression);
            //.Returns(customerList.Expression);

            customerDbSetMock.As <IQueryable <Customer> >()
            .Setup(m => m.ElementType);
            //.Returns(customerList.ElementType);

            customerDbSetMock.As <IQueryable <Customer> >()
            .Setup(m => m.GetEnumerator());
            //.Returns(customerList.GetEnumerator());

            var webContextMock =
                new Mock <WebContextDb>();

            webContextMock.Setup(m => m.Set <Customer>()).
            Returns(customerDbSetMock.Object);

            webContextMock.Setup(m => m.Set <Customer>()).
            Returns(customerDbSetMock.Object);

            var repository =
                new BaseRepositorio <Customer>(webContextMock.Object);

            var customerGetByID = repository
                                  .GetById(p => p.FirstName == "Name1");

            customerGetByID.Should().NotBeNull();
        }