コード例 #1
0
        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 });
        }
コード例 #2
0
        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 });
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 public void IterationCleanup()
 {
     sqlConnection.Dispose();
 }
コード例 #8
0
        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 });
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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 });
        }