コード例 #1
0
            public void CreateBusinessChannelOptInIsSuccessful()
            {
                // Arrange
                const long BUSINESS_ID = 11;

                var businessChannelOptIn = new BusinessChannelOptIn
                    {
                        BusinessId = BUSINESS_ID,
                        ChannelId = 1,
                        ChannelTermsId = 1,
                        ChannelOptInStatus = new ChannelOptInStatus { Code = ChannelOptInStatusEnum.Live.GetCode() },
                        OptInDatetime = DateTime.Now,
                    };

                var setupQueries = new List<string>
                    {
                        GetTestQuery(TestQuery.PopulateBasicChannelTestData),
                        GetTestQuery(TestQuery.PopulateOptInTestData)
                    };
                
                using (new TestDataHelper(setupQueries, GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    // Act
                    businessChannelOptInDao.Create(businessChannelOptIn);

                    // Assert
                    Assert.IsNotNull(businessChannelOptIn.Id, "The created id was not returned.");
                }
            }
コード例 #2
0
 public void CreateBusinessChannelOptInWithNoDataThrowsNullReferenceException()
 {
     // Arrange
     var businessChannelOptIn = new BusinessChannelOptIn();
         
     // Act
     businessChannelOptInDao.Create(businessChannelOptIn);
 }
コード例 #3
0
            public void OptInToChannelInGroupOptsIntoGroupAsWell()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";

                var businessChannelOptInDao = new Mock<IBusinessChannelOptInDao>();
                var eventTrackingManagerMock = new Mock<IEventTrackingManager>();
                var channelDaoMock = new Mock<IChannelDao>();
                var distributionManagerMock = new Mock<DistributionManager>();
                var businessDaoMock = new Mock<IBusinessDao>();
                var prePayDaoMock = new Mock<IPrePayDao>();

                distributionManagerMock.Object.BusinessChannelOptInDao = businessChannelOptInDao.Object;
                distributionManagerMock.Object.EventTrackingManager = eventTrackingManagerMock.Object;
                distributionManagerMock.Object.ChannelDao = channelDaoMock.Object;
                distributionManagerMock.Object.BusinessDao = businessDaoMock.Object;
                distributionManagerMock.Object.PrePayDao = prePayDaoMock.Object;
                distributionManagerMock.CallBase = true;

                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    BusinessId = 1,
                    ChannelId = 1,
                    ChannelTermsId = 1
                };
                var logicalGroupChannelOptIn = new BusinessChannelOptIn
                {
                    BusinessId = 1,
                    ChannelId = 2,
                    ChannelTermsId = 2
                };
                
                Channel nullLogical = null;
                Channel logicalGroupChannel = new Channel
                    {
                        Id = 2,
                        ChannelType = ChannelTypeEnum.LogicalGroup,
                        ChannelTermsId = 2
                    };

                prePayDaoMock.Setup(p => p.GetPermittedChannelSettings(businessChannelOptIn.BusinessId.Value, logicalGroupChannelOptIn.ChannelId.Value)).Returns(new List<ChannelPrePayPermittedSetting>
                                                                                                                                                                 {
                                                                                                                                                                     new ChannelPrePayPermittedSetting
                                                                                                                                                                         {
                                                                                                                                                                             Type = PrePayRuleTypeEnum.Nights,
                                                                                                                                                                             Min = 1,
                                                                                                                                                                             Max = 5
                                                                                                                                                                         }
                                                                                                                                                                 });

                businessDaoMock.Setup(b => b.GetByKey(businessChannelOptIn.BusinessId.Value, It.IsAny<string>())).Returns(new Model.Business.Business
                {
                    Id = logicalGroupChannelOptIn.BusinessId.Value,
                    PrePayRuleValue = 5,
                    PrePayRuleType = PrePayRuleTypeEnum.Nights
                });
                businessChannelOptInDao.Setup(dao => dao.Create(It.Is<BusinessChannelOptIn>(bco => bco.BusinessId == businessChannelOptIn.BusinessId && bco.ChannelId == businessChannelOptIn.ChannelId && bco.ChannelTermsId == businessChannelOptIn.ChannelTermsId))).Callback(delegate { businessChannelOptIn.Id = 1; });
                businessChannelOptInDao.Setup(dao => dao.Create(It.Is<BusinessChannelOptIn>(bco => bco.BusinessId == logicalGroupChannelOptIn.BusinessId && bco.ChannelId == logicalGroupChannelOptIn.ChannelId && bco.ChannelTermsId == logicalGroupChannelOptIn.ChannelTermsId))).Callback(delegate { logicalGroupChannelOptIn.Id = 2; });
                
                channelDaoMock.Setup(ch => ch.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value))
                              .Returns(logicalGroupChannel);

                // logical group isn't in a group
                channelDaoMock.Setup(ch => ch.GetById(logicalGroupChannelOptIn.ChannelId.Value)).Returns(new Channel
                {
                    Id = logicalGroupChannel.Id,
                    SupportsCustomCancPolicy = false
                });
                channelDaoMock.Setup(ch => ch.GetFirstLogicalGroupChannelByChannelId(logicalGroupChannel.Id))
                              .Returns(nullLogical);
                
                // show it isn't opted in to group
                businessChannelOptInDao.Setup(
                    bc => bc.IsChannelOptedInForBusiness(businessChannelOptIn.BusinessId.Value, logicalGroupChannel.Id))
                                       .Returns(false);
                businessChannelOptInDao.Setup(dao => dao.UpdatePrePaySettings(It.IsAny<BusinessChannelOptIn>()));
                
                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId),
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptIn),
                                                It.IsAny<string>(), It.IsAny<string>()));

                distributionManagerMock.Setup(dmm => dmm.UpdateGroupChannelsWithCancelPrepaySettings(logicalGroupChannel, businessChannelOptIn, It.IsAny<string>()));

                // Act
                distributionManagerMock.Object.OptInToChannel(businessChannelOptIn, CULTURE_CODE);

                // Assert
                Assert.AreEqual(ChannelOptInStatusEnum.Live.GetCode(), businessChannelOptIn.ChannelOptInStatus.Code, "The channel opt in status code is incorrect.");
                Assert.AreEqual(1, businessChannelOptIn.Id, "The id returned is incorrect.");
                Assert.AreEqual(2, logicalGroupChannelOptIn.Id, "logical group was not opted in.");

                channelDaoMock.VerifyAll();
                businessChannelOptInDao.VerifyAll();
                eventTrackingManagerMock.Verify(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId),
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptIn),
                                                It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
                distributionManagerMock.VerifyAll();
                prePayDaoMock.VerifyAll();
                businessDaoMock.VerifyAll();

                // Reset the Daos
                distributionManager.BusinessChannelOptInDao = new BusinessChannelOptInDao();
            }
