Example #1
0
        void App_Startup(object sender, StartupEventArgs e)
        {
            var messagingPlugInRepository = new MessagingPlugInRepository();
            var messagingPluginFinder = new MessagingPluginFinder(messagingPlugInRepository);
            var unifiedMessenger = new UnifiedMessenger(messagingPlugInRepository);

            var messagingFiber = new AsyncFiber(Dispatcher);
            var cachedCredentialRepository = new MessagingCredentialCache(messagingPlugInRepository);
            var userSecurityPrompt = new UserSecurityPrompt(messagingFiber);

            messagingPlugInRepository.OnCredentialsRequestedNotify(cachedCredentialRepository);
            cachedCredentialRepository.OnCredentialsRequestedNotify(userSecurityPrompt);
            cachedCredentialRepository.OnCredentialsProvidedNotify(unifiedMessenger);

            userSecurityPrompt.OnCredentialsProvidedNotify(cachedCredentialRepository);

            var codePasteToUrlService = new CodePasteToUrlService();
            var automaticMessageFormatting = new AutoFormatCodePastesAsUrls(codePasteToUrlService);

            var messageRepository = new MessageRepository();
            var unifiedMessagingController = new UnifiedMessagingController(unifiedMessenger, messageRepository, automaticMessageFormatting, messagingFiber);
            automaticMessageFormatting.OnMessageToSendNotify(unifiedMessagingController);

            var messagingViewModel = new MessagingViewModel(unifiedMessagingController);
            var messagingWindow = new MessagingWindow(messagingViewModel);

            messageRepository.OnAddedMessagesNotify(unifiedMessagingController);
            unifiedMessagingController.OnReceivedMessagesNotify(messagingViewModel);

            messagingPluginFinder.GetAllPlugins();

            unifiedMessagingController.StartReceiving();
            unifiedMessagingController.RequestMessageUpdate();

            messagingWindow.Show();
        }
        public void It_should_send_message_using_each_service()
        {
            var messagingPlugIns = new[] {new TestMessagingPlugIn(), new TestMessagingPlugIn()};
            var messagingPlugInProvider = new TestServiceProvider();
            messagingPlugInProvider.Add(messagingPlugIns);

            var unifiedMessenger = new UnifiedMessenger(messagingPlugInProvider);

            unifiedMessenger.SendMessage("recipient", "message");

            Assert.That(messagingPlugIns.Select(x => x.SentMessages.SingleOrDefault().Text).ToArray(), Has.All.EqualTo("message"), "It should send the message via every plugin.");
            Assert.That(messagingPlugIns.Select(x=>x.SentMessages.SingleOrDefault().Address.UserName).ToArray(), Has.All.EqualTo("recipient"), "It should send the message to the correct recipient.");
        }