public void UpdateCancellationForOptedInChannelInvalidTermsUpdateThrowsValidationException(TestData testData)
            {
                // Arrange
                const int CHANNEL_ID = 1;
                const long BUSINESS_ID = 1;
                const int CHANNEL_TERMS_ID = 1;

                var channelDao = new Mock<IChannelDao>();
                var channelTermsDao = new Mock<IChannelCancellationTermsDao>();

                var distributionManager = new DistributionManager
                {
                    ChannelDao = channelDao.Object,
                    ChannelCancellationTermsDao = channelTermsDao.Object
                };

                channelDao.Setup(c => c.GetById(It.Is<int>(i => i == CHANNEL_ID))).Returns(new Channel
                {
                    Id = CHANNEL_ID,
                    SupportsCustomCancPolicy = true
                });

                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    ChannelId = CHANNEL_ID,
                    BusinessId = BUSINESS_ID,
                    ChannelTermsId = CHANNEL_TERMS_ID,
                    CancellationValues = new CancellationValues
                    {
                        CancellationChargeType = new CancellationChargeType
                        {
                            Type = testData.chargeTypeToUse
                        },
                        CancellationWindowHours = testData.windowHoursToUse,
                        CancellationChargeValue = testData.chargeValueToUse
                    }
                };

                // set up terms here
                var channelTerms = new ChannelCancellationTerms
                    {
                        ChannelId = CHANNEL_ID,
                        AcceptedChargeTypes = new List<CancellationChargeTypeEnum> { testData.acceptableChargeType },
                        MinChargeValue = testData.minChargeValue,
                        MaxChargeValue = testData.maxChargeValue,
                        ChargeValueMultiple = testData.chargeMultiple,
                        MinChargePercentage = testData.minPercentValue,
                        MaxChargePercentage = testData.maxPercentValue,
                        ChargePercentageMultiple = testData.percentMultiple,
                        WindowMinValue = testData.windowMinValue,
                        WindowMaxValue = testData.windowMaxValue
                    };

                channelTermsDao.Setup(ct => ct.GetByBusiness(It.IsAny<long>())).Returns(new List<ChannelCancellationTerms> {channelTerms});

                // Act
                try
                {
                    distributionManager.UpdateCancellationForOptedInChannel(businessChannelOptIn);
                    Assert.Fail("Validation exception SRVEX30132 was not thrown");
                }
                catch (ValidationException ex)
                {
                    Assert.AreEqual("SRVEX30132", ex.Code, "SRVEX30132 was not thrown");
                    channelDao.VerifyAll();
                    channelTermsDao.VerifyAll();
                }
            }
            public void UpdateCancellationForOptedInInvalidChannelThrowsValidationException()
            {
                // Arrange
                const int CHANNEL_ID = 1;
                const long BUSINESS_ID = 1;

                var distributionManager = new DistributionManager();

                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    ChannelId = CHANNEL_ID,
                    BusinessId = BUSINESS_ID,
                    CancellationValues = new CancellationValues()
                };

                // Act
                try
                {
                    distributionManager.UpdateCancellationForOptedInChannel(businessChannelOptIn);
                }
                catch (ValidationException ex)
                {
                    Assert.AreEqual("SRVEX30080", ex.Code, "SRVEX30080 was not thrown");
                }
            }
            public void UpdateCancellationForOptedInChannelDoesntSupportUpdateThrowsValidationException()
            {
                // Arrange
                const int CHANNEL_ID = 1;
                const long BUSINESS_ID = 1;
                const int CHANNEL_TERMS_ID = 1;

                var channelDao = new Mock<IChannelDao>();
                
                var distributionManager = new DistributionManager
                {
                    ChannelDao = channelDao.Object
                };

                channelDao.Setup(c => c.GetById(It.Is<int>(i => i == CHANNEL_ID))).Returns(new Channel
                {
                    Id = CHANNEL_ID,
                    SupportsCustomCancPolicy = false
                });

                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    ChannelId = CHANNEL_ID,
                    BusinessId = BUSINESS_ID,
                    ChannelTermsId = CHANNEL_TERMS_ID,
                    CancellationValues = new CancellationValues()
                };

                // Act
                try
                {
                    distributionManager.UpdateCancellationForOptedInChannel(businessChannelOptIn);
                }
                catch (ValidationException ex)
                {
                    Assert.AreEqual("SRVEX30131", ex.Code, "SRVEX30131 was not thrown");
                    channelDao.VerifyAll();
                }
            }
            public void UpdateCancellationForOptedInGroupChannelCallsCorrectMethods()
            {
                // 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 channelCancelTermsDao = new Mock<IChannelCancellationTermsDao>();

                var distributionManager = new DistributionManager
                {
                    BusinessChannelOptInDao = businessChannelOptInDao.Object,
                    ChannelDao = channelDao.Object,
                    EventTrackingManager = eventTrackingManager.Object,
                    ChannelCancellationTermsDao = channelCancelTermsDao.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.UpdateCancellation(It.IsAny<BusinessChannelOptIn>())).Returns(true);

                channelCancelTermsDao.Setup(cc => cc.GetByBusiness(BUSINESS_ID)).Returns(new List<ChannelCancellationTerms>
                    {
                        new ChannelCancellationTerms
                        {
                            ChannelId = CHANNEL_ID
                        },
                        new ChannelCancellationTerms
                        {
                            ChannelId = SUB_CHANNEL_ID
                        }
                    });

                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>()));

                List<int> sub_channels = new List<int>
                    {
                        SUB_CHANNEL_ID
                    };

                businessChannelOptInDao.Setup(b => b.GetOptedInChannelsRelatedToGroup(BUSINESS_ID, CHANNEL_ID))
                                       .Returns(sub_channels);

                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    ChannelId = CHANNEL_ID,
                    BusinessId = BUSINESS_ID,
                    ChannelTermsId = CHANNEL_TERMS_ID,
                    CancellationValues = new CancellationValues()
                };

                // Act
                var result = distributionManager.UpdateCancellationForOptedInChannel(businessChannelOptIn);

                // Assert
                Assert.IsTrue(result, "Update for channel cancellation was not successful");
                channelDao.VerifyAll();
                businessChannelOptInDao.Verify(bco => bco.UpdateCancellation(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));

                // only need group terms
                channelCancelTermsDao.Verify(cc => cc.GetByBusiness(It.IsAny<long>()), Times.Once);
            }