Beispiel #1
0
 public void CreateBusinessContact()
 {
     // arrange
     const int businessId = 1;
     var businessDao = MockRepository.GenerateMock<IBusinessDao>();
     var businessEventDao = MockRepository.GenerateMock<IBusinessEventDao>();
     var newBusinessContact = new BusinessContactPerson();
     var newBusinessContactPhone = new BusinessContactPersonPhone();
     businessManager.BusinessDao = businessDao;
     businessManager.BusinessEventDao = businessEventDao;
     businessDao.CreateContact(newBusinessContact);
     businessEventDao.Expect(z => z.Create(new BusinessEvent() { BusinessId = businessId }));
     businessDao.CreateContactPersonPhone(newBusinessContactPhone);
     businessEventDao.Expect(z => z.Create(new BusinessEvent() { BusinessId = businessId }));
     // act
     businessManager.CreateContact(newBusinessContact);
     // assert
     businessDao.VerifyAllExpectations();
     //Needs fixing 
     businessEventDao.VerifyAllExpectations();
 }
Beispiel #2
0
            public void UpdatePrimaryContact_ExpectSuccess()
            {
                
                 using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                 {
                     const long BUSINESS_ID = 1;
                     var businessContact = new BusinessContactPerson()
                                               {
                                                   BusinessId = 1,
                                                   ContactTypeCode = "BC",
                                                   Surname = "Surname",
                                                   UseBusinessAddress = true,
                                                   IsPrimary = true,
                                                   CreatedDatetime = DateTime.Now
                                               };

                     int contactId = businessDao.CreateContact(businessContact);
                     bool result = businessDao.UpdatePrimaryContact(BUSINESS_ID, contactId, true);
                     Assert.IsTrue(result);
                 }
            }
Beispiel #3
0
        /// <summary>
        /// Create contact
        /// </summary>
        /// <param name="contactPerson">BusinessContactPerson</param>
        /// <returns>true if creation succeeeds</returns>
        public int CreateContact(BusinessContactPerson contactPerson)
        {
            int contactId = 0;
            int contactPhoneId = 0;
            using (var tx = new BusinessTransaction())
            {
                // write contact record to ContactPerson table
                contactId = businessDao.CreateContact(contactPerson);

                var createBusinessContactPersonEvent = new BusinessEvent
                {
                    BusinessId = contactPerson.BusinessId,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.ContactPersonCreated.GetCode() },
                    Reference = contactId.ToString()

                };

                // reset primary contact if new contact is primary
                if (contactPerson.PrimaryContactId != default(int) && contactPerson.IsPrimary)
                {
                    businessDao.UpdatePrimaryContact(contactPerson.BusinessId, contactPerson.PrimaryContactId, false);
                    businessDao.UpdatePrimaryContact(contactPerson.BusinessId, contactId, true);

                    var updatecontactPerson = new BusinessEvent
                    {
                        BusinessId = contactPerson.BusinessId,
                        EventType = new EnumEntity { Code = BusinessEventTypesEnum.PrimaryContactModified.GetCode() },
                        Reference = contactId.ToString()
                    };

                    businessEventDao.Create(updatecontactPerson);
                }


                // write to business event table
                businessEventDao.Create(createBusinessContactPersonEvent);

                // write contact record to ContactPersonPhone table
                BusinessContactPersonPhone businessContactPersonPhone = new BusinessContactPersonPhone()
                {
                    BusinessId = contactPerson.BusinessId,
                    ContactPersonId = contactId,
                    PhoneTypeCode = PhoneTypeEnum.Contact1.GetCode(),
                    Number = contactPerson.Telephone
                };

                // write record to BusinessContactPersonPhone table
                contactPhoneId = businessDao.CreateContactPersonPhone(businessContactPersonPhone);

                var createBusinessPhoneEvent = new BusinessEvent
                {
                    BusinessId = contactPerson.BusinessId,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.ContactPersonPhoneCreated.GetCode() },
                    Reference = contactPhoneId.ToString()

                };

                // write create business event to event table
                businessEventDao.Create(createBusinessPhoneEvent);

                tx.Commit();
            }
            return contactId;
        }
