public void RegisterReceiver_ValidExistingReceiver_RegistrationException()
        {
            // Arrange
            MessageSystem messageSystem = new MessageSystem();

            messageSystem.RegisterReceiver <IMessage>(HandleMessage);

            // Act / Assert
            Assert.Throws <RegistrationException>(() => messageSystem.RegisterReceiver <IMessage>(HandleMessage));
        }
        public void RegisterReceiver_Null_ArgumentNullException()
        {
            // Arrange
            MessageSystem messageSystem = new MessageSystem();

            // Act / Assert
            Assert.Throws <ArgumentNullException>(() => messageSystem.RegisterReceiver <IMessage>(null));
        }
        public void RegisterReceiver_ValidNonExistingReceiver_Successful()
        {
            // Arrange
            MessageSystem messageSystem = new MessageSystem();

            // Act
            messageSystem.RegisterReceiver <IMessage>(HandleMessage);

            // Assert
            Assert.Single(messageSystem.Receiver);
        }
        public void UnregisterReceiver_ValidExistingReceiver_Successful()
        {
            // Arrange
            MessageSystem messageSystem = new MessageSystem();

            messageSystem.RegisterReceiver <IMessage>(HandleMessage);

            // Act
            messageSystem.UnregisterReceiver <IMessage>(HandleMessage);

            // Assert
            Assert.Empty(messageSystem.Receiver);
        }
        public async void ProcessMessages_Successful()
        {
            // Arrange
            MessageSystem   messageSystem = new MessageSystem();
            UnitTestMessage message       = new UnitTestMessage();

            messageSystem.RegisterReceiver <UnitTestMessage>(HandleMessage);
            messageSystem.SendMessage(message);

            // Act
            await messageSystem.ProcessMessagesAsync();

            // Assert
            Assert.Empty(messageSystem.ActiveMessages);
            Assert.True(callbackExecuted);
        }