Exemplo n.º 1
0
        public void CampaignManagerDriverMultipleCampaignsWithValidatorReturningFalseTest()
        {
            // The Subscriber is set up in the constructor
            var testCampaignManagagerSubscriber = new Mock <ISubscriber>();

            // Mock the call to the subscriber
            testCampaignManagagerSubscriber.Setup(d => d.SetupAddOnReceiveActionToChannel(It.IsAny <Action <ILeadEntity> >())).Verifiable();
            // Mock CampaignConfig to return the above Subscriber
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerSubscriber).Returns(testCampaignManagagerSubscriber.Object);

            // No Campaigns set up, mock the Decorator that is called once
            var decorator = new Mock <IDecorator>();

            decorator.Setup(d => d.DecorateLead(It.IsAny <ILeadEntity>(), It.IsAny <List <IResult> >())).Verifiable();
            // Mock CampaignConfig to return the above Decorator
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerDecorator).Returns(decorator.Object);

            // Set up 3 Campaigns
            const int testCampaignCnt        = 3;
            var       testCampaignCollection = new ICampaign[testCampaignCnt];

            for (var campaignIndex = 0; campaignIndex < testCampaignCnt; campaignIndex++)
            {
                var id   = campaignIndex;
                var mock = new Mock <ICampaign>();
                mock.Setup(campaign => campaign.ProcessLead(It.IsAny <ILeadEntity>()))
                .Returns(_testCampaignManagerResultList);
                testCampaignCollection[id] = mock.Object;
            }
            // Mock the Campaign Config to return the above Campaign Collection
            _campaignManagerConfig.SetupGet(cc =>
                                            cc.CampaignCollection).Returns(testCampaignCollection);

            // Mock the Campaign Manager Validator to return false
            var testValidator = new Mock <IValidator>();

            testValidator.Setup(v => v.ValidLead(It.IsAny <ILeadEntity>())).Returns(false);

            // Mock the Campaign Config to return the testValidator as the CampaignMangerValidator
            _campaignManagerConfig.SetupGet(cc =>
                                            cc.CampaignManagerValidator).Returns(testValidator.Object);

            // Intitialize the CampaignManager with the mocked testCampaignCollection
            var campaignManager = new Implementation.CampaignManager(_testCampaignManagerId, _campaignManagerConfig.Object, _loggerClient.Object);

            campaignManager.CampaignManagerDriver(_testLeadEntity);
        }
Exemplo n.º 2
0
        public void CampaignManagerDriverEmptyCampaignTest()
        {
            // The Subscriber is set up in the constructor
            var testCampaignManagagerSubscriber = new Mock <ISubscriber>();

            // Mock the call to the subscriber
            testCampaignManagagerSubscriber.Setup(d => d.SetupAddOnReceiveActionToChannel(It.IsAny <Action <ILeadEntity> >())).Verifiable();
            // Mock CampaignConfig to return the above Subscriber
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerSubscriber).Returns(testCampaignManagagerSubscriber.Object);

            // No Campaigns set up, mock the Decorator that is called once
            var decorator = new Mock <IDecorator>();

            decorator.Setup(d => d.DecorateLead(It.IsAny <ILeadEntity>(), It.IsAny <List <IResult> >())).Verifiable();
            // Mock CampaignConfig to return the above Decorator
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerDecorator).Returns(decorator.Object);

            var campaignManager = new Implementation.CampaignManager(_testCampaignManagerId, _campaignManagerConfig.Object, _loggerClient.Object);

            campaignManager.CampaignManagerDriver(_testLeadEntity);
        }
