public void UpdatePrePayForOptedInChannelInvalidPrePaySettingsThrowsException() { // Arrange const int CHANNEL_ID = 1; const long BUSINESS_ID = 1; const int CHANNEL_TERMS_ID = 1; var channelDao = new Mock<IChannelDao>(); var businessChannelOptInDao = new Mock<IBusinessChannelOptInDao>(); var prePayDao = new Mock<IPrePayDao>(); var distributionManager = new DistributionManager { BusinessChannelOptInDao = businessChannelOptInDao.Object, ChannelDao = channelDao.Object, PrePayDao = prePayDao.Object }; channelDao.Setup(c => c.GetById(It.Is<int>(i => i == CHANNEL_ID))).Returns(new Channel { Id = CHANNEL_ID }); businessChannelOptInDao.Setup(b => b.UpdatePrePaySettings(It.IsAny<BusinessChannelOptIn>())).Returns(false); prePayDao.Setup(cc => cc.GetPermittedChannelSettings(BUSINESS_ID, CHANNEL_ID)) .Returns(new List<ChannelPrePayPermittedSetting> { new ChannelPrePayPermittedSetting { ChannelId = CHANNEL_ID, Min = 10, Max = 100, Type = PrePayRuleTypeEnum.Amount } }); var businessChannelOptIn = new BusinessChannelOptIn { ChannelId = CHANNEL_ID, BusinessId = BUSINESS_ID, ChannelTermsId = CHANNEL_TERMS_ID, PrePaySettings = new BusinessChannelPrePaySettings { Type = PrePayRuleTypeEnum.Amount, Value = 150, IsOverridden = true } }; // Act try { distributionManager.UpdatePrePayForOptedInChannel(businessChannelOptIn); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30135", ex.Code, "SRVEX30135 was not thrown"); } }
public void UpdatePrePayForOptedInGroupChannelCallsCorrectMethods() { // Arrange const int CHANNEL_ID = 1; const int SUB_CHANNEL_ID = 2; const long BUSINESS_ID = 1; const int CHANNEL_TERMS_ID = 1; var channelDao = new Mock<IChannelDao>(); var businessChannelOptInDao = new Mock<IBusinessChannelOptInDao>(); var eventTrackingManager = new Mock<IEventTrackingManager>(); var prePayDao = new Mock<IPrePayDao>(); var distributionManager = new DistributionManager { BusinessChannelOptInDao = businessChannelOptInDao.Object, ChannelDao = channelDao.Object, EventTrackingManager = eventTrackingManager.Object, PrePayDao = prePayDao.Object }; channelDao.Setup(c => c.GetById(It.Is<int>(i => i == CHANNEL_ID))).Returns(new Channel { Id = CHANNEL_ID, SupportsCustomCancPolicy = true, ChannelType = ChannelTypeEnum.LogicalGroup }); channelDao.Setup(c => c.GetById(It.Is<int>(i => i == SUB_CHANNEL_ID))).Returns(new Channel { Id = SUB_CHANNEL_ID, SupportsCustomCancPolicy = true, ChannelType = ChannelTypeEnum.Channel }); businessChannelOptInDao.Setup(b => b.UpdatePrePaySettings(It.IsAny<BusinessChannelOptIn>())).Returns(true); prePayDao.Setup(cc => cc.GetPermittedChannelSettings(BUSINESS_ID, CHANNEL_ID)) .Returns(new List<ChannelPrePayPermittedSetting> { new ChannelPrePayPermittedSetting { ChannelId = CHANNEL_ID, Type = PrePayRuleTypeEnum.Amount, Min = 1, Max = 100 } }); eventTrackingManager.Setup( e => e.CreateBusinessEventAsync(It.Is<long>(i => i == BUSINESS_ID), It.Is<BusinessEventTypesEnum>(i => i == BusinessEventTypesEnum.OptinChannelModified), It.Is<string>(i => i == CHANNEL_ID.ToString(CultureInfo.InvariantCulture)), It.IsAny<string>())); eventTrackingManager.Setup( e => e.CreateBusinessEventAsync(It.Is<long>(i => i == BUSINESS_ID), It.Is<BusinessEventTypesEnum>(i => i == BusinessEventTypesEnum.OptinChannelModified), It.Is<string>(i => i == SUB_CHANNEL_ID.ToString(CultureInfo.InvariantCulture)), It.IsAny<string>())); var businessChannelOptIn = new BusinessChannelOptIn { ChannelId = CHANNEL_ID, BusinessId = BUSINESS_ID, ChannelTermsId = CHANNEL_TERMS_ID, PrePaySettings = new BusinessChannelPrePaySettings { Type = PrePayRuleTypeEnum.Amount, Value = 10 } }; var subChannels = new List<int> { SUB_CHANNEL_ID }; businessChannelOptInDao.Setup(b => b.GetOptedInChannelsRelatedToGroup(BUSINESS_ID, CHANNEL_ID)) .Returns(subChannels); // Act var result = distributionManager.UpdatePrePayForOptedInChannel(businessChannelOptIn); // Assert Assert.IsTrue(result, "Update for channel prepay settings was not successful"); channelDao.VerifyAll(); businessChannelOptInDao.Verify(bco => bco.UpdatePrePaySettings(It.IsAny<BusinessChannelOptIn>()), Times.Exactly(2)); eventTrackingManager.Verify( et => et.CreateBusinessEventAsync(It.IsAny<long>(), BusinessEventTypesEnum.OptinChannelModified, It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2)); prePayDao.Verify(cc => cc.GetPermittedChannelSettings(It.IsAny<long>(), It.IsAny<int>()), Times.Once); }