<commit_before>﻿using BeekmanLabs.UnitTesting;
using Common.Logging;
using IntegrationEngine.Api;
using IntegrationEngine.Core.Mail;
using IntegrationEngine.Core.R;
using IntegrationEngine.Core.Storage;
using IntegrationEngine.MessageQueue;
using IntegrationEngine.Scheduler;
using Microsoft.Practices.Unity;
using Moq;
using Nest;
using NUnit.Framework;
using System;
using System.Collections.Generic;

namespace IntegrationEngine.Tests
{
    public class EngineHostConfigurationTest : TestBase<EngineHostConfiguration>
    {
        public IUnityContainer UnityContainer { get; set; }
        public Mock<ILog> MockLog { get; set; }

        [SetUp]
        public void Setup()
        {
            Subject.Container = UnityContainer = new UnityContainer();
            MockLog = new Mock<ILog>();
            Subject.Log = MockLog.Object;
        }

        [Test]
        public void CanLoadConfiguration()
        {
            Subject.LoadConfiguration();

            Assert.IsNotNull(Subject.Configuration);
        }

        [Test]
        public void ShouldSetupLogging()
        {
            Subject.LoadConfiguration();

            Subject.SetupLogging();

            Assert.That(Subject.Log.GetType(), Is.EqualTo(typeof(Common.Logging.NLog.NLogLogger)));
        }

        [Test]
        public void ShouldSetupDatabaseContext()
        {
            Subject.LoadConfiguration();

            Subject.SetupDatabaseContext();

            Subject.Container.Resolve<IntegrationEngineContext>();
        }

        [Test]
        public void ShouldSetupDatabaseRepository()
        {
            Subject.LoadConfiguration();
            var mockIntegrationEngineContext = new Mock<IntegrationEngineContext>();

            Subject.SetupDatabaseRepository(mockIntegrationEngineContext.Object);

            Subject.Container.Resolve<IDatabaseRepository>();
        }

        [Test]
        public void ShouldSetupMailClient()
        {
            Subject.LoadConfiguration();

            Subject.SetupMailClient();

            Subject.Container.Resolve<IMailClient>();
        }

        [Test]
        public void ShouldSetupElasticClient()
        {
            Subject.LoadConfiguration();

            Subject.SetupElasticClient();

            Subject.Container.Resolve<IElasticClient>();
        }

        [Test]
        public void ShouldSetupElasticsearchRepository()
        {
            Subject.LoadConfiguration();
            var mockElasticClient = new Mock<IElasticClient>();

            Subject.SetupElasticsearchRepository(mockElasticClient.Object);

            Subject.Container.Resolve<IElasticsearchRepository>();
        }

        [Test]
        public void ShouldSetupMessageQueueListener()
        {
            Subject.LoadConfiguration();
            var mockMailClient = new Mock<IMailClient>();
            var mockElasticClient = new Mock<IElasticClient>();
            var mockIntegrationEngineContext = new Mock<IntegrationEngineContext>();

            Subject.SetupMessageQueueListener(mockMailClient.Object, mockElasticClient.Object, mockIntegrationEngineContext.Object);

            Subject.Container.Resolve<IMessageQueueListener>();
        }

        [Test]
        public void ShouldSetupMessageQueueClient()
        {
            Subject.LoadConfiguration();

            Subject.SetupMessageQueueClient();

            Subject.Container.Resolve<IMessageQueueClient>();
        }

        [Test]
        public void ShouldSetupEngineScheduler()
        {
            Subject.IntegrationJobTypes = new List<Type>();
            Subject.LoadConfiguration();
            var mockElasticsearchRespository= new Mock<IElasticsearchRepository>();
            var mockMessageQueueClient = new Mock<IMessageQueueClient>();

            Subject.SetupEngineScheduler(mockMessageQueueClient.Object, mockElasticsearchRespository.Object);

            Subject.Container.Resolve<IEngineScheduler>();
        }

        [Test]
        public void ShouldSetupRScriptRunner()
        {
            Subject.SetupRScriptRunner();

            Subject.Container.Resolve<RScriptRunner>();
        }

        [Test]
        public void ShouldShutdownSchedulerAndDisposeOfMessageQueueListener()
        {
            var mockEngineScheduler = new Mock<IEngineScheduler>();
            mockEngineScheduler.Setup(x => x.Shutdown());
            UnityContainer.RegisterInstance<IEngineScheduler>(mockEngineScheduler.Object);
            var mockMessageQueueListener = new Mock<IMessageQueueListener>();
            mockMessageQueueListener.Setup(x => x.Dispose());
            UnityContainer.RegisterInstance<IMessageQueueListener>(mockMessageQueueListener.Object);

            Subject.Dispose();

            mockEngineScheduler.Verify(x => x.Shutdown(), Times.Once);
            mockMessageQueueListener.Verify(x => x.Dispose(), Times.Once);
        }
    }
}
<commit_msg>Fix test<commit_after>﻿using BeekmanLabs.UnitTesting;
using Common.Logging;
using IntegrationEngine.Api;
using IntegrationEngine.Core.Mail;
using IntegrationEngine.Core.R;
using IntegrationEngine.Core.Storage;
using IntegrationEngine.MessageQueue;
using IntegrationEngine.Scheduler;
using Microsoft.Practices.Unity;
using Moq;
using Nest;
using NUnit.Framework;
using System;
using System.Collections.Generic;