Exemplo n.º 3
0
        public void CampaignManagerDriverTestWithNullLeadEntityObject()
        {
            // The Subscriber is set up in the constructor
            var testCampaignManagagerSubscriber = new Mock <ISubscriber>();

            // Mock the call to the subscriber
            testCampaignManagagerSubscriber.Setup(d => d.SetupAddOnReceiveActionToChannel(It.IsAny <Action <ILeadEntity> >())).Verifiable();
            // Mock CampaignConfig to return the above Subscriber
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerSubscriber).Returns(testCampaignManagagerSubscriber.Object);

            // No Campaigns set up, not necessary to mock other components
            var campaignManager = new Implementation.CampaignManager(_testCampaignManagerId, _campaignManagerConfig.Object, _loggerClient.Object);

            try
            {
                campaignManager.CampaignManagerDriver(null);
            }
            catch (Exception exception)
            {
                Assert.AreEqual(typeof(ArgumentNullException), exception.GetType());
                Assert.AreEqual("Value cannot be null. Parameter name: leadEntity",
                                exception.Message.Replace(Environment.NewLine, " "));
            }
        }
Exemplo n.º 4
0
        public void CampaignManagerDriverMultipleCampaignTestWithResolverException()
        {
            // The Subscriber is set up in the constructor
            var testCampaignManagagerSubscriber = new Mock <ISubscriber>();

            // Mock the call to the subscriber
            testCampaignManagagerSubscriber.Setup(d => d.SetupAddOnReceiveActionToChannel(It.IsAny <Action <ILeadEntity> >())).Verifiable();
            // Mock CampaignConfig to return the above Subscriber
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerSubscriber).Returns(testCampaignManagagerSubscriber.Object);

            // No Campaigns set up, mock the Decorator that is called once
            var testCampaignManagerDecorator = new Mock <IDecorator>();

            testCampaignManagerDecorator.Setup(d => d.DecorateLead(It.IsAny <ILeadEntity>(), It.IsAny <List <IResult> >())).Verifiable();
            // Mock CampaignConfig to return the above Decorator
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerDecorator).Returns(testCampaignManagerDecorator.Object);

            // Set up 3 Campaigns
            const int testCampaignCnt        = 3;
            var       testCampaignCollection = new ICampaign[testCampaignCnt];

            for (var campaignIndex = 0; campaignIndex < testCampaignCnt; campaignIndex++)
            {
                var id   = campaignIndex;
                var mock = new Mock <ICampaign>();
                mock.Setup(campaign => campaign.ProcessLead(It.IsAny <ILeadEntity>()))
                .Returns(_testCampaignManagerResultList);
                testCampaignCollection[id] = mock.Object;
            }
            // Mock the Campaign Config to return the above Campaign Collection
            _campaignManagerConfig.SetupGet(cc =>
                                            cc.CampaignCollection).Returns(testCampaignCollection);

            // Mock the Campaign Manager Validator to return true
            var testValidator = new Mock <IValidator>();

            testValidator.Setup(v => v.ValidLead(It.IsAny <ILeadEntity>())).Returns(true);

            // Mock the Campaign Config to return the testValidator as the CampaignMangerValidator
            _campaignManagerConfig.SetupGet(cc =>
                                            cc.CampaignManagerValidator).Returns(testValidator.Object);

            // The Resolver
            var testCampaignManagagerResolver = new Mock <IResolver>();

            // Mock the call to the resolver to return an exception
            testCampaignManagagerResolver.Setup(d => d.ResolveLead(It.IsAny <ILeadEntity>())).Throws(new ArgumentNullException($"ResolveLeads"));
            // Mock CampaignConfig to return the above Resolver
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerResolver).Returns(testCampaignManagagerResolver.Object);



            //_campaignManagerResolver.Setup(c => c.ResolveLeads(It.IsAny<ILeadEntity>(), It.IsAny<List<IResult>[]>())).Throws(new ArgumentNullException(
            //    $"ResolveLeads"));
            //_campaignManagerDecorator.Setup(c => c.DecorateLead(It.IsAny<ILeadEntity>(), It.IsAny<List<IResult>>())).Verifiable();
            //_campaignManagerPublisher.Verify(c => c.PublishLead(It.IsAny<ILeadEntity>()), Times.Never());



            try
            {
                // Intitialize the CampaignManager with the mocked testCampaignCollection
                var campaignManager = new Implementation.CampaignManager(_testCampaignManagerId, _campaignManagerConfig.Object, _loggerClient.Object);
                campaignManager.CampaignManagerDriver(_testLeadEntity);

                // A sleep here - not a great solution - to wait for the campaign tasks to finish and ensure that
                // the resolver thows exception and the decorator are called in the CampaignManagerProcessResults() function
                // which is set up via ContinueWith() of the Campaign Task.
                Thread.Sleep(_testMultiThreadedWaitTime);
            }
            catch (Exception exception)
            {
                Assert.AreEqual(typeof(ArgumentNullException), exception.GetType());
                Assert.AreEqual("Value cannot be null. Parameter name: ResolveLeads",
                                exception.Message.Replace(Environment.NewLine, " "));
            }
        }