コード例 #4
0
            public void OptInToChannelCallsCorrectMethods()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";

                var businessChannelOptInDao = new Mock<IBusinessChannelOptInDao>();
                var eventTrackingManagerMock = new Mock<IEventTrackingManager>();
                var channelDaoMock = new Mock<IChannelDao>();
                var businessDaoMock = new Mock<IBusinessDao>();
                var prePayDaoMock = new Mock<IPrePayDao>();

                distributionManager.BusinessChannelOptInDao = businessChannelOptInDao.Object;
                distributionManager.EventTrackingManager = eventTrackingManagerMock.Object;
                distributionManager.ChannelDao = channelDaoMock.Object;
                distributionManager.BusinessDao = businessDaoMock.Object;
                distributionManager.PrePayDao = prePayDaoMock.Object;

                var businessChannelOptIn = new BusinessChannelOptIn
                    {
                        BusinessId = 1,
                        ChannelId = 1,
                        ChannelTermsId = 1
                    };
                Channel nullLogical = null;

                prePayDaoMock.Setup(p => p.GetPermittedChannelSettings(businessChannelOptIn.BusinessId.Value, businessChannelOptIn.ChannelId.Value)).Returns(new List<ChannelPrePayPermittedSetting>
                                                                                                                                                                 {
                                                                                                                                                                     new ChannelPrePayPermittedSetting
                                                                                                                                                                         {
                                                                                                                                                                             Type = PrePayRuleTypeEnum.Nights,
                                                                                                                                                                             Min = 1,
                                                                                                                                                                             Max = 5
                                                                                                                                                                         }
                                                                                                                                                                 });

                businessDaoMock.Setup(b => b.GetByKey(businessChannelOptIn.BusinessId.Value, It.IsAny<string>())).Returns(new Model.Business.Business
                                                                                                          {
                                                                                                              Id = businessChannelOptIn.BusinessId.Value,
                                                                                                              PrePayRuleValue = 5,
                                                                                                              PrePayRuleType = PrePayRuleTypeEnum.Nights
                                                                                                          });
                businessChannelOptInDao.Setup(dao => dao.Create(businessChannelOptIn)).Callback(delegate { businessChannelOptIn.Id = 1; });
                businessChannelOptInDao.Setup(dao => dao.UpdatePrePaySettings(businessChannelOptIn));
                channelDaoMock.Setup(ch => ch.GetById(businessChannelOptIn.ChannelId.Value)).Returns(new Channel
                                                                                                         {
                                                                                                             Id = businessChannelOptIn.ChannelId.Value,
                                                                                                             SupportsCustomCancPolicy = false
                                                                                                         });
                channelDaoMock.Setup(ch => ch.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value)).Returns(nullLogical);

                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId), 
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptIn), 
                                                It.IsAny<string>(), It.IsAny<string>()));

                // Act
                distributionManager.OptInToChannel(businessChannelOptIn, CULTURE_CODE);

                // Assert
                Assert.AreEqual(ChannelOptInStatusEnum.Live.GetCode(), businessChannelOptIn.ChannelOptInStatus.Code, "The channel opt in status code is incorrect.");
                Assert.AreEqual(1, businessChannelOptIn.Id, "The id returned is incorrect.");
                eventTrackingManagerMock.VerifyAll();
                channelDaoMock.VerifyAll();
                businessChannelOptInDao.VerifyAll();
                prePayDaoMock.VerifyAll();
                businessDaoMock.VerifyAll();

                // Reset the Daos
                distributionManager.BusinessChannelOptInDao = new BusinessChannelOptInDao();
            }
