public void SqlServerStorageContainerConnectivityHealthCheckPasses() { DbConnection connection = m_MockRepository.StrictMock <DbConnection>(); IHealthCheck healthCheck = SqlServerStorageContainerConnectivityHealthCheck.Create(connection); using (m_MockRepository.Record()) { Expect.Call(connection.Open); Expect.Call(connection.ConnectionString).Return("SampleConnectionString"); m_MockRepository.ReplayAll(); IHealthCheckResult result = healthCheck.Execute(); Assert.IsTrue(result.Passed); StringAssert.Contains(result.Message, "Connection to SqlServer database succeeded"); StringAssert.Contains(result.Message, "SampleConnectionString"); m_MockRepository.VerifyAll(); } }
private void AssertExceptionHandled <T>(string exceptionMessage) where T : Exception { DbConnection connection = m_MockRepository.StrictMock <DbConnection>(); IHealthCheck healthCheck = SqlServerStorageContainerConnectivityHealthCheck.Create(connection); T exception = m_MockRepository.StrictMock <T>(); using (m_MockRepository.Record()) { Expect.Call(connection.Open).Throw(exception); Expect.Call(connection.ConnectionString).Return("SampleConnectionString"); Expect.Call(exception.Message).Return(exceptionMessage); m_MockRepository.ReplayAll(); } IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "An exception occured opening the connection to the database:"); StringAssert.Contains(result.Message, exceptionMessage); m_MockRepository.VerifyAll(); }