<commit_before>﻿using LightMessageBus.Interfaces;
using LightMessageBus.Test.TestClasses;
using NUnit.Framework;

namespace LightMessageBus.Test
{
    [TestFixture]
    public class LightMessageBusTests
    {
        #region Default
        
        [Test]
        public void Default_ReturnsSingleton()
        {
            Assert.IsNotNull(LightMessageBus.Default);
        }

        [Test]
        public void Default_ReturnsSameInstance()
        {
            Assert.AreSame(LightMessageBus.Default, LightMessageBus.Default);
        }

        [Test]
        public void Default_ReturnsPublishers()
        {
            Assert.IsInstanceOf<IPublishers>(LightMessageBus.Default);
        }

        #endregion

        #region From

        [Test]
        public void From_ReturnsUntypedMessages()
        {
            var messages = LightMessageBus.Default.From(new object());

            Assert.IsInstanceOf<IMessages>(messages);
        }

        #endregion

        #region Notify

        [Test]
        public void Notify_SubscriberRegistered()
        {
            var subscriber = new EmptySubscriber();

            LightMessageBus.Default.From(new object()).Notify(subscriber);

            Assert.IsTrue(LightMessageBus.Default.HasRegistered(subscriber));
        }

        [Test]
        public void NoNotify_SubscriberNotRegistered()
        {
            var subscriber = new EmptySubscriber();

            Assert.IsFalse(LightMessageBus.Default.HasRegistered(subscriber));
        }

        #endregion

        #region Publish

        [Test]
        public void Publish_SubscriberNotified()
        {
            var subscriber = new NotifiableSubscriber();
            LightMessageBus.Default.From(new object()).Notify(subscriber);

            LightMessageBus.Default.Publish(new object());

            Assert.IsTrue(subscriber.IsNotified);
        }

        [Test]
        public void Publish_DifferentSubscriberNotNotified()
        {
            var subscriber = new NotifiableSubscriber();
            LightMessageBus.Default.From(new object()).Notify(new NotifiableSubscriber());

            LightMessageBus.Default.Publish(new object());

            Assert.IsFalse(subscriber.IsNotified);
        }

        #endregion

        
    }
}<commit_msg>renamed tests to bdd convention<commit_after>﻿using LightMessageBus.Interfaces;
using LightMessageBus.Test.TestClasses;
using NUnit.Framework;

namespace LightMessageBus.Test
{
    [TestFixture]
    public class LightMessageBusTests
    {
        #region Default
        
        [Test]
        public void GivenMessageBus_WhenDefault_ReturnsObject()
        {
            Assert.IsNotNull(LightMessageBus.Default);
        }

        [Test]
        public void GivenMessageBus_WhenDefault_ReturnsSameInstance()
        {
            Assert.AreSame(LightMessageBus.Default, LightMessageBus.Default);
        }

        [Test]
        public void GivenMessageBus_WhenDefault_ReturnsPublishers()
        {
            Assert.IsInstanceOf<IPublishers>(LightMessageBus.Default);
        }

        #endregion

        #region From

        [Test]
        public void GivenMessageBus_WhenFrom_ReturnsMessages()
        {
            var messages = LightMessageBus.Default.From(new object());

            Assert.IsInstanceOf<IMessages>(messages);
        }

        #endregion

        #region Notify

        [Test]
        public void GivenSubscriber_WhenSubscriberRegistered_SubscriberRegistered()
        {
            var subscriber = new EmptySubscriber();

            LightMessageBus.Default.From(new object()).Notify(subscriber);

            Assert.IsTrue(LightMessageBus.Default.HasRegistered(subscriber));
        }

        [Test]
        public void GivenSubscriber_WhenSubscriberNotRegistered_SubscriberNotRegistered()
        {
            var subscriber = new EmptySubscriber();

            Assert.IsFalse(LightMessageBus.Default.HasRegistered(subscriber));
        }

        #endregion

        #region Publish

        [Test]
        public void GivenRegisteredSubscriber_WhenMessagePublished_SubscriberNotified()
        {
            var subscriber = new NotifiableSubscriber();
            LightMessageBus.Default.From(new object()).Notify(subscriber);

            LightMessageBus.Default.Publish(new object());

            Assert.IsTrue(subscriber.IsNotified);
        }

        [Test]
        public void GivenRegisteredSubscriber_WhenMessagePublished_OtherSubscriberNotNotified()
        {
            var otherSubscriber = new NotifiableSubscriber();
            LightMessageBus.Default.From(new object()).Notify(new NotifiableSubscriber());

            LightMessageBus.Default.Publish(new object());

            Assert.IsFalse(otherSubscriber.IsNotified);
        }

        #endregion

        
    }
}
{'fraction_non_alphanumeric': 0.08086253369272237, 'fraction_numerical': 0.0, 'mean_word_length': 2.1968190854870775, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5757574', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1191, 'n_words': 196}