public async Task ShouldNotSendBonusOperation_WhenConditionInCampaignIsAlreadyCompleted() { // Arrange var fixtureData = new CampaignServiceBonusProcessingTestsFixture(); fixtureData.SetupCampaignCacheGetCampaignsByTypeAsync(); fixtureData.ConditionCompletions.Add(new ConditionCompletion { ConditionId = fixtureData.ConditionId, CurrentCount = 1, CustomerId = fixtureData.CustomerId, IsCompleted = true }); fixtureData.CampaignModel.Conditions = new List <Condition>() { // Condition one is completed, condition 2 is not - we use 2 conditions to simulate running campaign, since // campaign completion is used to determine if a campaign is finished by a customer or not new Condition() { CampaignId = fixtureData.CampaignModel.Id, CompletionCount = 1, BonusType = new BonusType { Type = "signup" }, Id = fixtureData.ConditionId, ImmediateReward = 10 }, new Condition() { CampaignId = fixtureData.CampaignModel.Id, CompletionCount = 1, BonusType = new BonusType { Type = "referral" }, Id = Guid.NewGuid().ToString("D"), ImmediateReward = 15 } }; // Execute await fixtureData.CampaignServiceInstance.ProcessEventForCustomerAsync( fixtureData.CustomerId, fixtureData.PartnerId, fixtureData.LocationId, fixtureData.EventDataEmpty, fixtureData.BonusTypeName); // Assert fixtureData.ConditionCompletionServiceMock.Verify(c => c.IncreaseCompletionCountAsync(It.IsAny <ConditionCompletion>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <int>()), Times.Never); fixtureData.ConditionCompletionServiceMock.Verify(c => c.SetConditionCompletedAsync(It.IsAny <string>()), Times.Never); fixtureData.BonusOperationServiceMock.Verify(c => c.AddBonusOperationAsync(It.IsAny <BonusOperation>()), Times.Never); }
public async Task ShouldNotSendBonusOperation_WhenAllConditionsInCampaignIsAlreadyCompleted() { // Arrange var fixtureData = new CampaignServiceBonusProcessingTestsFixture(); fixtureData.SetupCampaignCacheGetCampaignsByTypeAsync(); const string conditionId2 = "d9aa75ea-e0c6-4436-a9d5-bf5ab8c70e54"; fixtureData.ConditionModels.Add(new Condition { CampaignId = fixtureData.CampaignId, CompletionCount = 1, BonusType = fixtureData.BonusType, Id = conditionId2, ImmediateReward = 45 }); fixtureData.ConditionCompletions.Add(new ConditionCompletion { ConditionId = fixtureData.ConditionId, CurrentCount = 1, CustomerId = fixtureData.CustomerId, IsCompleted = true }); fixtureData.ConditionCompletions.Add(new ConditionCompletion { ConditionId = conditionId2, CurrentCount = 1, CustomerId = fixtureData.CustomerId, IsCompleted = true }); // Execute await fixtureData.CampaignServiceInstance.ProcessEventForCustomerAsync( fixtureData.CustomerId, fixtureData.PartnerId, fixtureData.LocationId, fixtureData.EventDataEmpty, fixtureData.BonusTypeName); // Assert fixtureData.ConditionCompletionServiceMock.Verify(c => c.IncreaseCompletionCountAsync(It.IsAny <ConditionCompletion>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <int>()), Times.Never); fixtureData.ConditionCompletionServiceMock.Verify(c => c.SetConditionCompletedAsync(It.IsAny <string>()), Times.Never); fixtureData.BonusOperationServiceMock.Verify(c => c.AddBonusOperationAsync(It.IsAny <BonusOperation>()), Times.Never); }
public async Task ShouldSendMultipleBonusOperation_WhenConditionFulfilledMultipleTimes(int triggerCount) { // Arrange var fixtureData = new CampaignServiceBonusProcessingTestsFixture { ConditionModel = { CompletionCount = triggerCount + 1 } }; fixtureData.SetupConditionProcessingMocks(); fixtureData.SetupCampaignCacheGetCampaignsByTypeAsync(); fixtureData.SetupConditionRewardMocks(); // in SetupCommonMocks GetByCampaignAsync each time takes new completion entry for (int i = 0; i < triggerCount; i++) { fixtureData.CampaignCompletions.Add(new CampaignCompletion() { CampaignCompletionCount = 0, CampaignId = fixtureData.CampaignId, CustomerId = fixtureData.CustomerId, }); } fixtureData.BonusCalculatorServiceMock.Setup(b => b.CalculateConditionRewardAmountAsync(It.IsAny <Condition>(), It.IsAny <ConditionCompletion>())) .ReturnsAsync(10); // Execute for (int i = 0; i < triggerCount; i++) { await fixtureData.CampaignServiceInstance.ProcessEventForCustomerAsync( fixtureData.CustomerId, fixtureData.PartnerId, fixtureData.LocationId, fixtureData.EventDataEmpty, fixtureData.BonusTypeName); } // Assert fixtureData.BonusOperationServiceMock.Verify(c => c.AddBonusOperationAsync(It.IsAny <BonusOperation>()), Times.Exactly(triggerCount)); }