Example #1
0
        private void VerifyMethodInitialization(Action <BridgeDataReader> methodToInvoke, bool async = false)
        {
            Assert.NotNull(methodToInvoke);

            var sourceEnumerable = new[] { new object[] { 1 } };

            var rootCoordinatorFactory = MockHelper.CreateCoordinatorFactory <int, RecordState>(
                depth: 0,
                stateSlot: 0,
                ordinal: 0,
                nestedCoordinators: new CoordinatorFactory[0],
                producedValues: null);

            var shaperMock = new Mock <Shaper <RecordState> >(
                Common.Internal.Materialization.MockHelper.CreateDbDataReader(sourceEnumerable),
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 2,
                rootCoordinatorFactory,
                /*readerOwned*/ false,
                /*useSpatialReader*/ false,
                /*shouldReleaseConnection*/ true)
            {
                CallBase = true
            };

            var bridgeDataReaderMock = new Mock <BridgeDataReader>(shaperMock.Object, rootCoordinatorFactory, 0, null)
            {
                CallBase = true
            };

            bridgeDataReaderMock.Protected().Setup("EnsureInitialized").Verifiable();
#if !NET40
            bridgeDataReaderMock.Protected().Setup <Task>("EnsureInitializedAsync", ItExpr.IsAny <CancellationToken>()).Verifiable();
#endif

            try
            {
                methodToInvoke(bridgeDataReaderMock.Object);
            }
            catch (Exception)
            {
            }

            if (async)
            {
                bridgeDataReaderMock.Protected().Verify <Task>(
                    "EnsureInitializedAsync", Times.AtLeastOnce(), ItExpr.IsAny <CancellationToken>());
            }
            else
            {
                bridgeDataReaderMock.Protected().Verify("EnsureInitialized", Times.AtLeastOnce());
            }
        }
Example #2
0
        private BridgeDataRecord CreateBridgeDataRecord()
        {
            var dbDataReaderMock = new Mock <DbDataReader>();

            var coordinatorFactory = MockHelper.CreateCoordinatorFactory <RecordState>(shaper => null);

            var shaperMock = new Mock <Shaper <RecordState> >(
                dbDataReaderMock.Object,
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 1,
                coordinatorFactory,
                /*checkPermissions*/ null,
                /*readerOwned*/ false)
            {
                CallBase = true
            };

            return(new BridgeDataRecord(shaperMock.Object, 0));
        }
Example #3
0
        public void Constructors_dont_advance_the_underlying_shaper()
        {
            var sourceEnumerable = new[] { new object[] { 1 } };

            var rootCoordinatorFactory = MockHelper.CreateCoordinatorFactory <int, RecordState>(
                depth: 0,
                stateSlot: 0,
                ordinal: 0,
                nestedCoordinators: new CoordinatorFactory[0],
                producedValues: null);

            var shaperMock = new Mock <Shaper <RecordState> >(
                Common.Internal.Materialization.MockHelper.CreateDbDataReader(sourceEnumerable),
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 2,
                rootCoordinatorFactory,
                /*readerOwned*/ false,
                /*useSpatialReader*/ false,
                /*shouldReleaseConnection*/ true)
            {
                CallBase = true
            };

            shaperMock.Setup(m => m.GetEnumerator()).Returns(
                () =>
            {
                Assert.True(false);
                return(null);
            });

            // Verify these methods don't cause initialization
            var bridgeDataReader = new BridgeDataReader(shaperMock.Object, rootCoordinatorFactory, 0, null);

            bridgeDataReader.GetEnumerator();
        }
Example #4
0
        private BridgeDataReader CreateNestedBridgeDataReader(DbDataReader dataReader = null)
        {
            var sourceEnumerable1 = new[]
            {
                new object[] { 1 },
                new object[] { null },
                new object[] { 2 },
                new object[] { 2 }
            };

            var sourceEnumerable2 = new[]
            {
                new object[] { 1 },
                new object[] { 3 },
            };

            dataReader = dataReader
                         ?? Common.Internal.Materialization.MockHelper.CreateDbDataReader(sourceEnumerable1, sourceEnumerable2);

            var rootCoordinatorFactory = MockHelper.CreateCoordinatorFactory <int, RecordState>(
                depth: 0,
                stateSlot: 0,
                ordinal: 0,
                nestedCoordinators: new CoordinatorFactory[0],
                producedValues: null);

            var shaperMock = new Mock <Shaper <RecordState> >(
                dataReader,
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 2,
                rootCoordinatorFactory,
                /*checkPermissions*/ null,
                /*readerOwned*/ false)
            {
                CallBase = true
            };

            var rootCoordinatorFactory2 = MockHelper.CreateCoordinatorFactory <int, RecordState>(
                depth: 0,
                stateSlot: 0,
                ordinal: 0,
                nestedCoordinators: new CoordinatorFactory[0],
                producedValues: null);

            var shaperMock2 = new Mock <Shaper <RecordState> >(
                dataReader,
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 2,
                rootCoordinatorFactory2,
                /*checkPermissions*/ null,
                /*readerOwned*/ false)
            {
                CallBase = true
            };

            var nextResultInfo = new[]
            {
                new KeyValuePair <Shaper <RecordState>, CoordinatorFactory <RecordState> >(
                    shaperMock2.Object, rootCoordinatorFactory2)
            }.ToList();

            return(new BridgeDataReader(shaperMock.Object, rootCoordinatorFactory, 0, nextResultInfo.GetEnumerator()));
        }