public void Foreach_calls_generic_GetEnumerator()
        {
            var shaperMock = MockHelper.CreateShaperMock <string>();

            shaperMock.Setup(m => m.GetEnumerator()).Returns(
                () =>
                new DbEnumeratorShim <string>(((IEnumerable <string>) new[] { "foo" }).GetEnumerator()));
            var objectQuery = MockHelper.CreateMockObjectQuery(refreshedValue: null, shaper: shaperMock.Object).Object;

            foreach (var element in objectQuery)
            {
                Assert.True(element.StartsWith("foo"));
            }
        }
        private void GetEnumerator_calls_Shaper_GetEnumerator_lazily_implementation(Func <ObjectQuery <object>, IEnumerator> getEnumerator)
        {
            var shaperMock = MockHelper.CreateShaperMock <object>();

            shaperMock.Setup(m => m.GetEnumerator()).Returns(
                () => new DbEnumeratorShim <object>(((IEnumerable <object>) new[] { new object() }).GetEnumerator()));
            var objectQuery = MockHelper.CreateMockObjectQuery(null, shaperMock.Object).Object;

            var enumerator = getEnumerator(objectQuery);

            shaperMock.Verify(m => m.GetEnumerator(), Times.Never());

            enumerator.MoveNext();

            shaperMock.Verify(m => m.GetEnumerator(), Times.Once());
        }
Example #3
0
        private ObjectResult VerifyMethod(Action <ObjectResult <object> > methodInvoke, Expression <Action <Shaper <object> > > mockMethodInvoke)
        {
            Assert.NotNull(methodInvoke);
            Assert.NotNull(mockMethodInvoke);

            var shaperMock = MockHelper.CreateShaperMock <object>();

            shaperMock.Setup(m => m.GetEnumerator()).Returns(new Mock <IDbEnumerator <object> >().Object);
            var objectResult = new Mock <ObjectResult <object> >(shaperMock.Object, null, null)
            {
                CallBase = true
            }.Object;

            methodInvoke(objectResult);

            shaperMock.Verify(mockMethodInvoke, Times.Once());

            return(objectResult);
        }