コード例 #5
0
        /// <summary>
        /// Create a new BusinessChannelOptIn record
        /// </summary>
        /// <param name="businessChannelOptIn">The BusinessChannelOptIn to create</param>
        public void Create(BusinessChannelOptIn businessChannelOptIn)
        {
            const string SQL_STATEMENT = @"
                INSERT INTO Distribution.BusinessChannelOptIn
                (
                        BusinessId,
                        ChannelId,
                        ChannelTermsId,
                        OptInDatetime,
                        MembershipReference,
                        ChannelOptInStatusCode,
                        UpdatedByUserId,
                        CurrencyCode
                )
                VALUES
                (
                        @BusinessId,
                        @ChannelId,
                        @ChannelTermsId,
                        @OptInDatetime,
                        @MembershipReference,
                        @ChannelOptInStatusCode,
                        @UpdatedByUserId,
                        @CurrencyCode
                )
                SELECT @Id = SCOPE_IDENTITY()";

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.BusinessId, businessChannelOptIn.BusinessId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.ChannelId, businessChannelOptIn.ChannelId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.ChannelTermsId, businessChannelOptIn.ChannelTermsId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.OptInDatetime, businessChannelOptIn.OptInDatetime),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.MembershipReference, businessChannelOptIn.MembershipReference),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.ChannelOptInStatusCode, businessChannelOptIn.ChannelOptInStatus.Code),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.CurrencyCode, businessChannelOptIn.CurrencyCode)
                };


            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);
            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(BusinessChannelOptInMapper.Parameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
            
            // Make sure the record was created
            if (outputKey.Value == DBNull.Value)
            {
                throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30022, "BusinessChannelOptInDao.Create",
                    additionalDescriptionParameters: (new object[] { businessChannelOptIn.BusinessId, businessChannelOptIn.ChannelId })));
            }

            businessChannelOptIn.Id = DbHelper.ParameterValue<int>(outputKey);
        }
コード例 #6
0
            public void UpdateCancellationIsSuccessful()
            {
                const string CHANNEL_NAME = "toprooms";
                const int BUSINESS_ID = 5001;

                // Arrange
                var channel = channelDao.GetChannelByShortName(CHANNEL_NAME);

                var optIn = new BusinessChannelOptIn
                                {
                                    BusinessId = BUSINESS_ID,
                                    ChannelId = channel.Id,
                                    CancellationValues = new CancellationValues
                                                             {
                                                                 CancellationChargeType = new CancellationChargeType
                                                                                              {
                                                                                                  Code = "FN"
                                                                                              },
                                                                 CancellationChargeValue = 100,
                                                                 CancellationType = new CancellationType
                                                                                        {
                                                                                            Code = "FF"
                                                                                        },
                                                                 CancellationWindowHours = 48
                                                             }
                                };


                // Act
                var result = businessChannelOptInDao.UpdateCancellation(optIn);

                // Assert
                Assert.IsTrue(result, "Opt in cancellation values were not updated");
            }
コード例 #7
0
ファイル: DistributionManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// for a given new opt in, update cancel / prepay info for it based on logical group info
        /// </summary>
        /// <param name="businessChannelOptIn">opt in info for channel being opted in</param>
        /// <param name="cultureCode">culture info</param>
        /// <param name="logicalGroup">channel of the group</param>
        public virtual void UpdateGroupChannelsWithCancelPrepaySettings(Channel logicalGroup, BusinessChannelOptIn businessChannelOptIn, string cultureCode)
        {
            if (logicalGroup != null)
            {
                BusinessChannelOptIn optInToModify =
                    businessChannelOptInDao.GetOptInByBusinessAndChannel(businessChannelOptIn.BusinessId.Value,
                                                                         logicalGroup.Id, cultureCode);

                // get cancel info based on group
                var channelTermsList = channelCancellationTermsDao.GetByBusiness(businessChannelOptIn.BusinessId.Value);
                var channelTerms = channelTermsList.FirstOrDefault(ct => ct.ChannelId == logicalGroup.Id);

                // get prepay info based on group
                var prePaySettings = prePayDao.GetPermittedChannelSettings(businessChannelOptIn.BusinessId.Value, logicalGroup.Id);
                optInToModify.ChannelId = businessChannelOptIn.ChannelId;
                optInToModify.ChannelTermsId = businessChannelOptIn.ChannelTermsId;

                // cancellation update
                UpdateCancellationForOptedInChannel(optInToModify, channelTerms);

                // prepay update
                UpdatePrePayForOptedInChannel(optInToModify, prePaySettings);
            }
        }
