Пример #1
0
        /// <summary>
        /// Create BusinessAgreement
        /// </summary>
        /// <param name="businessAgreement">business agreement to add</param>
        public void Create(BusinessAgreement businessAgreement)
        {
            const string SQL_STATEMENT = @"
                INSERT INTO Business.BusinessAgreement
                (
                        BusinessId,
                        AgreementId,
                        UpdatedByUserId
                )
                VALUES
                (
                        @BusinessId,
                        @AgreementId,
                        @UpdatedByUserId
                )
                SELECT @Id = SCOPE_IDENTITY()";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessAgreementMapper.Parameters.BusinessId, businessAgreement.BusinessId),
                DbHelper.CreateParameter(BusinessAgreementMapper.Parameters.AgreementId, businessAgreement.AgreementId)
            };

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(BusinessAgreementMapper.Parameters.Id, SqlDbType.Int));

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

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
            businessAgreement.Id = DbHelper.ParameterValue<int>(outputKey);
        }
Пример #2
0
        /// <summary>
        /// Map the basic fields for the BusinessAgreement table to the BusinessAgreement model object
        /// </summary>
        /// <param name="record">The SqlDataReader with the executed query result</param>
        /// <param name="prefix">a prefix used to identify fields for the BusinessAgreement model  in the resultset if required</param>        
        /// <returns>An instance of Model.Business.BusinessAgreement</returns>
        internal static BusinessAgreement MapRecord(IDataRecord record, string prefix = "")
        {
            var businessAgreement = new BusinessAgreement
            {
                Id = DbHelper.ConvertValue<int>(record[prefix + SelectParameters.Id]),
                BusinessId = DbHelper.ConvertValue<long>(record[prefix + SelectParameters.BusinessId]),
                AgreementId = DbHelper.ConvertValue<int>(record[prefix + SelectParameters.AgreementId]),
                UpdatedByUserId = DbHelper.ConvertValue<Guid>(record[prefix + SelectParameters.UpdatedByUserId]),
                UpdatedDateTime = DbHelper.ConvertValue<DateTime>(record[prefix + SelectParameters.UpdatedDatetime])
            };

            if (record.HasColumn(prefix + SelectParameters.AgreementTypeCode))
            {
                businessAgreement.LinkedAgreementType =
                    DbHelper.ConvertEnumValue<AgreementType>(record[prefix + SelectParameters.AgreementTypeCode]);
            }

            return businessAgreement;
        }
Пример #3
0
            public void AgreeToAgreementsCallsCorrectMethods()
            {
                // Arrange
                IBusinessAgreementDao businessAgreementDao = MockRepository.GenerateMock<IBusinessAgreementDao>();
                IBusinessEventDao businessEventDao = MockRepository.GenerateMock<IBusinessEventDao>();
                BusinessAgreement ukBus1Agree = new BusinessAgreement
                                                    {
                                                        BusinessId = UK_BUSINESS_1,
                                                        AgreementId = UK_AGREEMENT_ID
                                                    };
                BusinessAgreement ukBus2Agree = new BusinessAgreement
                                                    {
                                                        BusinessId = UK_BUSINESS_2,
                                                        AgreementId = UK_AGREEMENT_ID
                                                    };
                BusinessAgreement frBus1Agree = new BusinessAgreement
                                                    {
                                                        BusinessId = FR_BUSINESS_1,
                                                        AgreementId = FR_AGREEMENT_ID
                                                    };
                List<BusinessAgreement> agreementsToAgreeTo = new List<BusinessAgreement>
                                                                  {
                                                                      ukBus1Agree,
                                                                      ukBus2Agree,
                                                                      frBus1Agree
                                                                  };
                businessAgreementDao.Expect(
                    bagree =>
                    bagree.Create(
                        Arg<BusinessAgreement>.Matches(
                            ba => ba.BusinessId == ukBus1Agree.BusinessId && ba.AgreementId == ukBus1Agree.AgreementId)))
                                    .Repeat.Once();
                businessAgreementDao.Expect(
                    bagree =>
                    bagree.Create(
                        Arg<BusinessAgreement>.Matches(
                            ba => ba.BusinessId == ukBus2Agree.BusinessId && ba.AgreementId == ukBus2Agree.AgreementId)))
                                    .Repeat.Once();
                businessAgreementDao.Expect(
                    bagree =>
                    bagree.Create(
                        Arg<BusinessAgreement>.Matches(
                            ba => ba.BusinessId == frBus1Agree.BusinessId && ba.AgreementId == frBus1Agree.AgreementId)))
                                    .Repeat.Once();

                // verify 3 events created for business
                businessEventDao.Expect(
                    bEvent =>
                    bEvent.Create(
                        Arg<BusinessEvent>.Matches(
                            be =>
                            be.EventType != null &&
                            be.EventType.Code == BusinessEventTypesEnum.AcceptedBusinessAgreement.GetCode())))
                                .Repeat.Times(3);

                AgreementManager manager = new AgreementManager
                                               {
                                                   BusinessAgreementDao = businessAgreementDao,
                                                   BusinessEventDao = businessEventDao
                                               };
                // Act
                // Assert
                Assert.IsTrue(manager.AgreeToAgreements(agreementsToAgreeTo), "Should have returned true");
                businessAgreementDao.VerifyAllExpectations();
                businessEventDao.VerifyAllExpectations();
            }