public void CanGetCampaignDetailsWithServeralCampaignsIgnoreInvalidData() { var clientRepository = RepositoryHelper.RepositoryLocalWithOneClient; var gaService = new Mock <IGoogleAnalyticsApi>(); var userManager = new Mock <IIdentityMembershipProvider>(); var contactProductService = new Mock <IProductService>(); var contactIndexCalculator = new Mock <IContactIndexCalculator>(); var controller = new SourceController(clientRepository, contactProductService.Object, userManager.Object, gaService.Object, contactIndexCalculator.Object); var startDate = new DateTime(2014, 1, 1); var endDate = new DateTime(2014, 2, 1); var mapRowResponse = new List <CampaignDetails>(); var row1 = new CampaignDetails { Campaign = "Campaign1", SourceMedium = "google/cpc", AdCost = 20, Sessions = 10 }; var row2 = new CampaignDetails { Campaign = "Campaign2", SourceMedium = "Adroll/cpc", AdCost = 30, AdClicksMetric = 20, Sessions = 0 }; var invalidRow = new CampaignDetails { Campaign = "Campaign1", SourceMedium = "google/direct", AdCost = 20, Sessions = 0 }; mapRowResponse.Add(row1); mapRowResponse.Add(row2); mapRowResponse.Add(invalidRow); var contact1 = new Contact() { Date = startDate.AddDays(1), Campaign = "Campaign1" }; var contact2 = new Contact() { Date = startDate.AddDays(1), Campaign = "Campaign2" }; var contactNotInRange = new Contact() { Date = endDate.AddDays(1), Campaign = "Campaign1" }; clientRepository.All().First().Leads.Add(contact1); clientRepository.All().First().Leads.Add(contact2); clientRepository.All().First().Leads.Add(contactNotInRange); var analyticQuery = new AnalyticQuery(); analyticQuery.Dimenssions.AddMany("ga:sourceMedium", "ga:campaign"); analyticQuery.TabelId = clientRepository.All().First().AnalyticsTableId; analyticQuery.StartDate = startDate; analyticQuery.EndDate = endDate; analyticQuery.Metrics.AddMany("ga:adClicks", "ga:adCost", "ga:impressions", "ga:sessions"); analyticQuery.Filters.Add("ga:campaign!=(not set)"); gaService.Setup( ga => ga.Get <CampaignDetails>(It.Is <AnalyticQuery>( aq => !aq.Dimenssions.Except(analyticQuery.Dimenssions).Any() && !aq.Metrics.Except(analyticQuery.Metrics).Any() && !aq.Filters.Except(analyticQuery.Filters).Any() && aq.StartDate == analyticQuery.StartDate && aq.EndDate == analyticQuery.EndDate && aq.TabelId == analyticQuery.TabelId))).Returns(mapRowResponse); contactProductService.Setup(cp => cp.IsValidProduct(It.IsAny <string>(), "cpc")).Returns(true); contactProductService.Setup(cp => cp.GetProduct(It.IsAny <string>(), "cpc")).Returns("Display"); var result = controller.GetCampaignsDetail(1, startDate, endDate) as OkNegotiatedContentResult <IEnumerable <CampaignDetails> >; Assert.AreEqual(2, result.Content.Count()); Assert.AreEqual(10, result.Content.Single(c => c.Campaign == "Campaign1").AdClicks); Assert.AreEqual(10, result.Content.Single(c => c.Campaign == "Campaign1").Sessions); Assert.AreEqual(false, result.Content.Single(c => c.Campaign == "Campaign1").AdClicksMetric.HasValue); Assert.AreEqual(20, result.Content.Single(c => c.Campaign == "Campaign1").AdCost); Assert.AreEqual("Adwords", result.Content.Single(c => c.Campaign == "Campaign1").AdProvider); Assert.AreEqual("google", result.Content.Single(c => c.Campaign == "Campaign1").Source); Assert.AreEqual("cpc", result.Content.Single(c => c.Campaign == "Campaign1").Medium); Assert.AreEqual("Display", result.Content.Single(c => c.Campaign == "Campaign1").Product); Assert.AreEqual(1, result.Content.Single(c => c.Campaign == "Campaign1").NumContacts); Assert.AreEqual(20, result.Content.Single(c => c.Campaign == "Campaign2").AdClicks); Assert.AreEqual(0, result.Content.Single(c => c.Campaign == "Campaign2").Sessions); Assert.AreEqual(true, result.Content.Single(c => c.Campaign == "Campaign2").AdClicksMetric.HasValue); Assert.AreEqual(20, result.Content.Single(c => c.Campaign == "Campaign2").AdClicksMetric); Assert.AreEqual(30, result.Content.Single(c => c.Campaign == "Campaign2").AdCost); Assert.AreEqual("Adroll", result.Content.Single(c => c.Campaign == "Campaign2").AdProvider); Assert.AreEqual("Adroll", result.Content.Single(c => c.Campaign == "Campaign2").Source); Assert.AreEqual("cpc", result.Content.Single(c => c.Campaign == "Campaign2").Medium); Assert.AreEqual("Display", result.Content.Single(c => c.Campaign == "Campaign2").Product); Assert.AreEqual(1, result.Content.Single(c => c.Campaign == "Campaign2").NumContacts); }
public void CanGetCampaignDetailsReturnsNoCampaignForNoProductAndNoAdClick() { var clientRepository = RepositoryHelper.RepositoryLocalWithOneClient; var gaService = new Mock <IGoogleAnalyticsApi>(); var userManager = new Mock <IIdentityMembershipProvider>(); var contactProductService = new Mock <IProductService>(); var contactIndexCalculator = new Mock <IContactIndexCalculator>(); var controller = new SourceController(clientRepository, contactProductService.Object, userManager.Object, gaService.Object, contactIndexCalculator.Object); var startDate = new DateTime(2014, 1, 1); var endDate = new DateTime(2014, 2, 1); var mapRowResponse = new List <CampaignDetails>(); var row1 = new CampaignDetails { Campaign = "Campaign1", SourceMedium = "google/cpc", AdCost = 20, Sessions = 0 }; var row2 = new CampaignDetails { Campaign = "Campaign2", SourceMedium = "Adroll/cpc", AdCost = 30, AdClicksMetric = 10 }; mapRowResponse.Add(row1); mapRowResponse.Add(row2); var analyticQuery = new AnalyticQuery(); analyticQuery.Dimenssions.AddMany("ga:sourceMedium", "ga:campaign"); analyticQuery.TabelId = clientRepository.All().First().AnalyticsTableId; analyticQuery.StartDate = startDate; analyticQuery.EndDate = endDate; analyticQuery.Metrics.AddMany("ga:adClicks", "ga:adCost", "ga:impressions", "ga:sessions"); analyticQuery.Filters.Add("ga:campaign!=(not set)"); gaService.Setup( ga => ga.Get <CampaignDetails>(It.Is <AnalyticQuery>( aq => !aq.Dimenssions.Except(analyticQuery.Dimenssions).Any() && !aq.Metrics.Except(analyticQuery.Metrics).Any() && !aq.Filters.Except(analyticQuery.Filters).Any() && aq.StartDate == analyticQuery.StartDate && aq.EndDate == analyticQuery.EndDate && aq.TabelId == analyticQuery.TabelId))).Returns(mapRowResponse); contactProductService.Setup(cp => cp.IsValidProduct(It.IsAny <string>(), "cpc")).Returns(false); var result = controller.GetCampaignsDetail(1, startDate, endDate) as OkNegotiatedContentResult <IEnumerable <CampaignDetails> >; Assert.AreEqual(0, result.Content.Count()); }