<commit_before>using System;
using System.Diagnostics.CodeAnalysis;
using HealthCheck;
using HealthCheck.Framework;
using Moq;
using Xunit;

namespace UnitTests
{
    [SuppressMessage(
         "StyleCop.CSharp.DocumentationRules",
         "SA1600:ElementsMustBeDocumented",
         Justification = "Test Suites do not need XML Documentation.")]
    public class HealthCheckJobTests
    {
        [Fact]
        public void Execute_Should_CallListernerAfterExecution()
        {
            // Arrange
            var executed = false;
            var mockPlugin = new Mock<IHealthCheckPlugin>();

            var mockStatus = new Mock<IHealthStatus>();
            mockStatus.SetupGet(s => s.Status).Returns(CheckResult.Success);
            mockPlugin.Setup(p => p.Execute()).Returns(mockStatus.Object);

            var job = new HealthCheckJob
            {
                Plugin = mockPlugin.Object
            };

            var mockListener = new Mock<IStatusListener>();
            mockListener.Setup(l => l.Process(It.IsAny<IHealthStatus>())).Callback(() =>
            {
                executed = true;
            });

            job.Listeners.Add(mockListener.Object);

            // Act
            job.Execute(null);

            // Assert
            Assert.True(executed);
        }

        [Fact]
        public void Execute_Should_ExecuteJob()
        {
            // Arrange
            var executed = false;
            var mock = new Mock<IHealthCheckPlugin>();
            mock.Setup(p => p.Execute()).Callback(() =>
            {
                executed = true;
            });

            var job = new HealthCheckJob
            {
                Plugin = mock.Object
            };

            // Act
            job.Execute(null);

            // Assert
            Assert.True(executed);
        }

        [Fact]
        public void Execute_Should_HandleExceptions()
        {
            // Arrange
            var mockPlugin = new Mock<IHealthCheckPlugin>();
            mockPlugin.Setup(p => p.Execute()).Throws(new Exception("BOOM!"));
            mockPlugin.SetupProperty(p => p.PluginStatus);

            var job = new HealthCheckJob
            {
                Plugin = mockPlugin.Object
            };

            // Act
            job.Execute(null);

            // Assert
            Assert.Equal(PluginStatus.TaskExecutionFailure, job.Plugin.PluginStatus);
        }

        [Fact]
        public void NotifyListener_Should_CallListener_When_ThreshholdIsOverThreshold()
        {
            // Arrange
            var executed = false;

            var mockPlugin = new Mock<IHealthCheckPlugin>();
<commit_msg>Added a unit test to make sure HealthChecks do not execute during a quite period.<commit_after>using System;
using System.Diagnostics.CodeAnalysis;
using HealthCheck;
using HealthCheck.Framework;
using Moq;
using Quartz.Impl.Calendar;
using Xunit;

namespace UnitTests
{
    [SuppressMessage(
         "StyleCop.CSharp.DocumentationRules",
         "SA1600:ElementsMustBeDocumented",
         Justification = "Test Suites do not need XML Documentation.")]
    public class HealthCheckJobTests
    {
        [Fact]
        public void Execute_Should_CallListernerAfterExecution()
        {
            // Arrange
            var executed = false;
            var mockPlugin = new Mock<IHealthCheckPlugin>();

            var mockStatus = new Mock<IHealthStatus>();
            mockStatus.SetupGet(s => s.Status).Returns(CheckResult.Success);
            mockPlugin.Setup(p => p.Execute()).Returns(mockStatus.Object);

            var job = new HealthCheckJob
            {
                Plugin = mockPlugin.Object
            };

            var mockListener = new Mock<IStatusListener>();
            mockListener.Setup(l => l.Process(It.IsAny<IHealthStatus>())).Callback(() =>
            {
                executed = true;
            });

            job.Listeners.Add(mockListener.Object);

            // Act
            job.Execute(null);

            // Assert
            Assert.True(executed);
        }

        [Fact]
        public void Execute_Should_ExecuteJob()
        {
            // Arrange
            var executed = false;
            var mock = new Mock<IHealthCheckPlugin>();
            mock.Setup(p => p.Execute()).Callback(() =>
            {
                executed = true;
            });

            var job = new HealthCheckJob
            {
                Plugin = mock.Object
            };

            // Act
            job.Execute(null);

            // Assert
            Assert.True(executed);
        }

        [Fact]
        public void Execute_Should_HandleExceptions()
        {
            // Arrange
            var mockPlugin = new Mock<IHealthCheckPlugin>();
            mockPlugin.Setup(p => p.Execute()).Throws(new Exception("BOOM!"));
            mockPlugin.SetupProperty(p => p.PluginStatus);

            var job = new HealthCheckJob
            {
                Plugin = mockPlugin.Object
            };

            // Act
            job.Execute(null);

            // Assert
            Assert.Equal(PluginStatus.TaskExecutionFailure, job.Plugin.PluginStatus);
        }

        [Fact]
        public void Execute_Should_NotExecuteJob_When_InQuietPeriod()
        {
            // Arrange
            var today = DateTime.Now;
            var startTime = today.AddMinutes(-15);
            var endTime = today.AddMinutes(15);
            var calendar = new DailyCalendar(startTime, endTime); // 6:00 AM until 6:59 AM, every day

            var executed = false;
            var mock = new Mock<IHealthCheckPlugin>();
            _ = mock.Setup(p => p.Execute()).Callback(() => executed = true);

            var job = new HealthCheckJob
            {
                Plugin = mock.Object
            };

            // Act
            job.QuietPeriods.AddCalendar(calendar);
            job.Execute(null);

            // Assert
            Assert.False(executed);
        }

        [Fact]
        public void NotifyListener_Should_CallListener_When_ThreshholdIsOverThreshold()
        {
            // Arrange
            var executed = false;

            var mockPlugin = new Mock<IHealthCheckPlugin>();

{'fraction_non_alphanumeric': 0.09724447292534444, 'fraction_numerical': 0.0028836911246395386, 'mean_word_length': 1.5607054963084495, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2740492', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1532, 'n_words': 324}