Exemple #1
0
        private IHealthCheck GetHealthCheck(Tuple <bool, string>[] results, bool readReturnValue)
        {
            DbConnection connection   = m_MockRepository.StrictMock <DbConnection>();
            DbCommand    sprocCommand = m_MockRepository.StrictMock <DbCommand>();
            DbDataReader dataReader   = m_MockRepository.StrictMock <DbDataReader>();

            IHealthCheck healthCheck = SqlServerStorageContainerObjectExistenceHealthCheck.Create(connection);

            using (m_MockRepository.Record())
            {
                Expect.Call(connection.CreateCommand()).Return(sprocCommand);
                Expect.Call(sprocCommand.ExecuteReader()).Return(dataReader);
                Expect.Call(() => { sprocCommand.CommandText = "IsHealthy_ObjectExistenceCheck"; });
                Expect.Call(() => { sprocCommand.CommandType = CommandType.StoredProcedure; });
                Expect.Call(dataReader.Read()).Return(readReturnValue);
                Expect.Call(((IDisposable)dataReader).Dispose);

                if (readReturnValue)
                {
                    int fieldCount = results.Length;
                    Expect.Call(dataReader.FieldCount).Return(fieldCount);

                    for (int index = 0; index < fieldCount; index++)
                    {
                        Expect.Call(dataReader.GetBoolean(index)).Return(results[index].Item1);
                        Expect.Call(dataReader.GetName(index)).Return(results[index].Item2);
                    }
                }
            }

            m_MockRepository.ReplayAll();
            return(healthCheck);
        }
Exemple #2
0
        public void InvalidOperationExceptionIsHandledCorrectly()
        {
            const string exceptionMessage       = "An invalid operation was attempted.";
            DbConnection connection             = m_MockRepository.StrictMock <DbConnection>();
            IHealthCheck healthCheck            = SqlServerStorageContainerObjectExistenceHealthCheck.Create(connection);
            InvalidOperationException exception = m_MockRepository.StrictMock <InvalidOperationException>();

            using (m_MockRepository.Record())
            {
                Expect.Call(connection.CreateCommand()).Throw(exception);
                Expect.Call(exception.Message).Return(exceptionMessage);
                Expect.Call(connection.ConnectionString).Return("SampleConnectionString");

                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();
        }