コード例 #8
0
ファイル: DistributionManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Opt in to a channel
        /// </summary>
        /// <param name="businessChannelOptIn">The businessChannelOptIn object to create</param>
        /// <param name="cultureCode">The culture code used for translations</param>
        public void OptInToChannel(BusinessChannelOptIn businessChannelOptIn, string cultureCode )
        {
            var prePaySettings = new BusinessChannelPrePaySettings();
            Channel logicalGroup = null;

            using (var tx = new BusinessTransaction())
            {
                if (businessChannelOptIn.IsValid())
                {
                    businessChannelOptIn.ChannelOptInStatus = new ChannelOptInStatus
                    {
                        Code = ChannelOptInStatusEnum.Live.GetCode()
                    };
                    businessChannelOptIn.OptInDatetime = DateTime.UtcNow;
                   
                    businessChannelOptInDao.Create(businessChannelOptIn);

                    // Record business event
                    eventTrackingManager.CreateBusinessEventAsync(businessChannelOptIn.BusinessId.Value, BusinessEventTypesEnum.ChannelOptIn, businessChannelOptIn.ChannelId.ToString());

                    logicalGroup = channelDao.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value);

                    if (logicalGroup == null)
                    {
                        var channel = channelDao.GetById(businessChannelOptIn.ChannelId.Value);                        
                        var business = businessDao.GetByKey(businessChannelOptIn.BusinessId.Value);

                        var permittedSettings = prePayDao.GetPermittedChannelSettings(businessChannelOptIn.BusinessId.Value, businessChannelOptIn.ChannelId.Value);

                        channel.FullPrePaySettings = new ChannelPrePaySettings
                        {
                            PermittedSettings = permittedSettings
                        };

                        // if the channel isnt flexible use the channel defaults otherwise use the business defaults
                        if (!channel.FullPrePaySettings.Flexible)
                        {
                            if (channel.DefaultPrePayType.HasValue && channel.DefaultPrePayValue.HasValue)
                            {
                                prePaySettings.Type = channel.DefaultPrePayType.Value;
                                prePaySettings.Value = channel.DefaultPrePayValue.Value;
                                prePaySettings.IsOverridden = false;
                            }
                        }
                        else
                        {
                            if (business.PrePayRuleValue.HasValue)
                            {
                                prePaySettings.Type = business.PrePayRuleType;
                                prePaySettings.Value = business.PrePayRuleValue.Value;
                                prePaySettings.IsOverridden = false;
                            }
                        }

                        businessChannelOptIn.PrePaySettings = prePaySettings;                    

                        // Update pre pay settings on Opt In
                        UpdatePrePayForOptedInChannel(businessChannelOptIn, permittedSettings);
                    }

                    tx.Commit();
                }
            }

            // update logical group channel to opt into if needed
            if (businessChannelOptIn.IsValid() && logicalGroup != null)
            {
                    // if not already opted in, opt the logical group channel in
                    if (businessChannelOptInDao.IsChannelOptedInForBusiness(businessChannelOptIn.BusinessId.Value, logicalGroup.Id) == false)
                    {
                        BusinessChannelOptIn bco = new BusinessChannelOptIn
                    {
                        BusinessId = businessChannelOptIn.BusinessId.Value,
                        ChannelId = logicalGroup.Id,
                        ChannelTermsId = logicalGroup.ChannelTermsId ?? businessChannelOptIn.ChannelTermsId.Value,
                        PrePaySettings = prePaySettings
                    };
                        OptInToChannel(bco, cultureCode);
                    }

                    // in all cases, update this channel with info from logical group
                    // need to update cancel / ppy info here based on logical group settings
                    UpdateGroupChannelsWithCancelPrepaySettings(logicalGroup, businessChannelOptIn, cultureCode);
                }
            }
コード例 #9
0
            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);
            }
コード例 #10
0
            public void OptOutOfChannelNotInGroupOptsOutOnlyChannel()
            {
                // Arrange
                var businessChannelOptInDao = new Mock<IBusinessChannelOptInDao>();
                var eventTrackingManagerMock = new Mock<IEventTrackingManager>();
                var channelDaoMock = new Mock<IChannelDao>();

                distributionManager.BusinessChannelOptInDao = businessChannelOptInDao.Object;
                distributionManager.EventTrackingManager = eventTrackingManagerMock.Object;
                distributionManager.ChannelDao = channelDaoMock.Object;

                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    BusinessId = 1,
                    ChannelId = 1,
                    ChannelTermsId = 1
                };

                Channel nullLogical = null;
                
                businessChannelOptInDao.Setup(
                    dao => dao.Remove(businessChannelOptIn.BusinessId.Value, businessChannelOptIn.ChannelId.Value));

                channelDaoMock.Setup(ch => ch.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value))
                              .Returns(nullLogical);

                // logical group isn't in a group
                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId),
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptOut),
                                                It.IsAny<string>(), It.IsAny<string>()));

                // Act
                distributionManager.OptOutOfChannel(businessChannelOptIn);

                // Assert
                channelDaoMock.VerifyAll();
                businessChannelOptInDao.VerifyAll();
                eventTrackingManagerMock.Verify(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId),
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptOut),
                                                It.IsAny<string>(), It.IsAny<string>()), Times.Once);

                // Reset the Daos
                distributionManager.BusinessChannelOptInDao = new BusinessChannelOptInDao();
            }