namespace IntegrationEngine.Tests
{
    public class EngineHostConfigurationTest : TestBase<EngineHostConfiguration>
    {
        public IUnityContainer UnityContainer { get; set; }
        public Mock<ILog> MockLog { get; set; }

        [SetUp]
        public void Setup()
        {
            Subject.Container = UnityContainer = new UnityContainer();
            MockLog = new Mock<ILog>();
            Subject.Log = MockLog.Object;
        }

        [Test]
        public void CanLoadConfiguration()
        {
            Subject.LoadConfiguration();

            Assert.IsNotNull(Subject.Configuration);
        }

        [Test]
        public void ShouldSetupLogging()
        {
            Subject.LoadConfiguration();

            Subject.SetupLogging();

            Assert.That(Subject.Log.GetType(), Is.EqualTo(typeof(Common.Logging.NLog.NLogLogger)));
        }

        [Test]
        public void ShouldSetupDatabaseContext()
        {
            Subject.LoadConfiguration();

            Subject.SetupDatabaseContext();

            Subject.Container.Resolve<IntegrationEngineContext>();
        }

        [Test]
        public void ShouldSetupDatabaseRepository()
        {
            Subject.LoadConfiguration();
            var mockIntegrationEngineContext = new Mock<IntegrationEngineContext>();

            Subject.SetupDatabaseRepository(mockIntegrationEngineContext.Object);

            Subject.Container.Resolve<IDatabaseRepository>();
        }

        [Test]
        public void ShouldSetupMailClient()
        {
            Subject.LoadConfiguration();

            Subject.SetupMailClient();

            Subject.Container.Resolve<IMailClient>();
        }

        [Test]
        public void ShouldSetupElasticClient()
        {
            Subject.LoadConfiguration();

            Subject.SetupElasticClient();

            Subject.Container.Resolve<IElasticClient>();
        }

        [Test]
        public void ShouldSetupElasticsearchRepository()
        {
            Subject.LoadConfiguration();
            var mockElasticClient = new Mock<IElasticClient>();

            Subject.SetupElasticsearchRepository(mockElasticClient.Object);

            Subject.Container.Resolve<IElasticsearchRepository>();
        }

        [Test]
        public void ShouldSetupMessageQueueListener()
        {
            Subject.LoadConfiguration();
            var mockMailClient = new Mock<IMailClient>();
            var mockElasticClient = new Mock<IElasticClient>();
            var mockIntegrationEngineContext = new Mock<IntegrationEngineContext>();

            Subject.SetupMessageQueueListener(mockMailClient.Object, mockElasticClient.Object, mockIntegrationEngineContext.Object);

            Subject.Container.Resolve<IMessageQueueListener>();
        }

        [Test]
        public void ShouldSetupMessageQueueClient()
        {
            Subject.LoadConfiguration();

            Subject.SetupMessageQueueClient();

            Subject.Container.Resolve<IMessageQueueClient>();
        }

        [Test]
        public void ShouldSetupEngineScheduler()
        {
            Subject.IntegrationJobTypes = new List<Type>();
            Subject.LoadConfiguration();
            var mockElasticsearchRespository= new Mock<IElasticsearchRepository>();
            var mockMessageQueueClient = new Mock<IMessageQueueClient>();

            Subject.SetupEngineScheduler(mockMessageQueueClient.Object, mockElasticsearchRespository.Object);

            Subject.Container.Resolve<IEngineScheduler>();
        }

        [Test]
        public void ShouldSetupRScriptRunner()
        {
            Subject.SetupRScriptRunner();

            Subject.Container.Resolve<RScriptRunner>();
        }

        [Test]
        public void ShouldShutdownSchedulerAndDisposeOfMessageQueueListener()
        {
            var mockWebApiApplication = new Mock<IWebApiApplication>();
            mockWebApiApplication.Setup(x => x.Stop());
            UnityContainer.RegisterInstance<IWebApiApplication>(mockWebApiApplication.Object);
            var mockEngineScheduler = new Mock<IEngineScheduler>();
            mockEngineScheduler.Setup(x => x.Shutdown());
            UnityContainer.RegisterInstance<IEngineScheduler>(mockEngineScheduler.Object);
            var mockMessageQueueListener = new Mock<IMessageQueueListener>();
            mockMessageQueueListener.Setup(x => x.Dispose());
            UnityContainer.RegisterInstance<IMessageQueueListener>(mockMessageQueueListener.Object);

            Subject.Dispose();

            mockWebApiApplication.Verify(x => x.Stop(), Times.Once);
            mockEngineScheduler.Verify(x => x.Shutdown(), Times.Once);
            mockMessageQueueListener.Verify(x => x.Dispose(), Times.Once);
        }
    }
}

{'fraction_non_alphanumeric': 0.09031556039173014, 'fraction_numerical': 0.0, 'mean_word_length': 2.459958932238193, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 63, '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': '411855', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2364, 'n_words': 395}