예제 #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.NextResultAsync(It.IsAny <CancellationToken>())).Callback(() => readNextCount++)
                .Returns(() => Task.FromResult(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.ExecuteNonQueryAsync().Result;

                Assert.Equal(10, result);
            }
예제 #2
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.NextResultAsync(It.IsAny <CancellationToken>())).Callback(
                    (CancellationToken ct) => readNextCount++).Returns(() => Task.FromResult(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,
                    new DbInterceptionContext(), entityDataReaderFactoryMock.Object);

                entityCommand.ExecuteNonQueryAsync().Wait();

                entityDataReaderMock.Verify(m => m.NextResultAsync(It.IsAny <CancellationToken>()), Times.Exactly(5));
            }
예제 #3
0
            public void ExecuteNonQueryAsync_throws_OperationCanceledException_before_executing_command_if_task_is_cancelled()
            {
                var entityCommand = new EntityCommand();

                Assert.Throws <OperationCanceledException>(
                    () => entityCommand
                    .ExecuteNonQueryAsync(new CancellationToken(canceled: true))
                    .GetAwaiter().GetResult());
            }