コード例 #11
0
            public void OptOutOfLastChannelInGroupOptsOutGroupAsWell()
            {
                // Arrange
                var businessChannelOptInDao = new Mock<IBusinessChannelOptInDao>();
                var eventTrackingManagerMock = new Mock<IEventTrackingManager>();
                var channelDaoMock = new Mock<IChannelDao>();
                
                distributionManager.BusinessChannelOptInDao = businessChannelOptInDao.Object;
                distributionManager.EventTrackingManager = eventTrackingManagerMock.Object;
                distributionManager.ChannelDao = channelDaoMock.Object;
                
                var businessChannelOptIn = new BusinessChannelOptIn
                {
                    BusinessId = 1,
                    ChannelId = 1,
                    ChannelTermsId = 1
                };
                var logicalGroupChannelOptIn = new BusinessChannelOptIn
                {
                    BusinessId = 1,
                    ChannelId = 2,
                    ChannelTermsId = 2
                };

                Channel nullLogical = null;
                Channel logicalGroupChannel = new Channel
                {
                    Id = 2,
                    ChannelType = ChannelTypeEnum.LogicalGroup,
                    ChannelTermsId = 2
                };

                businessChannelOptInDao.Setup(
                    dao => dao.Remove(businessChannelOptIn.BusinessId.Value, businessChannelOptIn.ChannelId.Value));

                businessChannelOptInDao.Setup(
                    dao => dao.Remove(logicalGroupChannelOptIn.BusinessId.Value, logicalGroupChannelOptIn.ChannelId.Value));

                channelDaoMock.Setup(ch => ch.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value))
                              .Returns(logicalGroupChannel);

                businessChannelOptInDao.Setup(
                    bc =>
                    bc.GetOptedInChannelsRelatedToGroup(businessChannelOptIn.BusinessId.Value, logicalGroupChannel.Id))
                                       .Returns
                    (new List<int>
                        {
                            businessChannelOptIn.ChannelId.Value
                        });

                // logical group isn't in a group
                channelDaoMock.Setup(ch => ch.GetFirstLogicalGroupChannelByChannelId(logicalGroupChannel.Id))
                              .Returns(nullLogical);

                
                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId),
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptOut),
                                                It.IsAny<string>(), It.IsAny<string>()));

                // Act
                distributionManager.OptOutOfChannel(businessChannelOptIn);

                // Assert
                channelDaoMock.VerifyAll();
                businessChannelOptInDao.VerifyAll();
                eventTrackingManagerMock.Verify(be => be.CreateBusinessEventAsync(It.Is<long>(l => l == businessChannelOptIn.BusinessId),
                                                It.Is<BusinessEventTypesEnum>(ev => ev == BusinessEventTypesEnum.ChannelOptOut),
                                                It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
                
                // Reset the Daos
                distributionManager.BusinessChannelOptInDao = new BusinessChannelOptInDao();
            }
コード例 #12
0
            public void OptInToChannelWithInvalidDataThrowsException()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";

                var businessChannelOptIn = new BusinessChannelOptIn();

                // Act
                try
                {
                    // Act
                    distributionManager.OptInToChannel(businessChannelOptIn, CULTURE_CODE);

                    // Assert
                    Assert.Fail("An exception SRVEX30080 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30080.ToString(), ex.Code, "The Validation exception is not returning the right error code");
                }
            }
コード例 #13
0
        /// <summary>
        /// Update cancellation information for an opted in channel
        /// </summary>
        /// <param name="businessChannelOptIn">opted in channel</param>
        /// <returns>True if the update was successful</returns>
        public bool UpdateCancellation(BusinessChannelOptIn businessChannelOptIn)
        {
            const string SQL = @"
                                UPDATE Distribution.BusinessChannelOptIn
                                SET
                                        UpdatedByUserId = @UpdatedByUserId,
                                        CancellationTypeCode = @CancellationTypeCode,
                                        CancellationChargeTypeCode = @CancellationChargeTypeCode,
                                        CancellationWindowHours = @CancellationWindowHours,
                                        CancellationChargeValue = @CancellationChargeValue
                                WHERE
                                        BusinessId = @BusinessId and ChannelId = @ChannelId";
            
            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.BusinessId, businessChannelOptIn.BusinessId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.ChannelId, businessChannelOptIn.ChannelId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.CancellationTypeCode, businessChannelOptIn.CancellationValues.CancellationType.Code),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.CancellationChargeValue, businessChannelOptIn.CancellationValues.CancellationChargeValue),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.CancellationWindowHours, businessChannelOptIn.CancellationValues.CancellationWindowHours),

                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.CancellationChargeTypeCode, businessChannelOptIn.CancellationValues.CancellationChargeType != null ? businessChannelOptIn.CancellationValues.CancellationChargeType.Code : null)

                };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            return DbHelper.ExecuteNonQueryCommand(SQL, parameters: parameters) == 1;
        }
コード例 #14
0
        /// <summary>
        /// Update prepay settings for an opted in channel
        /// </summary>
        /// <param name="businessChannelOptIn">opted in channel</param>
        /// <returns>True if the update was successful</returns>
        public bool UpdatePrePaySettings(BusinessChannelOptIn businessChannelOptIn)
        {
            const string SQL = @"
                                UPDATE Distribution.BusinessChannelOptIn
                                SET
                                        UpdatedByUserId = @UpdatedByUserId,
                                        PrePayRuleValue = @PrePayRuleValue,
                                        PrePayRuleTypeCode = @PrePayRuleTypeCode,
                                        IsOverridden = @IsOverridden
                                WHERE
                                        BusinessId = @BusinessId and ChannelId = @ChannelId";

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.BusinessId, businessChannelOptIn.BusinessId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.ChannelId, businessChannelOptIn.ChannelId),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.PrePayRuleValue, businessChannelOptIn.PrePaySettings.Value),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.PrePayRuleTypeCode, businessChannelOptIn.PrePaySettings.Type.GetCode()),
                    DbHelper.CreateParameter(BusinessChannelOptInMapper.Parameters.IsOverridden, businessChannelOptIn.PrePaySettings.IsOverridden)
                };


            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            return DbHelper.ExecuteNonQueryCommand(SQL, parameters: parameters) == 1;
        }
