Esempio n. 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();
 }
Esempio n. 2
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;
        }
Esempio n. 3
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);
                }
            }
Esempio n. 4
0
            public void CreateBusinessContactWithMissingMandatoryContactPerson_ExpectExpection()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var businessContactPhone = new BusinessContactPersonPhone()
                    {
                        BusinessId = 1,
                        PhoneTypeCode = PhoneTypeEnum.Contact1.GetCode(),
                        Number = "123456789"
                    };

                    businessDao.CreateContactPersonPhone(businessContactPhone);
                }
            }
Esempio n. 5
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");
                }
            }
Esempio n. 6
0
        /// <summary>
        /// Create business contact person phone
        /// </summary>
        /// <param name="businessContactPersonPhone">BusinessContactPersonPhone</param>
        /// <returns>new BusinessContactPersonPhone id</returns>
        public int CreateContactPersonPhone(BusinessContactPersonPhone businessContactPersonPhone)
        {
            const string SQL_CREATE_BUSINESS_CONTACT_PERSONPHONE_STATEMENT = @"
            INSERT INTO Business.ContactPersonPhone (ContactPersonId, PhoneTypeCode, Number, UpdatedByUserId)
            VALUES (@ContactPersonId, @PhoneTypeCode, @Number, @UpdatedByUserId)
            SET @Id = SCOPE_IDENTITY();";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessMapper.ContactPersonPhoneParameters.ContactPersonId, businessContactPersonPhone.ContactPersonId),
                DbHelper.CreateParameter(BusinessMapper.ContactPersonPhoneParameters.PhoneTypeCode, businessContactPersonPhone.PhoneTypeCode),
                DbHelper.CreateParameter(BusinessMapper.ContactPersonPhoneParameters.Number, businessContactPersonPhone.Number),
                DbHelper.CreateParameter(BusinessMapper.ContactPersonPhoneParameters.UpdatedByUserId, AuditFieldsHelper.GetUserId())
            };

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

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

            return DbHelper.ParameterValue<int>(outputKey);

        }