﻿using Loquat.MessageBus.Messages;
using Loquat.MessageBus.Nodes;
using Loquat.MessageBus.Tests.Helpers;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Loquat.MessageBus.Tests.Subscriptions
{
    [TestClass]
    public class CallbackSubscriptionTest
    {
        IMessengerOutputNode<IMessage> node;

        [TestMethod]
        [TestCategory("Subscription - Callbacks")]
        public void SimpleSubscription()
        {
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback1);
        }

        [TestMethod]
        [TestCategory("Subscription - Callbacks")]
        public void MultipleSubscription()
        {
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback1);
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback2);
        }

        [TestMethod]
        [TestCategory("Subscription - Callbacks")]
        public void MultipleDerivedSubscription()
        {
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback1);
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback2);
            this.node.Subscribe<TestMessage>(TestCallbacks.TestCallback3);
            this.node.Subscribe<TestMessage>(TestCallbacks.TestCallback4);
        }

        [TestMethod]
        [TestCategory("Subscription - Callbacks")]
        public void RepeatedSubscription()
        {
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback1);
            this.node.Subscribe<TestMessage>(TestCallbacks.TestCallback2);
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback1);
            this.node.Subscribe<TestMessage>(TestCallbacks.TestCallback2);
        }

        [TestMethod]
        [TestCategory("Subscription - Callbacks")]
        public void RepeatedDerivedSubscription()
        {
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback1);
            this.node.Subscribe<IMessage>(TestCallbacks.TestCallback2);
            this.node.Subscribe<TestMessage>(TestCallbacks.TestCallback1);
            this.node.Subscribe<TestMessage>(TestCallbacks.TestCallback2);
        }

        [TestInitialize]
        public void InitializeTest()
        {
            this.node = new MessengerNode<IMessage>();
        }

        [TestCleanup]
        public void CleanUpTest()
        {
            this.node = null;
        }
    }
}