コード例 #15
0
ファイル: DistributionManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Modify Channel PrePay Settings
        /// </summary>
        /// <param name="channelOptIn">Channel Opt In Record</param>
        /// <param name="permittedSettings">settings permitted</param>
        /// <returns>True if created</returns>
        public bool UpdatePrePayForOptedInChannel(BusinessChannelOptIn channelOptIn, List<ChannelPrePayPermittedSetting> permittedSettings = null)
        {
            var success = false;

            if (channelOptIn.IsValid() && channelOptIn.PrePaySettings != null)
            {
                // verify they can edit prepay details
                var currentChannel = channelDao.GetById(channelOptIn.ChannelId.Value);

                if (currentChannel == null)
                {
                    //throw error if we cannot find the channel
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30130,
                                                                                 "DistributionManager.UpdatePrePayForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[] { channelOptIn.ChannelId.Value },
                                                                                 arguments: new object[] { channelOptIn }));
                }

                // retrieve settings if null (will be not null when validating for a group channel as will be supplied below)
                if (permittedSettings == null)
                {
                    permittedSettings = prePayDao.GetPermittedChannelSettings(channelOptIn.BusinessId.Value, channelOptIn.ChannelId.Value);
                }

                var suppliedSetting = channelOptIn.PrePaySettings;
                if (suppliedSetting.Type != PrePayRuleTypeEnum.Unknown)
                {
                var permittedSetting = permittedSettings.First(c => c.Type == suppliedSetting.Type);

                // if supplied values are not valid then throw exception
                if (suppliedSetting.Value < permittedSetting.Min || suppliedSetting.Value > permittedSetting.Max)
                {
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30135,
                                                                                 "DistributionManager.UpdatePrePayForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[] { currentChannel.ShortName },
                                                                                 arguments:
                                                                                     new object[] { currentChannel.ShortName }));
                }

                using (var tx = new BusinessTransaction())
                {
                    success = businessChannelOptInDao.UpdatePrePaySettings(channelOptIn);

                    tx.Commit();
                }

                // Record business event
                eventTrackingManager.CreateBusinessEventAsync(channelOptIn.BusinessId.Value, BusinessEventTypesEnum.OptinChannelModified, channelOptIn.ChannelId.Value.ToString(CultureInfo.InvariantCulture), string.Format("{0} - {1}", suppliedSetting.Type, suppliedSetting.Value));


                // if not a channel (so a group) update the related channels
                if (currentChannel.ChannelType != ChannelTypeEnum.Channel)
                {
                    // update the opted in related channels with this info as well
                    var channelIds = businessChannelOptInDao.GetOptedInChannelsRelatedToGroup(channelOptIn.BusinessId.Value, currentChannel.Id);

                    if (channelIds != null && channelIds.Any())
                    {
                        foreach (var channelId in channelIds)
                        {
                            channelOptIn.ChannelId = channelId;
                            UpdatePrePayForOptedInChannel(channelOptIn, permittedSettings); // update the sub-channel validating against permitted settings for the group channel
                        }
                    }
                    }                    
                }
            }

            return success;
        }
