public void Existing_connection_is_not_disposed_even_after_being_opened_and_closed() { var connectionMock = CreateDbConnectionMock("Database=FrodoLives"); var connection = new FakeConnection(CreateOptions(e => e.Connection = connectionMock.Object)); Assert.Equal(0, connection.CreateCount); Assert.Same(connectionMock.Object, connection.DbConnection); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Never(), new object[] { true }); Assert.Equal(0, connection.CreateCount); Assert.Same(connectionMock.Object, connection.DbConnection); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); connectionMock.Protected().Verify("Dispose", Times.Never(), new object[] { true }); }
public void Lazy_connection_is_recreated_if_used_again_after_being_disposed() { var connection = new FakeConnection(CreateOptions(e => e.ConnectionString = "Database=FrodoLives")); Assert.Equal(0, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); Assert.Equal(1, connection.CreateCount); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Once(), new object[] { true }); Assert.Equal(1, connection.CreateCount); connectionMock = Mock.Get(connection.DbConnection); Assert.Equal(2, connection.CreateCount); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Once(), new object[] { true }); }
public void Lazy_connection_is_not_created_just_so_it_can_be_disposed() { var connection = new FakeConnection(CreateOptions(e => e.ConnectionString = "Database=FrodoLives")); connection.Dispose(); Assert.Equal(0, connection.CreateCount); }
public void Lazy_connection_is_not_created_just_so_it_can_be_disposed() { var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { ConnectionString = "Database=FrodoLives" })); connection.Dispose(); Assert.Equal(0, connection.CreateCount); }
public void Existing_connection_is_not_disposed_even_after_being_opened_and_closed() { var connectionMock = CreateDbConnectionMock("Database=FrodoLives"); var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { Connection = connectionMock.Object })); Assert.Equal(0, connection.CreateCount); Assert.Same(connectionMock.Object, connection.DbConnection); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Never(), true); Assert.Equal(0, connection.CreateCount); Assert.Same(connectionMock.Object, connection.DbConnection); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); connectionMock.Protected().Verify("Dispose", Times.Never(), true); }
public void Lazy_connection_is_recreated_if_used_again_after_being_disposed() { var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { ConnectionString = "Database=FrodoLives" })); Assert.Equal(0, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); Assert.Equal(1, connection.CreateCount); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Once(), true); Assert.Equal(1, connection.CreateCount); connectionMock = Mock.Get(connection.DbConnection); Assert.Equal(2, connection.CreateCount); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Once(), true); }
public void IterationCleanup() { sqlConnection.Dispose(); }
public void Existing_connection_is_not_disposed_even_after_being_opened_and_closed() { var connectionMock = CreateDbConnectionMock("Database=FrodoLives"); var connection = new FakeConnection( CreateConfiguration(e => e.Connection = connectionMock.Object), new ConnectionStringResolver(null)); Assert.Equal(0, connection.CreateCount); Assert.Same(connectionMock.Object, connection.DbConnection); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Never(), new object[] { true }); Assert.Equal(0, connection.CreateCount); Assert.Same(connectionMock.Object, connection.DbConnection); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); connectionMock.Protected().Verify("Dispose", Times.Never(), new object[] { true }); }
public void Lazy_connection_is_not_created_just_so_it_can_be_disposed() { var connection = new FakeConnection( CreateConfiguration(e => e.ConnectionString = "Database=FrodoLives"), new ConnectionStringResolver(null)); connection.Dispose(); Assert.Equal(0, connection.CreateCount); }
public void Lazy_connection_is_recreated_if_used_again_after_being_disposed() { var connection = new FakeConnection( CreateConfiguration(e => e.ConnectionString = "Database=FrodoLives"), new ConnectionStringResolver(null)); Assert.Equal(0, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); Assert.Equal(1, connection.CreateCount); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Once(), new object[] { true }); Assert.Equal(1, connection.CreateCount); connectionMock = Mock.Get(connection.DbConnection); Assert.Equal(2, connection.CreateCount); connection.Open(); connection.Close(); connection.Dispose(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connectionMock.Protected().Verify("Dispose", Times.Once(), new object[] { true }); }