Beispiel #4
0
            public void CreateBusinessContact_ExpectSuccess()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var businessContact = new BusinessContactPerson()
                    {
                        BusinessId = 1,
                        ContactTypeCode = "BC",
                        Surname = "Surname",
                        UseBusinessAddress = true,
                        IsPrimary = true,
                        CreatedDatetime = DateTime.Now
                    };

                    int newContactId = businessDao.CreateContact(businessContact);

                    var businessContactPhone = new BusinessContactPersonPhone()
                    {
                        BusinessId = 1,
                        ContactPersonId = newContactId,
                        PhoneTypeCode = PhoneTypeEnum.Contact1.GetCode(),
                        Number = "123456789"                      
                    };

                    int newContactPhoneId = businessDao.CreateContactPersonPhone(businessContactPhone);
                    Assert.IsTrue(newContactPhoneId > 0, "Expect new business contact person phone to be created");
                }
            }
Beispiel #5
0
            public void CreateBusinessContactWithMissingMandatoryPhoneTypeCode_ExpectExpection()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var businessContact = new BusinessContactPerson()
                    {
                        BusinessId = 1,
                        ContactTypeCode = "BC",
                        Surname = "Surname",
                        UseBusinessAddress = true,
                        IsPrimary = true,
                        CreatedDatetime = DateTime.Now
                    };

                    int newContactId = businessDao.CreateContact(businessContact);

                    var businessContactPhone = new BusinessContactPersonPhone()
                    {
                        BusinessId = 1,
                        ContactPersonId = newContactId,
                     
                        Number = "123456789"
                    };

                    businessDao.CreateContactPersonPhone(businessContactPhone);
                }
            }
Beispiel #6
0
            public void CreateBusinessContactWithMissingMandatoryBusinessId_ExpectExpection()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var businessContact = new BusinessContactPerson()
                                              {

                                                  ContactTypeCode = "BC",
                                                  Surname = "Surname",
                                                  UseBusinessAddress = true,
                                                  IsPrimary = true,
                                                  CreatedDatetime = DateTime.Now
                                              };

                    int newContactId = businessDao.CreateContact(businessContact);
                    Assert.IsTrue(newContactId > 0, "Expect new business contact person to be created");
                }
            }
Beispiel #7
0
            public void CreateBusinessContactWithMissingMandatorySurname_ExpectExpection()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var businessContact = new BusinessContactPerson()
                                              {
                                                  BusinessId = 1,
                                                  ContactTypeCode = "BC",
                                                  UseBusinessAddress = true,
                                                  IsPrimary = true,
                                                  CreatedDatetime = DateTime.Now
                                              };

                    businessDao.CreateContact(businessContact);

                }
            }
Beispiel #8
0
 /// <summary>
 /// Get settlement Account Holder from eagle business primary contact
 /// </summary>
 /// <param name="primaryContact">BusinessContactPerson</param>
 /// <returns>ContactPerson name</returns>
 private string GetAccountHolder(BusinessContactPerson primaryContact)
 {
     return primaryContact != null ? primaryContact.Forename + " " + primaryContact.Surname : string.Empty;
 }