Exemplo n.º 5
0
        public void CampaignManagerDriverMultipleCampaignTest()
        {
            // The Subscriber is set up in the constructor
            var testCampaignManagagerSubscriber = new Mock <ISubscriber>();

            // Mock the call to the subscriber
            testCampaignManagagerSubscriber.Setup(d => d.SetupAddOnReceiveActionToChannel(It.IsAny <Action <ILeadEntity> >())).Verifiable();
            // Mock CampaignConfig to return the above Subscriber
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerSubscriber).Returns(testCampaignManagagerSubscriber.Object);

            // No Campaigns set up, mock the Decorator that is called once
            var testCampaignManagerDecorator = new Mock <IDecorator>();

            testCampaignManagerDecorator.Setup(d => d.DecorateLead(It.IsAny <ILeadEntity>(), It.IsAny <List <IResult> >())).Verifiable();
            // Mock CampaignConfig to return the above Decorator
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerDecorator).Returns(testCampaignManagerDecorator.Object);

            // Set up 3 Campaigns
            const int testCampaignCnt        = 3;
            var       testCampaignCollection = new ICampaign[testCampaignCnt];

            for (var campaignIndex = 0; campaignIndex < testCampaignCnt; campaignIndex++)
            {
                var id   = campaignIndex;
                var mock = new Mock <ICampaign>();
                mock.Setup(campaign => campaign.ProcessLead(It.IsAny <ILeadEntity>()))
                .Returns(_testCampaignManagerResultList);
                testCampaignCollection[id] = mock.Object;
            }
            // Mock the Campaign Config to return the above Campaign Collection
            _campaignManagerConfig.SetupGet(cc =>
                                            cc.CampaignCollection).Returns(testCampaignCollection);

            // Mock the Campaign Manager Validator to return true
            var testValidator = new Mock <IValidator>();

            testValidator.Setup(v => v.ValidLead(It.IsAny <ILeadEntity>())).Returns(true);

            // Mock the Campaign Config to return the testValidator as the CampaignMangerValidator
            _campaignManagerConfig.SetupGet(cc =>
                                            cc.CampaignManagerValidator).Returns(testValidator.Object);

            // The Resolver
            var testCampaignManagagerResolver = new Mock <IResolver>();

            // Mock the call to the resolver
            testCampaignManagagerResolver.Setup(d => d.ResolveLead(It.IsAny <ILeadEntity>())).Verifiable();
            // Mock CampaignConfig to return the above Resolver
            _campaignManagerConfig.SetupGet(cc => cc.CampaignManagerResolver).Returns(testCampaignManagagerResolver.Object);

            // Intitialize the CampaignManager with the mocked testCampaignCollection
            var campaignManager = new Implementation.CampaignManager(_testCampaignManagerId, _campaignManagerConfig.Object, _loggerClient.Object);

            campaignManager.CampaignManagerDriver(_testLeadEntity);


            // A sleep here - not a great solution - to wait for the campaign tasks to finish and ensure that
            // the resolver, publisher and decorator are called in the CampaignManagerProcessResults() function
            // which is set up via ContinueWith() of the Campaign Task.
            Thread.Sleep(_testMultiThreadedWaitTime);
        }