Example #1
0
            public void Returns_EntityDataReader_RecordsAffected_as_a_result()
            {
                var entityConnection        = MockHelper.CreateEntityConnection();
                var entityCommandDefinition = MockHelper.CreateEntityCommandDefinition();

                var readNextCount = 0;

                var entityDataReaderMock = new Mock <EntityDataReader>();

                entityDataReaderMock.Setup(m => m.NextResult()).Callback(() => readNextCount++).Returns(() => readNextCount < 5);
                entityDataReaderMock.SetupGet(m => m.RecordsAffected).Returns(10);

                var entityDataReaderFactoryMock = new Mock <EntityCommand.EntityDataReaderFactory>();

                entityDataReaderFactoryMock.Setup(
                    m => m.CreateEntityDataReader(It.IsAny <EntityCommand>(), It.IsAny <DbDataReader>(), It.IsAny <CommandBehavior>())).
                Returns(entityDataReaderMock.Object);

                var entityCommand = new EntityCommand(
                    entityConnection, entityCommandDefinition,
                    new DbInterceptionContext(), entityDataReaderFactoryMock.Object);
                var result = entityCommand.ExecuteNonQuery();

                Assert.Equal(10, result);
            }
Example #2
0
            public void Calls_ExecuteReader_with_CommandBehavior_set_to_SequentialAccess()
            {
                var entityConnection        = MockHelper.CreateEntityConnection();
                var entityCommandDefinition = MockHelper.CreateEntityCommandDefinition();

                var entityDataReaderMock        = new Mock <EntityDataReader>();
                var entityDataReaderFactoryMock = new Mock <EntityCommand.EntityDataReaderFactory>();

                entityDataReaderFactoryMock.Setup(
                    m => m.CreateEntityDataReader(It.IsAny <EntityCommand>(), It.IsAny <DbDataReader>(), It.IsAny <CommandBehavior>())).
                Returns(entityDataReaderMock.Object);

                var entityCommand = new EntityCommand(entityConnection, entityCommandDefinition, entityDataReaderFactoryMock.Object);

                entityCommand.ExecuteNonQuery();
            }
Example #3
0
            public void Iterates_over_all_results_of_EntityDataReader_without_touching_individual_rows()
            {
                var entityConnection        = MockHelper.CreateEntityConnection();
                var entityCommandDefinition = MockHelper.CreateEntityCommandDefinition();

                var readNextCount = 0;

                var entityDataReaderMock = new Mock <EntityDataReader>();

                entityDataReaderMock.Setup(m => m.NextResult()).Callback(() => readNextCount++).Returns(() => readNextCount < 5);

                var entityDataReaderFactoryMock = new Mock <EntityCommand.EntityDataReaderFactory>();

                entityDataReaderFactoryMock.Setup(
                    m => m.CreateEntityDataReader(It.IsAny <EntityCommand>(), It.IsAny <DbDataReader>(), It.IsAny <CommandBehavior>())).
                Returns(entityDataReaderMock.Object);

                var entityCommand = new EntityCommand(entityConnection, entityCommandDefinition, entityDataReaderFactoryMock.Object);

                entityCommand.ExecuteNonQuery();

                entityDataReaderMock.Verify(m => m.NextResult(), Times.Exactly(5));
            }