Beispiel #9
0
        /// <summary>
        /// Set contact information on NewProvider Model
        /// </summary>
        /// <param name="provider">NewProvider</param>
        /// <param name="business">business</param>
        /// <param name="primaryContact">primaryContact</param>
        /// <param name="settlementBankAccount">settlementBankAccount</param>
        private void SetBusinessInfoOnNewProviderModel(NewProvider provider, Model.Business.Business business, BusinessContactPerson primaryContact, BankAccount settlementBankAccount)
        {

            Helper.ArgumentNotNull(provider, "provider");
            Helper.ArgumentNotNull(business, "business");
            Country countryOfBusiness = countryDao.GetByBusiness(business.Id);

            provider.NewProviderId = Helper.LongToGuid(business.Id).ToString();
            provider.ContactInformation = CreateContactInformation(business);
            provider.ModificationDate = business.UpdatedDateTime;
            provider.RefCode = business.ReferenceCode;
            provider.ShortName = business.ShortName;
            provider.FullName = business.Name;
            provider.MerchantId = settlementHelper.GetMerchantIdForNewProviderModel(business).Result;
            provider.AccountHolder = primaryContact != null ? GetAccountHolder(primaryContact) : string.Empty;
            provider.TaxStatus = business.IsTaxRegistered;

            provider.BankSortCode = GetBankSortCode(countryOfBusiness, settlementBankAccount);
            provider.BankAccountNumber = GetBankAccountNumber(countryOfBusiness, settlementBankAccount);
            provider.BankAccountName = settlementBankAccount != null ? settlementBankAccount.AccountName : null;

            provider.SupplyPartnerReferenceCode = SUPPLY_PARTNER_ID;
            provider.SupplyPartner = SUPPLY_PARTNER_ID;
            provider.Status = GetProviderStatus(business.BusinessStatus.Code);
            provider.IsMerchant = business.MerchantStatusEnum == MerchantStatusEnum.OwnMerchant;

        }
Beispiel #10
0
        /// <summary>
        /// Create Business Contact Person
        /// </summary>
        /// <param name="businessContactPerson">BusinessContactPerson</param>
        /// <returns>new contact id</returns>
        public int CreateContact(BusinessContactPerson businessContactPerson)
        {
            const string SQL_CREATE_BUSINESSCONTACT_STATEMENT = @"
            INSERT INTO Business.ContactPerson
               (BusinessId
               ,ContactTypeCode
               ,TitleId
               ,Forename
               ,Surname
               ,Email
               ,UseBusinessAddress
               ,AddressLine1
               ,AddressLine2
               ,AddressLine3
               ,City
               ,StateProvinceId
               ,PostCode
               ,CountryId
               ,Notes
               ,IsPrimary
               ,UpdatedByUserId)
            VALUES
               (@BusinessId
               ,@ContactTypeCode
               ,@TitleId
               ,@ForeName
               ,@Surname
               ,@Email
               ,@UseBusinessAddress
               ,@AddressLine1
               ,@AddressLine2
               ,@AddressLine3
               ,@City
               ,@StateProvinceId
               ,@PostCode
               ,@CountryId
               ,@Notes
               ,@IsPrimary
               ,@UpdatedByUserId)
            SET @Id = SCOPE_IDENTITY();";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.BusinessId, businessContactPerson.BusinessId),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.ContactTypeCode, businessContactPerson.ContactTypeCode),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.TitleId, businessContactPerson.TitleId),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.Forename, businessContactPerson.Forename),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.Surname, businessContactPerson.Surname),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.Email, businessContactPerson.Email),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.UseBusinessAddress, businessContactPerson.UseBusinessAddress),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.AddressLine1, businessContactPerson.AddressLine1),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.AddressLine2, businessContactPerson.AddressLine2),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.AddressLine3, businessContactPerson.AddressLine3),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.City, businessContactPerson.City),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.StateProvinceId, businessContactPerson.StateProvinceId),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.PostCode, businessContactPerson.PostCode),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.CountryId, businessContactPerson.CountryId),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.Notes, businessContactPerson.Notes),
                DbHelper.CreateParameter(BusinessContactMapper.Parameters.IsPrimary, businessContactPerson.IsPrimary)
            };

            AuditFieldsHelper.PopulateAuditFields(parameters);

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(BusinessMapper.Parameters.Id, SqlDbType.Int));
            
            try
            {
                DbHelper.ExecuteNonQueryCommand(SQL_CREATE_BUSINESSCONTACT_STATEMENT, parameters: parameters);
            }
            catch (SqlException exception)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30099, "BusinessDao.CreateContact", additionalDescriptionParameters: (new object[] { exception.Message }), arguments: new object[] { businessContactPerson.GetType().Name, businessContactPerson.Id }));
            }

            if (outputKey.Value == DBNull.Value)
            {
                throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30100, "BusinessDao.CreateContact", additionalDescriptionParameters: (new object[] { businessContactPerson.Id })));
            }

            return DbHelper.ParameterValue<int>(outputKey);

        }