public void BulkSmsSendDynamicTests() { if (string.IsNullOrWhiteSpace(TestContact.GetStringField(Fields.contact_.mobilephone))) { TestContact.SetField(Fields.contact_.mobilephone, "0438570301"); TestContact = UpdateFieldsAndRetreive(TestContact, Fields.contact_.mobilephone); } if (!string.IsNullOrWhiteSpace(TestContact2.GetStringField(Fields.contact_.mobilephone))) { TestContact2.SetField(Fields.contact_.mobilephone, null); TestContact2 = UpdateFieldsAndRetreive(TestContact2, Fields.contact_.mobilephone); } var bulkSms = CreateTestRecord(Entities.jmcg_bulksms, new Dictionary <string, object> { { Fields.jmcg_bulksms_.jmcg_name, "Test Script Bulk SMS Content" }, { Fields.jmcg_bulksms_.jmcg_smscontent, "Test Script Bulk SMS Content" }, { Fields.jmcg_bulksms_.jmcg_marketinglist, TestDynamicContactMarketingList.ToEntityReference() }, { Fields.jmcg_bulksms_.jmcg_sendmessages, true }, }); Assert.IsTrue(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages)); Assert.IsFalse(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendmessages)); WaitTillTrue(() => !Refresh(bulkSms).GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages), 60); var smsMessages = GetSmsMessagesSent(bulkSms); var smsErrors = GetSmsErrorsActive(bulkSms); Assert.AreEqual(1, smsMessages.Count()); Assert.AreEqual(TestContact.Id, smsMessages.First().GetActivityPartyReferences(Fields.jmcg_sms_.to).First().Id); Assert.AreEqual(1, smsErrors.Count()); Assert.AreEqual(TestContact2.Id, smsErrors.First().GetLookupGuid(Fields.jmcg_bulksmserror_.jmcg_contact)); //fix error and reprocess //populate mobile number TestContact2.SetField(Fields.contact_.mobilephone, "0438570301"); TestContact2 = UpdateFieldsAndRetreive(TestContact2, Fields.contact_.mobilephone); //resend bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_sendmessages, true); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_sendmessages); Assert.IsTrue(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages)); Assert.IsFalse(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendmessages)); WaitTillTrue(() => !Refresh(bulkSms).GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages), 60); //verify now 2 sms messages //and no active errors smsMessages = GetSmsMessagesSent(bulkSms); smsErrors = GetSmsErrorsActive(bulkSms); Assert.AreEqual(2, smsMessages.Count()); Assert.AreEqual(1, smsMessages.Count(e => e.GetActivityPartyReferences(Fields.jmcg_sms_.to).First().Id == TestContact.Id)); Assert.AreEqual(1, smsMessages.Count(e => e.GetActivityPartyReferences(Fields.jmcg_sms_.to).First().Id == TestContact2.Id)); Assert.AreEqual(0, smsErrors.Count()); DeleteMyToday(); }
public void BulkSmsSendStaticTests() { var bulkSms = CreateTestRecord(Entities.jmcg_bulksms); //validate sms content populated when send try { bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_sendmessages, true); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_sendmessages); Assert.Fail(); } catch (Exception ex) { Assert.IsFalse(ex is AssertFailedException); } bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_smscontent, "Test Script Bulk SMS Content"); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_smscontent); //validate marketing list populated when send try { bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_sendmessages, true); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_sendmessages); Assert.Fail(); } catch (Exception ex) { Assert.IsFalse(ex is AssertFailedException); } bulkSms.SetLookupField(Fields.jmcg_bulksms_.jmcg_marketinglist, TestAccountMarketingList); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_marketinglist); //validate marketing list for contacts when send try { bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_sendmessages, true); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_sendmessages); Assert.Fail(); } catch (Exception ex) { Assert.IsFalse(ex is AssertFailedException); } //okay now set to a contact marketing list //should be valid for send //lets add a contact with a mobile number //and one without a mobile number bulkSms.SetLookupField(Fields.jmcg_bulksms_.jmcg_marketinglist, TestContactMarketingList); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_marketinglist); //clear the contact list var marketingListMembers = XrmService.GetMarketingListMemberIds(TestContactMarketingList.Id); foreach (var memberId in marketingListMembers) { RemoveListMember(memberId, TestContactMarketingList.Id); } //add test contact with mobile number if (string.IsNullOrWhiteSpace(TestContact.GetStringField(Fields.contact_.mobilephone))) { TestContact.SetField(Fields.contact_.mobilephone, "0438570301"); TestContact = UpdateFieldsAndRetreive(TestContact, Fields.contact_.mobilephone); } AddListMember(TestContact.Id, TestContactMarketingList.Id); //add test contact2 without mobile number if (!string.IsNullOrWhiteSpace(TestContact2.GetStringField(Fields.contact_.mobilephone))) { TestContact2.SetField(Fields.contact_.mobilephone, null); TestContact2 = UpdateFieldsAndRetreive(TestContact2, Fields.contact_.mobilephone); } AddListMember(TestContact2.Id, TestContactMarketingList.Id); //send sms including error bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_sendmessages, true); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_sendmessages); Assert.IsTrue(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages)); Assert.IsFalse(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendmessages)); WaitTillTrue(() => !Refresh(bulkSms).GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages), 60); var smsMessages = GetSmsMessagesSent(bulkSms); var smsErrors = GetSmsErrorsActive(bulkSms); Assert.AreEqual(1, smsMessages.Count()); Assert.AreEqual(TestContact.Id, smsMessages.First().GetActivityPartyReferences(Fields.jmcg_sms_.to).First().Id); Assert.AreEqual(1, smsErrors.Count()); Assert.AreEqual(TestContact2.Id, smsErrors.First().GetLookupGuid(Fields.jmcg_bulksmserror_.jmcg_contact)); //fix error and reprocess //populate mobile number TestContact2.SetField(Fields.contact_.mobilephone, "0438570301"); TestContact2 = UpdateFieldsAndRetreive(TestContact2, Fields.contact_.mobilephone); //resend bulkSms.SetField(Fields.jmcg_bulksms_.jmcg_sendmessages, true); bulkSms = UpdateFieldsAndRetreive(bulkSms, Fields.jmcg_bulksms_.jmcg_sendmessages); Assert.IsTrue(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages)); Assert.IsFalse(bulkSms.GetBoolean(Fields.jmcg_bulksms_.jmcg_sendmessages)); WaitTillTrue(() => !Refresh(bulkSms).GetBoolean(Fields.jmcg_bulksms_.jmcg_sendingmessages), 60); //verify now 2 sms messages //and no active errors smsMessages = GetSmsMessagesSent(bulkSms); smsErrors = GetSmsErrorsActive(bulkSms); Assert.AreEqual(2, smsMessages.Count()); Assert.AreEqual(1, smsMessages.Count(e => e.GetActivityPartyReferences(Fields.jmcg_sms_.to).First().Id == TestContact.Id)); Assert.AreEqual(1, smsMessages.Count(e => e.GetActivityPartyReferences(Fields.jmcg_sms_.to).First().Id == TestContact2.Id)); Assert.AreEqual(0, smsErrors.Count()); DeleteMyToday(); }