<commit_before>using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using Akka.Actor;
using Akka.DI.Core;
using Akka.DI.Unity;
using GridDomain.Common;
using GridDomain.CQRS;
using GridDomain.CQRS.Messaging.MessageRouting;
using GridDomain.EventSourcing.Sagas;
using GridDomain.Logging;
using GridDomain.Node;
using GridDomain.Node.Actors;
using GridDomain.Node.Configuration.Akka;
using GridDomain.Node.Configuration.Composition;
using GridDomain.Node.Configuration.Persistence;
using GridDomain.Scheduling.Akka.Messages;
using GridDomain.Scheduling.Integration;
using GridDomain.Scheduling.Quartz.Logging;
using GridDomain.Tests.Acceptance.Scheduling.TestHelpers;
using GridDomain.Tests.Framework;
using GridDomain.Tests.Framework.Configuration;
using Microsoft.Practices.Unity;
using Moq;
using NUnit.Framework;
using Wire;
using IScheduler = Quartz.IScheduler;

namespace GridDomain.Tests.Acceptance.Scheduling
{
    [TestFixture]
    public class Spec : NodeCommandsTest
    {
        private const string Name = "test";
        private const string Group = "test";
        private IActorRef _scheduler;
        private IScheduler _quartzScheduler;
        private IUnityContainer _container;

        public Spec() : base(new AutoTestAkkaConfiguration().ToStandAloneSystemConfig())
        {

        }

        protected override GridDomainNode CreateGridDomainNode(AkkaConfiguration akkaConf, IDbConfiguration dbConfig)
        {
            var system = ActorSystemFactory.CreateActorSystem(akkaConf);
            _container = Register(system);
            system.AddDependencyResolver(new UnityDependencyResolver(_container, system));
            var router = new TestRouter();
            return new GridDomainNode(_container, router, TransportMode.Standalone, system);
        }

        private IUnityContainer Register(ActorSystem system)
        {
            var container = Container.CreateChildScope();
            CompositionRoot.Init(container, system, new AutoTestLocalDbConfiguration(), TransportMode.Standalone);
            container.RegisterInstance(new Mock<ILoggingSchedulerListener>().Object);

            container.RegisterType<AggregateActor<TestAggregate>>();
            container.RegisterType<AggregateHubActor<TestAggregate>>();
            container.RegisterType<ICommandAggregateLocator<TestAggregate>, TestAggregateCommandHandler>();
            container.RegisterType<IAggregateCommandsHandler<TestAggregate>, TestAggregateCommandHandler>();
            container.RegisterType<ISagaFactory<TestSaga, TestSagaState>, TestSagaFactory>();
            container.RegisterType<ISagaFactory<TestSaga, TestSagaStartMessage>, TestSagaFactory>();
            container.RegisterType<IEmptySagaFactory<TestSaga>, TestSagaFactory>();

            return container;
        }

        [SetUp]
        public void SetUp()
        {
            DateTimeStrategyHolder.Current = new DefaultDateTimeStrategy();
            LogManager.GetLogger().Error(new InvalidOperationException("ohshitwaddap"), "message {placeholder}", 18723);
            CreateScheduler();
            _scheduler = GridNode.System.ActorOf(GridNode.System.DI().Props<SchedulingActor>());
            _quartzScheduler.Clear();
        }

        [TearDown]
        public void TearDown()
        {
            ResultHolder.Clear();
            _quartzScheduler.Shutdown(true);
        }

        private void CreateScheduler()
        {
            _quartzScheduler = _container.Resolve<IScheduler>();
        }

      

        [Test]
        public void When_domain_event_that_should_start_a_saga_is_scheduled_Then_saga_gets_created()
        {
            var sagaId = Guid.NewGuid();
            var testEvent = new TestSagaStartMessage(sagaId, DateTimeFacade.UtcNow, sagaId);
            _scheduler.Ask<Scheduled>(new ScheduleEvent(testEvent, new ScheduleKey(Guid.Empty, Name, Group), DateTimeFacade.UtcNow.AddSeconds(0.3)));
            WaitFor<SagaCreatedEvent<TestSaga.TestStates>>();
            var sagaState = LoadSagaState<TestSaga, TestSagaState, TestSagaStartMessage>(sagaId);
            Assert.True(sagaState.MachineState == TestSaga.TestStates.GotStartEvent);
        }

