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 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 ReportsAsOpenUntilClosed() { var connection = new FakeConnection(new RabbitServer()); Assert.That(connection.IsOpen, Is.True); connection.Close(); Assert.That(connection.IsOpen, Is.False); }
public async Task Lazy_connection_is_async_opened_and_closed_when_necessary() { using (var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { ConnectionString = "Database=FrodoLives" }))) { Assert.Equal(0, connection.CreateCount); var cancellationToken = new CancellationTokenSource().Token; await connection.OpenAsync(cancellationToken); Assert.Equal(1, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); connectionMock.Verify(m => m.OpenAsync(cancellationToken), Times.Once); await connection.OpenAsync(cancellationToken); await connection.OpenAsync(cancellationToken); connectionMock.Verify(m => m.OpenAsync(It.IsAny <CancellationToken>()), Times.Once); connection.Close(); connection.Close(); connectionMock.Verify(m => m.OpenAsync(It.IsAny <CancellationToken>()), Times.Once); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.OpenAsync(It.IsAny <CancellationToken>()), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); await connection.OpenAsync(cancellationToken); connectionMock.Verify(m => m.OpenAsync(cancellationToken), Times.Exactly(2)); connection.Close(); connectionMock.Verify(m => m.OpenAsync(cancellationToken), 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 void Close_TimeoutArguments_ClosesTheConnection() { // Arrange var connection = new FakeConnection(new RabbitServer()); // Act connection.Close(timeout:2); // Assert Assert.That(connection.IsOpen, Is.False); Assert.That(connection.CloseReason, Is.Not.Null); }
public void Abort_NoArguments_AbortsTheConnection() { // Arrange var connection = new FakeConnection(new RabbitServer()); // Act connection.Close(); // Assert Assert.That(connection.IsOpen, Is.False); Assert.That(connection.CloseReason, Is.Not.Null); }
public void Close_TimeoutArguments_ClosesTheConnection() { // Arrange var connection = new FakeConnection(new RabbitServer()); // Act connection.Close(timeout: 2); // Assert Assert.That(connection.IsOpen, Is.False); Assert.That(connection.CloseReason, Is.Not.Null); }
public void Close_AllArguments_ClosesTheConnection() { // Arrange var connection = new FakeConnection(new RabbitServer()); // Act connection.Close(reasonCode: 3, reasonText: "foo", timeout: 4); // Assert Assert.That(connection.IsOpen, Is.False); Assert.That(connection.CloseReason.ReplyCode, Is.EqualTo(3)); Assert.That(connection.CloseReason.ReplyText, Is.EqualTo("foo")); }
public void Close_ReasonArguments_ClosesTheConnection() { // Arrange var connection = new FakeConnection(new RabbitServer()); // Act connection.Close(reasonCode:3,reasonText:"foo"); // Assert Assert.That(connection.IsOpen, Is.False); Assert.That(connection.CloseReason.ReplyCode, Is.EqualTo(3)); Assert.That(connection.CloseReason.ReplyText, Is.EqualTo("foo")); }
public void Close_ClosesAllModels() { // Arrange var connection = new FakeConnection(new RabbitServer()); connection.CreateModel(); // Act connection.Close(); // Assert Assert.IsTrue(connection.Models.All(m => m.IsOpen == false)); Assert.IsTrue(connection.Models.All(m => m.IsClosed == 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 Close_ClosesAllModels() { // Arrange var connection = new FakeConnection(new RabbitServer()); connection.CreateModel(); // Act connection.Close(); // Assert Assert.IsTrue(connection.Models.All(m=>m.IsOpen == false)); Assert.IsTrue(connection.Models.All(m=>m.IsClosed == 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 async Task Lazy_connection_is_async_opened_and_closed_when_necessary() { using (var connection = new FakeConnection( CreateOptions(new FakeOptionsExtension1 { ConnectionString = "Database=FrodoLives" }))) { Assert.Equal(0, connection.CreateCount); var cancellationToken = new CancellationTokenSource().Token; await connection.OpenAsync(cancellationToken); Assert.Equal(1, connection.CreateCount); var connectionMock = Mock.Get(connection.DbConnection); connectionMock.Verify(m => m.OpenAsync(cancellationToken), Times.Once); await connection.OpenAsync(cancellationToken); await connection.OpenAsync(cancellationToken); connectionMock.Verify(m => m.OpenAsync(It.IsAny<CancellationToken>()), Times.Once); connection.Close(); connection.Close(); connectionMock.Verify(m => m.OpenAsync(It.IsAny<CancellationToken>()), Times.Once); connectionMock.Verify(m => m.Close(), Times.Never); connection.Close(); connectionMock.Verify(m => m.OpenAsync(It.IsAny<CancellationToken>()), Times.Once); connectionMock.Verify(m => m.Close(), Times.Once); await connection.OpenAsync(cancellationToken); connectionMock.Verify(m => m.OpenAsync(cancellationToken), Times.Exactly(2)); connection.Close(); connectionMock.Verify(m => m.OpenAsync(cancellationToken), Times.Exactly(2)); connectionMock.Verify(m => m.Close(), Times.Exactly(2)); } }
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( 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 }); }