コード例 #16
0
ファイル: DistributionManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// update cancellation information for an opted in channel
        /// </summary>
        /// <param name="channelTerms">channel cancel terms to use</param>
        /// <param name="channelUpdateInfo">data to change</param>
        public bool UpdateCancellationForOptedInChannel(BusinessChannelOptIn channelUpdateInfo, ChannelCancellationTerms channelTerms = null)
        {
            var result = false;

            if (channelUpdateInfo.IsValid() &&
                channelUpdateInfo.CancellationValues != null)
            {
                // verify they can edit cancellation details
                Channel currentChannel = channelDao.GetById(channelUpdateInfo.ChannelId.Value);

                if (currentChannel == null)
                {
                    //throw error if we cannot find the channel
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30130,
                                                                                 "DistributionManager.UpdateCancellationForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[]
                                                                                         {
                                                                                             channelUpdateInfo.ChannelId
                                                                                                              .Value
                                                                                         },
                                                                                 arguments:
                                                                                     new object[] { channelUpdateInfo }));
                }

                if (currentChannel.SupportsCustomCancPolicy == false)
                {
                    //throw error if we don't support custom cancel
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30131,
                                                                                 "DistributionManager.UpdateCancellationForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[] { currentChannel.ShortName },
                                                                                 arguments:
                                                                                     new object[] { currentChannel.ShortName }));
                }

                // get restrictions for editing here
                List<ChannelCancellationTerms> ListOfChannelTerms = null;
                if (channelTerms == null)
                {
                    ListOfChannelTerms = channelCancellationTermsDao.GetByBusiness(channelUpdateInfo.BusinessId.Value);
                    channelTerms = ListOfChannelTerms.FirstOrDefault(ct => ct.ChannelId == currentChannel.Id);
                }
                //channel terms would be null if the business is not subscribed to the channel
                if (channelTerms != null)
                {
                    // set the terms to the channels
                    currentChannel.ChannelCancellationTerms = channelTerms;


                    if (channelUpdateInfo.IsCustomCancelValid(currentChannel.ChannelCancellationTerms) == false)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30132,
                                                                                     "DistributionManager.UpdateCancellationForOptedInChannel",
                                                                                     additionalDescriptionParameters:
                                                                                         new object[] { currentChannel.ShortName },
                                                                                     arguments:
                                                                                         new object[] { currentChannel.ShortName }));
                    }
                }
               

                using (var tx = new BusinessTransaction())
                {
                    result = businessChannelOptInDao.UpdateCancellation(channelUpdateInfo);

                    // Record business event
                    eventTrackingManager.CreateBusinessEventAsync(channelUpdateInfo.BusinessId.Value,
                                                             BusinessEventTypesEnum.OptinChannelModified,
                                                             channelUpdateInfo.ChannelId.ToString());

                    tx.Commit();
                }

                // if not a channel (so a group) update the related channels
                if (currentChannel.ChannelType != ChannelTypeEnum.Channel)
                {
                    // update the opted in related channels with this info as well
                    List<int> channelIds = businessChannelOptInDao.GetOptedInChannelsRelatedToGroup(channelUpdateInfo.BusinessId.Value, currentChannel.Id);

                    if (channelIds != null &&
                        channelIds.Any())
                    {
                        foreach (int channelId in channelIds)
                        {
                            channelUpdateInfo.ChannelId = channelId;
                            UpdateCancellationForOptedInChannel(channelUpdateInfo, channelTerms); // update the sub-channel
                        }
                    }
                }
            }

            return result;
        }
コード例 #17
0
            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");
                }
            }
コード例 #18
0
ファイル: DistributionManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Opt out of a channel
        /// </summary>
        /// <param name="businessChannelOptIn">The businessChannelOptIn record to delete</param>
        public void OptOutOfChannel(BusinessChannelOptIn businessChannelOptIn)
        {
            Channel logicalGroupChannel =
                channelDao.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value);

            if (logicalGroupChannel != null)
            {
                List<int> numberOptedIn =
                    businessChannelOptInDao.GetOptedInChannelsRelatedToGroup(businessChannelOptIn.BusinessId.Value,
                                                                                   logicalGroupChannel.Id);

                // if this is the last one being opted out, opt out the logical group as well
                if (numberOptedIn != null &&
                    numberOptedIn.Count == 1)
                {
                    OptOutOfChannel(new BusinessChannelOptIn
                        {
                            BusinessId = businessChannelOptIn.BusinessId,
                            ChannelId = logicalGroupChannel.Id
                        });
                }
            }

            using (var tx = new BusinessTransaction())
            {
                businessChannelOptInDao.Remove(businessChannelOptIn.BusinessId.Value, businessChannelOptIn.ChannelId.Value);

                tx.Commit();
            }
            // Record business event
            eventTrackingManager.CreateBusinessEventAsync(businessChannelOptIn.BusinessId.Value, BusinessEventTypesEnum.ChannelOptOut, businessChannelOptIn.ChannelId.ToString());
        }
コード例 #19
0
            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);
            }
コード例 #20
0
        /// <summary>
        /// Map the basic fields for the BusinessChannelOptIn table to the BusinessChannelOptIn model object
        /// </summary>
        /// <param name="record">The SqlDataReader with the executed query result</param>
        /// <param name="mapChannel">if true will map the associated channel as well</param>
        /// <param name="mapCancelValues">if true will map the cancellation values as well</param>
        /// <param name="mapPrePaySettings">if true will map the prepay settings as well</param>
        /// <param name="prefix">a prefix used to identify fields for the BusinessChannelOptIn model  in the resultset if required</param>
        /// <returns>An instance of Model.Distribution.BusinessChannelOptIn</returns>
        internal static BusinessChannelOptIn MapRecord(IDataRecord record, bool mapChannel, bool mapCancelValues, bool mapPrePaySettings, string prefix = "")
        {
            var channelOptin = new BusinessChannelOptIn
            {
                Id = DbHelper.ConvertValue<int?>(record[prefix + Parameters.Id]),
                BusinessId = DbHelper.ConvertValue<long?>(record[prefix + Parameters.BusinessId]),
                ChannelId = DbHelper.ConvertValue<int?>(record[prefix + Parameters.ChannelId]),
                ChannelTermsId = DbHelper.ConvertValue<int?>(record[prefix + Parameters.ChannelTermsId]),
                ChannelOptInStatus = ChannelOptInStatusMapper.MapRecord(record, Parameters.ChannelOptInStatus.ToString()),
                PlatformCode = DbHelper.ConvertEnumValue<ChannelPlatformEnum>(record[prefix + Parameters.PlatformCode.ToString()]),
            };

            if (mapChannel)
            {
                channelOptin.AssociatedChannel = ChannelMapper.MapRecord(record, false);
            }

            if (mapPrePaySettings)
            {
                channelOptin.PrePaySettings = new BusinessChannelPrePaySettings
                                                  {
                                                      Value = DbHelper.ConvertValue<decimal?>(record[prefix + Parameters.PrePayRuleValue]),
                                                      Type = DbHelper.ConvertEnumValue<PrePayRuleTypeEnum>(record[prefix + Parameters.PrePayRuleTypeCode]),
                                                      IsOverridden = DbHelper.ConvertValue<bool?>(record[prefix + Parameters.IsOverridden])
                                                  };
            }

            if (mapCancelValues)
            {
                channelOptin.CancellationValues = new CancellationValues
                {
                    CancellationType = CancellationTypeMapper.MapRecord(record, prefix + ChannelMapper.Parameters.CancellationType.ToString()),
                    CancellationChargeType = CancellationChargeTypeMapper.MapRecord(record, prefix + ChannelMapper.Parameters.CancellationChargeType.ToString()),
                    CancellationChargeValue = DbHelper.ConvertValue<decimal?>(record[prefix + ChannelMapper.Parameters.CancellationChargeValue]),
                    CancellationWindowHours = DbHelper.ConvertValue<int?>(record[prefix + ChannelMapper.Parameters.CancellationWindowHours]),
                };
            }

            
            return channelOptin;
        }