        [Test]
        public void When_domain_event_for_a_started_saga_is_scheduled_Then_saga_receives_it()
        {
            var sagaId = Guid.NewGuid();
            var startEvent = new TestSagaStartMessage(sagaId, DateTimeFacade.UtcNow, sagaId);
            _scheduler.Ask<Scheduled>(new ScheduleEvent(startEvent, new ScheduleKey(Guid.Empty, Name, Group), DateTimeFacade.UtcNow.AddSeconds(0.3)));
            WaitFor<SagaCreatedEvent<TestSaga.TestStates>>();

            var secondEvent = new TestEvent(sagaId);
            _scheduler.Ask<Scheduled>(new ScheduleEvent(secondEvent, new ScheduleKey(Guid.Empty, Name, Group), DateTimeFacade.UtcNow.AddSeconds(0.3)));
            WaitFor<SagaTransitionEvent<TestSaga.TestStates, TestSaga.Transitions>>();
            var sagaState = LoadSagaState<TestSaga, TestSagaState, TestSagaStartMessage>(sagaId);<commit_msg>removed log test from scheduler spec<commit_after>using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using Akka.Actor;
using Akka.DI.Core;
using Akka.DI.Unity;
using GridDomain.Common;
using GridDomain.CQRS;
using GridDomain.CQRS.Messaging.MessageRouting;
using GridDomain.EventSourcing.Sagas;
using GridDomain.Logging;
using GridDomain.Node;
using GridDomain.Node.Actors;
using GridDomain.Node.Configuration.Akka;
using GridDomain.Node.Configuration.Composition;
using GridDomain.Node.Configuration.Persistence;
using GridDomain.Scheduling.Akka.Messages;
using GridDomain.Scheduling.Integration;
using GridDomain.Scheduling.Quartz.Logging;
using GridDomain.Tests.Acceptance.Scheduling.TestHelpers;
using GridDomain.Tests.Framework;
using GridDomain.Tests.Framework.Configuration;
using Microsoft.Practices.Unity;
using Moq;
using NUnit.Framework;
using Wire;
using IScheduler = Quartz.IScheduler;

namespace GridDomain.Tests.Acceptance.Scheduling
{
    [TestFixture]
    public class Spec : NodeCommandsTest
    {
        private const string Name = "test";
        private const string Group = "test";
        private IActorRef _scheduler;
        private IScheduler _quartzScheduler;
        private IUnityContainer _container;

        public Spec() : base(new AutoTestAkkaConfiguration().ToStandAloneSystemConfig())
        {

        }

        protected override GridDomainNode CreateGridDomainNode(AkkaConfiguration akkaConf, IDbConfiguration dbConfig)
        {
            var system = ActorSystemFactory.CreateActorSystem(akkaConf);
            _container = Register(system);
            system.AddDependencyResolver(new UnityDependencyResolver(_container, system));
            var router = new TestRouter();
            return new GridDomainNode(_container, router, TransportMode.Standalone, system);
        }

        private IUnityContainer Register(ActorSystem system)
        {
            var container = Container.CreateChildScope();
            CompositionRoot.Init(container, system, new AutoTestLocalDbConfiguration(), TransportMode.Standalone);
            container.RegisterInstance(new Mock<ILoggingSchedulerListener>().Object);

            container.RegisterType<AggregateActor<TestAggregate>>();
            container.RegisterType<AggregateHubActor<TestAggregate>>();
            container.RegisterType<ICommandAggregateLocator<TestAggregate>, TestAggregateCommandHandler>();
            container.RegisterType<IAggregateCommandsHandler<TestAggregate>, TestAggregateCommandHandler>();
            container.RegisterType<ISagaFactory<TestSaga, TestSagaState>, TestSagaFactory>();
            container.RegisterType<ISagaFactory<TestSaga, TestSagaStartMessage>, TestSagaFactory>();
            container.RegisterType<IEmptySagaFactory<TestSaga>, TestSagaFactory>();

            return container;
        }


        [SetUp]
        public void SetUp()
        {
            DateTimeStrategyHolder.Current = new DefaultDateTimeStrategy();
            
            CreateScheduler();
            _scheduler = GridNode.System.ActorOf(GridNode.System.DI().Props<SchedulingActor>());
            _quartzScheduler.Clear();
        }

        [TearDown]
        public void TearDown()
        {
            ResultHolder.Clear();
            _quartzScheduler.Shutdown(true);
        }

        private void CreateScheduler()
        {
            _quartzScheduler = _container.Resolve<IScheduler>();
        }

        [Test]
        public void LogTest()
        {
            LogManager.GetLogger().Error(new InvalidOperationException("ohshitwaddap"), "message {placeholder}", 18723);
        }

        [Test]
        public void When_domain_event_that_should_start_a_saga_is_scheduled_Then_saga_gets_created()
        {
            var sagaId = Guid.NewGuid();
            var testEvent = new TestSagaStartMessage(sagaId, DateTimeFacade.UtcNow, sagaId);
            _scheduler.Ask<Scheduled>(new ScheduleEvent(testEvent, new ScheduleKey(Guid.Empty, Name, Group), DateTimeFacade.UtcNow.AddSeconds(0.3)));
            WaitFor<SagaCreatedEvent<TestSaga.TestStates>>();
            var sagaState = LoadSagaState<TestSaga, TestSagaState, TestSagaStartMessage>(sagaId);
            Assert.True(sagaState.MachineState == TestSaga.TestStates.GotStartEvent);
        }

        [Test]
        public void When_domain_event_for_a_started_saga_is_scheduled_Then_saga_receives_it()
        {
            var sagaId = Guid.NewGuid();
            var startEvent = new TestSagaStartMessage(sagaId, DateTimeFacade.UtcNow, sagaId);
            _scheduler.Ask<Scheduled>(new ScheduleEvent(startEvent, new ScheduleKey(Guid.Empty, Name, Group), DateTimeFacade.UtcNow.AddSeconds(0.3)));
            WaitFor<SagaCreatedEvent<TestSaga.TestStates>>();

            var secondEvent = new TestEvent(sagaId);
            _scheduler.Ask<Scheduled>(new ScheduleEvent(secondEvent, new ScheduleKey(Guid.Empty, Name, Group), DateTimeFacade.UtcNow.AddSeconds(0.3)));
            WaitFor<SagaTransitionEvent<TestSaga.TestStates, TestSaga.Transitions>>();
            var sagaState = LoadSagaState<TestSaga, TestSagaState, TestSagaStartMessage>(sagaId);
{'fraction_non_alphanumeric': 0.09049598762448033, 'fraction_numerical': 0.0021270424441651357, 'mean_word_length': 3.4759844223279965, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, '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': '7478448', 'n_tokens_mistral': 2872, 'n_tokens_neox': 2815, 'n_words': 488}