grumpydev / TinyIoC

An easy to use, hassle free, Inversion of Control Container for small projects, libraries and beginners alike.
MIT License
830 stars 235 forks source link

PublishAsync publishes message twice (.netstandard) #148

Closed gillima closed 3 years ago

gillima commented 3 years ago

Messages published with the PublishAsync method are published twice to all subscribes. In addition to this, the callback to indicated that publishing is finished is never invoked. This bug is intruduced by "Add dotnet core test app #132" where the publish mechanism was changed to support .netcore. Both bugs can be checked with the this unit test:

        [TestMethod]
        public void PublishAsync_Callback_EventOnce()
        {
            var syncRoot = new object();
            var messageCount = 0;
            var callbackEvent = new ManualResetEvent(false);

            var messenger = UtilityMethods.GetMessenger();
            messenger.Subscribe<TestMessage>(m => { lock (syncRoot) messageCount++; });
            var message = new TestMessage(this);

            messenger.PublishAsync<TestMessage>(message, ar => callbackEvent.Set());

            Assert.IsTrue(callbackEvent.WaitOne(1000));
            Assert.AreEqual(1, messageCount);
        }