public void ValidatePrePayCancelSettingsReturnsTrueWhenValid(CancellationValues cancelValues, decimal? prePayValue, PrePayRuleTypeEnum ruleType, bool result) { // Arrange Model.Business.Business business = new Model.Business.Business { CancellationValues = cancelValues, PrePayRuleValue = prePayValue, PrePayRuleType = ruleType }; // Act bool actualResult = businessManager.ValidatePrePayCancelSettingsForBusiness(business); // Assert Assert.AreEqual(result, actualResult, "Validation did not match expected"); }
/// <summary> /// Update prepay settings for an opted in channel /// </summary> /// <param name="businessId">Business Id</param> /// <param name="type">PrePay Rule Type</param> /// <param name="prePayValue">PrePay Value</param> /// <returns>True if the update was successful</returns> public void UpdateDefaultPrePaySettingsForBusiness(long businessId, PrePayRuleTypeEnum type, decimal prePayValue) { const string SQL = @" -- Update main channels first UPDATE Distribution.BusinessChannelOptIn SET UpdatedByUserId = @UpdatedByUserId, PrePayRuleValue = @PrePayRuleValue, PrePayRuleTypeCode = @PrePayRuleTypeCode, IsOverridden = 0 WHERE BusinessId = @BusinessId AND (IsOverridden = 0 OR IsOverridden IS NULL) AND ChannelId IN (SELECT DISTINCT(C.Id) FROM Distribution.Channel C WHERE C.Id IN (SELECT DISTINCT(CPPS.ChannelId) FROM Distribution.ChannelPrePaySettings CPPS LEFT JOIN Distribution.ChannelPrePaySettings CP ON CP.ChannelId = CPPS.ChannelId AND CPPS.Id != CP.Id WHERE CPPS.Min != CPPS.Max OR CP.Id IS NOT NULL)) -- Update any groups second UPDATE Distribution.BusinessChannelOptIn SET UpdatedByUserId = @UpdatedByUserId, PrePayRuleValue = @PrePayRuleValue, PrePayRuleTypeCode = @PrePayRuleTypeCode, IsOverridden = 0 WHERE BusinessId = @BusinessId AND (IsOverridden = 0 OR IsOverridden IS NULL) AND ChannelId IN (SELECT DISTINCT(GL.ChannelId) FROM Distribution.Channel C LEFT JOIN Distribution.ChannelGroupLink GL ON GL.ChannelGroupId = C.Id AND C.ChannelTypeCode != 'C' WHERE C.Id IN (SELECT DISTINCT(CPPS.ChannelId) FROM Distribution.ChannelPrePaySettings CPPS LEFT JOIN Distribution.ChannelPrePaySettings CP ON CP.ChannelId = CPPS.ChannelId AND CPPS.Id != CP.Id WHERE CPPS.Min != CPPS.Max OR CP.Id IS NOT NULL) AND GL.ChannelId IS NOT NULL)"; var parameters = new List<SqlParameter> { DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.BusinessId, businessId), DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.PrePayRuleValue, prePayValue), DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.PrePayRuleTypeCode, type.GetCode()) }; // Add auditing parameters AuditFieldsHelper.PopulateAuditFields(parameters); // Run the update query DbHelper.ExecuteNonQueryCommand(SQL, parameters: parameters); }