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 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 Existing_connection_can_start_in_opened_state() { var connectionMock = CreateDbConnectionMock("Database=FrodoLives"); connectionMock.Setup(m => m.State).Returns(ConnectionState.Open); using (var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { Connection = connectionMock.Object }))) { Assert.Equal(0, connection.CreateCount); connection.Open(); Assert.Equal(0, connection.CreateCount); connectionMock.Verify(m => m.Open(), Times.Never); connection.Open(); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Never); connection.Close(); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Never); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Never); connectionMock.Verify(m => m.Close(), Times.Never); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Never); connectionMock.Verify(m => m.Close(), Times.Never); } }
public void Existing_connection_is_opened_and_closed_when_necessary() { var connectionMock = CreateDbConnectionMock("Database=FrodoLives"); connectionMock.Setup(m => m.State).Returns(ConnectionState.Closed); using (var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { Connection = connectionMock.Object }))) { Assert.Equal(0, connection.CreateCount); connection.Open(); Assert.Equal(0, connection.CreateCount); connectionMock.Verify(m => m.Open(), Times.Once); connection.Open(); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Once); connection.Close(); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); } }
public void Existing_connection_can_start_in_opened_state() { var connectionMock = CreateDbConnectionMock("Database=FrodoLives"); connectionMock.Setup(m => m.State).Returns(ConnectionState.Open); using (var connection = new FakeConnection( CreateConfiguration(e => e.Connection = connectionMock.Object), new ConnectionStringResolver(null))) { Assert.Equal(0, connection.CreateCount); connection.Open(); Assert.Equal(0, connection.CreateCount); connectionMock.Verify(m => m.Open(), Times.Never); connection.Open(); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Never); connection.Close(); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Never); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Never); connectionMock.Verify(m => m.Close(), Times.Never); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Never); connectionMock.Verify(m => m.Close(), Times.Never); } }
public void Lazy_connection_is_opened_and_closed_when_necessary() { using (var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { ConnectionString = "Database=FrodoLives" }))) { Assert.Equal(0, connection.CreateCount); connection.Open(); Assert.Equal(1, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); connectionMock.Verify(m => m.Open(), Times.Once); connection.Open(); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Once); connection.Close(); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); } }
public void Lazy_connection_is_opened_and_closed_when_necessary() { using (var connection = new FakeConnection( CreateConfiguration( e => e.ConnectionString = "Database=FrodoLives"), new ConnectionStringResolver(null))) { Assert.Equal(0, connection.CreateCount); connection.Open(); Assert.Equal(1, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); connectionMock.Verify(m => m.Open(), Times.Once); connection.Open(); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Once); connection.Close(); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); connection.Open(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connection.Close(); connectionMock.Verify(m => m.Open(), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); } }
public QueryTypedObjectTests() { Connection = new FakeConnection(); Connection.Open(); }
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 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_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 }); }