private void ExecuteSqlQueryAsync_delegates_lazily(bool noTracking, bool streaming) { var objectContextMock = Mock.Get(MockHelper.CreateMockObjectContext <string>()); var internalSet = CreateInternalSet(objectContextMock, "foo"); var actualEnumerator = internalSet.ExecuteSqlQueryAsync("", noTracking, streaming, new object[0]); // The query shouldn't have run yet objectContextMock .Verify( m => m.ExecuteStoreQueryAsync <string>( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ExecutionOptions>(), It.IsAny <CancellationToken>(), It.IsAny <object[]>()), Times.Never()); actualEnumerator.MoveNextAsync(CancellationToken.None).Wait(); objectContextMock .Verify( m => m.ExecuteStoreQueryAsync <string>( It.IsAny <string>(), It.IsAny <string>(), new ExecutionOptions(noTracking ? MergeOption.NoTracking : MergeOption.AppendOnly, streaming), It.IsAny <CancellationToken>(), It.IsAny <object[]>()), Times.Once()); Assert.Equal("foo", actualEnumerator.Current); }
public void ExecuteSqlQueryAsync_delegates_lazily() { var objectContextMock = Mock.Get(MockHelper.CreateMockObjectContext <string>()); var internalSet = CreateInternalSet(objectContextMock, "foo"); var actualEnumerator = internalSet.ExecuteSqlQueryAsync("", true, new object[0]); // The query shouldn't have run yet objectContextMock .Verify( m => m.ExecuteStoreQueryAsync <string>( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MergeOption>(), It.IsAny <CancellationToken>(), It.IsAny <object[]>()), Times.Never()); actualEnumerator.MoveNextAsync(CancellationToken.None).Wait(); objectContextMock .Verify( m => m.ExecuteStoreQueryAsync <string>( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MergeOption>(), It.IsAny <CancellationToken>(), It.IsAny <object[]>()), Times.Once()); Assert.Equal("foo", actualEnumerator.Current); }
public void AsStreaming_sets_Streaming_on_internal_query() { var objectContextMock = Mock.Get(MockHelper.CreateMockObjectContext <string>()); var internalSet = CreateInternalSet(objectContextMock, "foo"); Assert.True(internalSet.ObjectQuery.Streaming); var streamingQuery = internalSet.AsStreaming(); Assert.True(streamingQuery.ObjectQuery.Streaming); }
public void GetEnumerator_calls_ObjectQuery_GetEnumerator() { var objectContextMock = Mock.Get(MockHelper.CreateMockObjectContext <string>()); var internalSet = CreateInternalSet(objectContextMock, "foo"); var enumerator = internalSet.GetEnumerator(); var executionPlanMock = Mock.Get(objectContextMock.Object.CreateQuery <string>("").QueryState.GetExecutionPlan(MergeOption.NoTracking)); executionPlanMock.Verify( m => m.Execute <string>(It.IsAny <ObjectContext>(), It.IsAny <ObjectParameterCollection>()), Times.Never()); enumerator.MoveNext(); executionPlanMock.Verify(m => m.Execute <string>(It.IsAny <ObjectContext>(), It.IsAny <ObjectParameterCollection>()), Times.Once()); }
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()); }