コード例 #1
0
        private void VerifyMethod(Action <InternalDbQuery <string> > methodInvoke, Expression <Action <IInternalQuery <string> > > mockMethodInvoke)
        {
            Assert.NotNull(methodInvoke);
            Assert.NotNull(mockMethodInvoke);

            var internalQueryMock = new Mock <IInternalQuery <string> >();

            internalQueryMock.Setup(m => m.GetEnumerator()).Returns(new Mock <IEnumerator <string> >().Object);
            internalQueryMock.Setup(m => m.AsNoTracking()).Returns(internalQueryMock.Object);
            internalQueryMock.Setup(m => m.Include(It.IsAny <string>())).Returns(internalQueryMock.Object);
            var dbQuery = new InternalDbQuery <string>(internalQueryMock.Object);

            methodInvoke(dbQuery);

            internalQueryMock.Verify(mockMethodInvoke, Times.Once());
        }
コード例 #2
0
        public void NonGeneric_methods_delegate_to_underlying_InternalQuery_correctly()
        {
            var internalQueryMock           = new Mock <IInternalQuery <string> >();
            var nonGenericInternalQueryMock = internalQueryMock.As <IInternalQuery>();

            nonGenericInternalQueryMock.Setup(m => m.GetEnumerator()).Returns(new Mock <IEnumerator>().Object);
            var dbQuery = new InternalDbQuery <string>(internalQueryMock.Object);

#if !NET40
            ((IDbAsyncEnumerable)dbQuery).GetAsyncEnumerator();

            nonGenericInternalQueryMock.Verify(m => m.GetAsyncEnumerator(), Times.Once());
#endif

            ((IEnumerable)dbQuery).GetEnumerator();

            nonGenericInternalQueryMock.Verify(m => m.GetEnumerator(), Times.Once());
        }
コード例 #3
0
        private void VerifyGetter <TProperty, TInternalProperty>(
            Func <InternalDbQuery <string>, TProperty> getterFunc,
            Expression <Func <IInternalQuery <string>, TInternalProperty> > mockGetterFunc)
        {
            Assert.NotNull(getterFunc);
            Assert.NotNull(mockGetterFunc);

            var internalQueryMock = new Mock <IInternalQuery <string> >();

            internalQueryMock.Setup(m => m.ElementType).Returns(typeof(string));
            internalQueryMock.Setup(m => m.Expression).Returns(Expression.Constant(new object()));
            internalQueryMock.Setup(m => m.InternalContext).Returns(new Mock <InternalContextForMock <DbContext> >().Object);
            internalQueryMock.Setup(m => m.ObjectQueryProvider).Returns(
                new ObjectQueryProvider(MockHelper.CreateMockObjectContext <string>()));
            var dbQuery = new InternalDbQuery <string>(internalQueryMock.Object);

            getterFunc(dbQuery);
            internalQueryMock.VerifyGet(mockGetterFunc, Times.Once());
        }