예제 #1
0
        public void LeadPublisherPublishLeadTest()
        {
            var          testChannel     = new InProcNotificationChannel <ILeadEntity>(new Mock <ILogger>().Object);
            var          testPublisher   = new Publisher <ILeadEntity>(new INotificationChannel <ILeadEntity>[] { testChannel }, true);
            var          testSubscriber  = new Subscriber <ILeadEntity>(testChannel, true);
            const string expectedMessage =
                "{\"Context\":null,\"Properties\":[{\"Id\":\"testKey\",\"Value\":\"testValue\"}],\"Segments\":null,\"Results\":null}";


            var leadPublisher = new LeadPublisher(testPublisher, new Mock <ILoggerClient>().Object);

            var testProperty = new TestProperty
            {
                Id    = "testKey",
                Value = "testValue"
            };

            var testLead = new TestLeadEntity
            {
                Properties = new IProperty[] { testProperty }
            };
            var actualLead = new TestLeadEntity();

            testSubscriber.AddOnReceiveActionToChannel(testlead => actualLead = testLead);

            leadPublisher.PublishLead(testLead);

            Thread.Sleep(5); //Speed bump to let the threads process.

            Assert.AreEqual(testLead, actualLead);
        }
예제 #2
0
        public void CampaignManagerSubscriberAddOnReceiveActionToChannel()
        {
            var testNotificationChannel   = new InProcNotificationChannel <ILeadEntity>(new Mock <ILogger>().Object);
            var testNotificationPublisher =
                new Publisher <ILeadEntity>(new INotificationChannel <ILeadEntity>[] { testNotificationChannel }, true);
            var testNotificationSubscriber = new Subscriber <ILeadEntity>(testNotificationChannel, true);

            // Set up the action to be invoked when a leadEntity is received
            bool actionWasInvoked = false;
            Action <ILeadEntity> leadEntityReceiveAction = campaignManagerDriver => actionWasInvoked = true;

            // Setup the Subscriber to execute the action when invoked
            var campaignManagerSubscriber =
                new CampaignManagerSubscriber(testNotificationSubscriber, _loggerClient.Object);

            campaignManagerSubscriber.SetupAddOnReceiveActionToChannel(leadEntityReceiveAction);

            // Let the Notification Publisher broadcast a leadEntity
            testNotificationPublisher.BroadcastMessage(_testLleadEntity);

            // Sleep a little while for the Notification Channel to pick up the LeadEntity
            Thread.Sleep(5);

            // The subscriber should now have executed the action
            Assert.AreEqual(true, actionWasInvoked);
        }