<commit_before>﻿using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Nimbus.Configuration;
using Nimbus.Extensions;
using Nimbus.IntegrationTests.Extensions;
using Nimbus.Tests.Common.Extensions;
using Nimbus.Tests.Common.TestScenarioGeneration.ScenarioComposition;
using Nimbus.Tests.Common.TestUtilities;
using NUnit.Framework;

namespace Nimbus.IntegrationTests
{
    [TestFixture]
    [Timeout(TimeoutSeconds*1000)]
    public abstract class TestForBus
    {
        protected const int TimeoutSeconds = 60;
        protected readonly TimeSpan Timeout = TimeSpan.FromSeconds(TimeoutSeconds);

        protected ScenarioInstance<BusBuilderConfiguration> Instance { get; private set; }
        protected Bus Bus { get; private set; }

        private bool _thenWasInvoked;

        protected virtual async Task Given(IConfigurationScenario<BusBuilderConfiguration> scenario)
        {
            MethodCallCounter.Clear();

            Instance = scenario.CreateInstance();
            Reconfigure();

            Bus = Instance.Configuration.Build();
            await Bus.Start();
        }

        protected virtual void Reconfigure()
        {
        }

        protected abstract Task When();

        protected async Task Then()
        {
            _thenWasInvoked = true;

            var assertionMethods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public)
                                            .Where(m => m.HasAttribute<ThenAttribute>())
                                            .ToArray();

            await assertionMethods
                .Select(m => (Task) m.Invoke(this, new object[0]))
                .WhenAll();
        }

        [SetUp]
        public void SetUp()
        {
            _thenWasInvoked = false;
            TestLoggingExtensions.LogTestStart();
        }

        [TearDown]
        public void TearDown()
        {
            var bus = Bus;
            Bus = null;

            bus?.Stop().Wait();
            bus?.Dispose();

            Instance?.Dispose();
            Instance = null;

            if (!_thenWasInvoked) Assert.Fail("It looks like we forgot to call our Then() method.");
            TestLoggingExtensions.LogTestResult();
        }
    }
}<commit_msg>Clearer message for when a test completes without invoking Then().<commit_after>﻿using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Nimbus.Configuration;
using Nimbus.Extensions;
using Nimbus.IntegrationTests.Extensions;
using Nimbus.Tests.Common.Extensions;
using Nimbus.Tests.Common.TestScenarioGeneration.ScenarioComposition;
using Nimbus.Tests.Common.TestUtilities;
using NUnit.Framework;

namespace Nimbus.IntegrationTests
{
    [TestFixture]
    [Timeout(TimeoutSeconds*1000)]
    public abstract class TestForBus
    {
        protected const int TimeoutSeconds = 60;
        protected readonly TimeSpan Timeout = TimeSpan.FromSeconds(TimeoutSeconds);

        protected ScenarioInstance<BusBuilderConfiguration> Instance { get; private set; }
        protected Bus Bus { get; private set; }

        private bool _thenWasInvoked;

        protected virtual async Task Given(IConfigurationScenario<BusBuilderConfiguration> scenario)
        {
            MethodCallCounter.Clear();

            Instance = scenario.CreateInstance();
            Reconfigure();

            Bus = Instance.Configuration.Build();
            await Bus.Start();
        }

        protected virtual void Reconfigure()
        {
        }

        protected abstract Task When();

        protected async Task Then()
        {
            _thenWasInvoked = true;

            var assertionMethods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public)
                                            .Where(m => m.HasAttribute<ThenAttribute>())
                                            .ToArray();

            await assertionMethods
                .Select(m => (Task) m.Invoke(this, new object[0]))
                .WhenAll();
        }

        [SetUp]
        public void SetUp()
        {
            _thenWasInvoked = false;
            TestLoggingExtensions.LogTestStart();
        }

        [TearDown]
        public void TearDown()
        {
            var bus = Bus;
            Bus = null;

            bus?.Stop().Wait();
            bus?.Dispose();

            Instance?.Dispose();
            Instance = null;

            TestLoggingExtensions.LogTestResult();

            if (!_thenWasInvoked) Assert.Fail($"Test completed without calling {nameof(Then)} method.");
        }
    }
}
{'fraction_non_alphanumeric': 0.08902333621434745, 'fraction_numerical': 0.003025064822817632, 'mean_word_length': 2.0254901960784313, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6639180', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1121, 'n_words': 269}