Exemplo n.º 1
0
        private IHealthCheckResult BuildHealthCheckAndSetExpectations(bool categoryFound, bool[] counterExistence)
        {
            IPerformanceCounterInquisitor inquisitor = m_MockRepository.StrictMock <IPerformanceCounterInquisitor>();
            IHealthCheck healthCheck = PerformanceCounterRegistrationHealthCheck.Create(inquisitor);

            using (m_MockRepository.Record())
            {
                Expect.Call(inquisitor.CheckCategoryExists(PerformanceCounterRegistrar.CategoryName)).Return(
                    categoryFound);

                Debug.Assert(counterExistence.Length == m_PerformanceCounterDefinitions.Count);

                if (categoryFound)
                {
                    for (int index = 0; index < m_PerformanceCounterDefinitions.Count; index++)
                    {
                        Expect.Call(inquisitor.CheckCounterExists(m_PerformanceCounterDefinitions[index].CounterName)).
                        Return(counterExistence[index]);
                    }
                }

                m_MockRepository.ReplayAll();
            }

            return(healthCheck.Execute());
        }
Exemplo n.º 2
0
        public void ExceptionThrownInHealthCheckImplementationIsReportedAsFailedHealthCheckResult()
        {
            IHealthCheck         firstHealthCheck     = m_Repository.StrictMock <IHealthCheck>();
            HealthCheckException healthCheckException = m_Repository.StrictMock <HealthCheckException>();

            using (m_Repository.Record())
            {
                Expect.Call(firstHealthCheck.Execute()).Throw(healthCheckException);
                Expect.Call(healthCheckException.Message).Return("Sample Exception");
                m_Repository.ReplayAll();

                HealthCheckResultCollection resultCollection =
                    HealthCheckRunner.RunHealthChecks(new HealthChecklistCollection(new[] { firstHealthCheck }));

                Assert.AreEqual(1, resultCollection.Count);

                IHealthCheckResult result = resultCollection[0];

                Assert.IsFalse(result.Passed);
                StringAssert.StartsWith(result.Message,
                                        "An exception was thrown during the execution of the Health Check");
                StringAssert.Contains(result.Message, "Sample Exception");

                m_Repository.VerifyAll();
            }
        }
Exemplo n.º 3
0
        public void NoResultsReturnedFromSproc()
        {
            IHealthCheck       healthCheck = GetHealthCheck(null, false);
            IHealthCheckResult result      = healthCheck.Execute();

            Assert.IsFalse(result.Passed);
            StringAssert.Contains(result.Message, "The IsHealthy_ObjectExistenceCheck sproc produced no result row.");
        }
Exemplo n.º 4
0
        public void UserIsNotFoundInRole()
        {
            IHealthCheck       healthCheck = BuildHealthCheckAndSetExpectations(false, true);
            IHealthCheckResult result      = healthCheck.Execute();

            Assert.IsFalse(result.Passed);
            StringAssert.Contains(result.Message, "not found in the necessary role.");

            m_MockRepository.VerifyAll();
        }
Exemplo n.º 5
0
        public void NoRowsReturnedFromRoleMemberQuery()
        {
            IHealthCheck       healthCheck = BuildHealthCheckAndSetExpectations(true, false);
            IHealthCheckResult result      = healthCheck.Execute();

            Assert.IsFalse(result.Passed);
            StringAssert.Contains(result.Message,
                                  "The call to check if the user was in the necessary role returned no row.");

            m_MockRepository.VerifyAll();
        }
Exemplo n.º 6
0
        private IHealthCheckResult RunHealthCheck(bool isRunning)
        {
            IServiceStateInquisitor serviceStateInquisitor = m_MockRepository.StrictMock <IServiceStateInquisitor>();
            IHealthCheck            healthCheck            = FeatureStoreServiceStateHealthCheck.Create(serviceStateInquisitor);

            using (m_MockRepository.Record())
            {
                Expect.Call(serviceStateInquisitor.ServiceIsRunning()).Return(isRunning);
                m_MockRepository.ReplayAll();
            }

            return(healthCheck.Execute());
        }
Exemplo n.º 7
0
        public void ServiceIsNotInstalled()
        {
            IServiceStateInquisitor serviceStateInquisitor = m_MockRepository.StrictMock <IServiceStateInquisitor>();
            IHealthCheck            healthCheck            = FeatureStoreServiceStateHealthCheck.Create(serviceStateInquisitor);

            using (m_MockRepository.Record())
            {
                Expect.Call(serviceStateInquisitor.ServiceIsRunning()).Throw(new ServiceNotInstalledException());
                m_MockRepository.ReplayAll();
            }

            IHealthCheckResult result = healthCheck.Execute();

            Assert.IsFalse(result.Passed);
            StringAssert.Contains(result.Message, "The Feature Store service is not installed.");
        }