コード例 #21
0
            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");
                }
            }
コード例 #22
0
            public void UpdatePrePayIsSuccessful()
            {
                const string CHANNEL_NAME = "toprooms";
                const int BUSINESS_ID = 5001;

                // Arrange
                var channel = channelDao.GetChannelByShortName(CHANNEL_NAME);


                var channelOptIn = new BusinessChannelOptIn
                                       {
                                           BusinessId = BUSINESS_ID,
                                           ChannelId = channel.Id,
                                           PrePaySettings = new BusinessChannelPrePaySettings
                                                                {
                                                                    IsOverridden = true,
                                                                    Type = PrePayRuleTypeEnum.Amount,
                                                                    Value = 100
                                                                }
                                       };

                // Act
                var result = businessChannelOptInDao.UpdatePrePaySettings(channelOptIn);

                // Assert
                Assert.IsTrue(result, "Opt in prepay values were not updated");
            }
コード例 #23
0
            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();
                }
            }
コード例 #24
0
            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();
                }
            }
コード例 #25
0
ファイル: EcomConverterTest.cs プロジェクト: ognjenm/egle
            public void EagleBusinessToEcomBusinessMapsChannelNames()
            {
                // Arrange
                var channelNames = new List<string> { "Channel1", "Channel3", "Channel3", "Channel4", "Channel5" };

                var createdByUser = new UserExtension { FirstName = "John", LastName = "Doe" };
                var updatedByUser = new UserExtension { FirstName = "Dummy", LastName = "User" };

                const int BUSINESS_ID = 12345;
                const string SYNC_CODE_UK = "UK";
                const string SYNC_CODE_IN = "IN";
                const string CHANNEL_6_NAME = "Channel6";

                var businessChannelOptIn = new BusinessChannelOptIn
                                               {
                                                   BusinessId = BUSINESS_ID,
                                                   PrePaySettings = new BusinessChannelPrePaySettings
                                                                        {
                                                                            Type = PrePayRuleTypeEnum.Amount,
                                                                            Value = 1,
                                                                            BusinessId = BUSINESS_ID
                                                                        }
                                               };

                var eagleBusiness = new Model.Business.Business
                {
                    Id = BUSINESS_ID,
                    Name = "Business 1",
                    ShortName = "Bus1",
                    CreatedByUser = createdByUser,
                    UpdatedByUser = updatedByUser,
                    Distributors = new Collection<Distributor>
                    {
                        new Distributor 
                        { 
                            Channels = new List<Channel>
                            {
                                new Channel { ShortName = channelNames[0], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = channelNames[1], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = channelNames[2], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                            }
                        },
                        new Distributor 
                        { 
                            Channels = new List<Channel>
                            {
                                new Channel { ShortName = channelNames[3], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = channelNames[4], BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_UK},
                                new Channel { ShortName = CHANNEL_6_NAME, BusinessChannelOptIn = businessChannelOptIn, ChannelSynchronizationTypeCode = SYNC_CODE_IN}
                            }
                        }
                    },
                    OnlineBookingScenarios = new Collection<OnlineBookingScenario>(),
                    MerchantDetails = new MerchantDetails(),
                    Provider = new Provider { ContentId = BUSINESS_ID.ToString(CultureInfo.InvariantCulture) }
                };

                // Act
                List<string> missedChannels;
                var ecommBusiness = EcomConverter.EagleBusinessToEcom(eagleBusiness, SYNC_CODE_UK, out missedChannels);

                foreach (var channelName in channelNames)
                {
                    Assert.True(ecommBusiness.Channels.Any(c => c.ChannelName == channelName), string.Format("{0} not found in ecommBusiness.Channels", channelName));
                }

                Assert.False(ecommBusiness.Channels.Any(c => c.ChannelName == CHANNEL_6_NAME), string.Format("{0} found in ecommBusiness.Channels", CHANNEL_6_NAME));

                Assert.IsTrue(missedChannels.Contains(CHANNEL_6_NAME), string.Format("{0} channel name was not missed", CHANNEL_6_NAME));
            }