Exemplo n.º 8
0
        private IHealthCheckResult GetHealthCheckResult(string configResourceName)
        {
            ILog4NetConfigurationResolver resolver = m_MockRepository.StrictMock <ILog4NetConfigurationResolver>();
            Assembly      assembly = Assembly.GetExecutingAssembly();
            Stream        stream   = assembly.GetManifestResourceStream(configResourceName);
            XPathDocument document = new XPathDocument(stream);

            using (m_MockRepository.Record())
            {
                Expect.Call(resolver.LoadConfiguration()).Return(document);
                m_MockRepository.ReplayAll();
            }

            IHealthCheck healthCheck = Log4NetConfigurationHealthCheck.Create(resolver);

            return(healthCheck.Execute());
        }
Exemplo n.º 9
0
        /// <summary>
        ///   Runs the health checks.
        /// </summary>
        /// <param name = "healthCheck">The health check.</param>
        /// <returns>A <see cref = "IHealthCheckResult" /> containing the results of the given <see cref = "IHealthCheck" /> implementation.</returns>
        private IHealthCheckResult RunHealthChecks(IHealthCheck healthCheck)
        {
            IHealthCheckResult result;

            try
            {
                result = healthCheck.Execute();
            }
            catch (Exception e)
            {
                m_Log.Warn(e);
                result = HealthCheckResult.Create(
                    false,
                    string.Format(CultureInfo.CurrentUICulture, ExceptionMessageResources.EXCEPTION_THROWN_IN_HEALTH_CHECK, e.Message));
            }

            return(result);
        }
        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();
            }
        }
Exemplo n.º 11
0
        public void HealthCheckRunnerExecutesListOfHealthChecksAndAllSucceed()
        {
            IHealthCheck firstHealthCheck  = m_Repository.StrictMock <IHealthCheck>();
            IHealthCheck secondHealthCheck = m_Repository.StrictMock <IHealthCheck>();
            IHealthCheck thirdHealthCheck  = m_Repository.StrictMock <IHealthCheck>();

            IHealthCheckResult firstHealthCheckResult  = m_Repository.StrictMock <IHealthCheckResult>();
            IHealthCheckResult secondHealthCheckResult = m_Repository.StrictMock <IHealthCheckResult>();
            IHealthCheckResult thirdHealthCheckResult  = m_Repository.StrictMock <IHealthCheckResult>();

            using (m_Repository.Record())
            {
                Expect.Call(firstHealthCheck.Execute()).Return(firstHealthCheckResult);
                Expect.Call(secondHealthCheck.Execute()).Return(secondHealthCheckResult);
                Expect.Call(thirdHealthCheck.Execute()).Return(thirdHealthCheckResult);

                Expect.Call(firstHealthCheckResult.Passed).Return(true);
                Expect.Call(firstHealthCheckResult.Message).Return("The Health Check was successful.");

                Expect.Call(secondHealthCheckResult.Passed).Return(true);
                Expect.Call(secondHealthCheckResult.Message).Return("The Health Check was successful.");

                Expect.Call(thirdHealthCheckResult.Passed).Return(true);
                Expect.Call(thirdHealthCheckResult.Message).Return("The Health Check was successful.");

                m_Repository.ReplayAll();

                HealthCheckResultCollection resultCollection =
                    HealthCheckRunner.RunHealthChecks(
                        new HealthChecklistCollection(new[] { firstHealthCheck, secondHealthCheck, thirdHealthCheck }));

                Assert.AreEqual(3, resultCollection.Count);
                foreach (IHealthCheckResult healthCheckResult in resultCollection)
                {
                    Assert.IsTrue(healthCheckResult.Passed);
                    StringAssert.Contains(healthCheckResult.Message, "success");
                }

                m_Repository.VerifyAll();
            }
        }
Exemplo n.º 12
0
        public void OneObjectDoesNotExist()
        {
            var results = new[]
            {
                new Tuple <bool, string>(true, "Role1Exists"),
                new Tuple <bool, string>(true, "Role2Exists"),
                new Tuple <bool, string>(false, "Table1Exists"),
                new Tuple <bool, string>(true, "Table2Exists"),
                new Tuple <bool, string>(true, "Table3Exists"),
                new Tuple <bool, string>(true, "Sproc1Exists"),
                new Tuple <bool, string>(true, "Sproc2Exists")
            };

            IHealthCheck healthCheck = GetHealthCheck(results, true);

            IHealthCheckResult result = healthCheck.Execute();

            Assert.IsFalse(result.Passed);

            StringAssert.Contains(result.Message, "Failed to find 'Table1Exists' object in database.");

            m_MockRepository.VerifyAll();
        }
Exemplo n.º 13
0
        public void AllObjectsExist()
        {
            var results = new[]
            {
                new Tuple <bool, string>(true, "Role1Exists"),
                new Tuple <bool, string>(true, "Role2Exists"),
                new Tuple <bool, string>(true, "Table1Exists"),
                new Tuple <bool, string>(true, "Table2Exists"),
                new Tuple <bool, string>(true, "Table3Exists"),
                new Tuple <bool, string>(true, "Sproc1Exists"),
                new Tuple <bool, string>(true, "Sproc2Exists")
            };

            IHealthCheck healthCheck = GetHealthCheck(results, true);

            IHealthCheckResult result = healthCheck.Execute();

            Assert.IsTrue(result.Passed);

            Console.WriteLine(result.Message);

            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();
        }
Exemplo n.º 15
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();
        }