|
1 | 1 | using DG.XrmFramework.BusinessDomain.ServiceContext; |
2 | 2 | using Microsoft.Crm.Sdk.Messages; |
| 3 | +using Microsoft.Xrm.Sdk; |
3 | 4 | using System.Linq; |
4 | 5 | using System.ServiceModel; |
5 | 6 | using Xunit; |
@@ -146,6 +147,55 @@ public void TestSendEmailRequestSuccessWithUnresolvedRecipient() |
146 | 147 | } |
147 | 148 | } |
148 | 149 |
|
| 150 | + [Fact] |
| 151 | + public void TestSendEmailRequestSuccessWhenEmailStatusFailed() |
| 152 | + { |
| 153 | + var contact = new Contact |
| 154 | + { |
| 155 | + FirstName = "Test", |
| 156 | + EMailAddress1 = "test@test.com" |
| 157 | + }; |
| 158 | + contact.Id = orgAdminUIService.Create(contact); |
| 159 | + |
| 160 | + var email = new Email |
| 161 | + { |
| 162 | + From = new ActivityParty[] |
| 163 | + { |
| 164 | + new ActivityParty |
| 165 | + { |
| 166 | + PartyId = crm.AdminUser |
| 167 | + } |
| 168 | + }, |
| 169 | + To = new ActivityParty[] |
| 170 | + { |
| 171 | + new ActivityParty |
| 172 | + { |
| 173 | + PartyId = contact.ToEntityReference() |
| 174 | + } |
| 175 | + }, |
| 176 | + Subject = "Test Email", |
| 177 | + StatusCode = Email_StatusCode.Failed |
| 178 | + }; |
| 179 | + email.Id = orgAdminUIService.Create(email); |
| 180 | + |
| 181 | + var sendEmailRequest = new SendEmailRequest |
| 182 | + { |
| 183 | + EmailId = email.Id, |
| 184 | + IssueSend = true |
| 185 | + }; |
| 186 | + |
| 187 | + var response = orgAdminUIService.Execute(sendEmailRequest) as SendEmailResponse; |
| 188 | + Assert.NotNull(response); |
| 189 | + Assert.Equal(email.Subject, response.Subject); |
| 190 | + |
| 191 | + using (var context = new Xrm(orgAdminUIService)) |
| 192 | + { |
| 193 | + var retrievedEmail = context.EmailSet.FirstOrDefault(); |
| 194 | + Assert.Equal(EmailState.Completed, retrievedEmail.StateCode); |
| 195 | + Assert.Equal(Email_StatusCode.PendingSend, retrievedEmail.StatusCode); |
| 196 | + } |
| 197 | + } |
| 198 | + |
149 | 199 | [Fact] |
150 | 200 | public void TestSendEmailRequestFailsWhenTryingToSendAgain() |
151 | 201 | { |
@@ -393,5 +443,77 @@ public void TestSendEmailRequestFailsWhenRecipientHasNoEmailAddress1() |
393 | 443 |
|
394 | 444 | Assert.Throws<FaultException>(() => orgAdminUIService.Execute(sendEmailRequest)); |
395 | 445 | } |
| 446 | + |
| 447 | + [Fact] |
| 448 | + public void TestSendEmailRequestSuccessWithSystemUserRecipient() |
| 449 | + { |
| 450 | + var email = new Email |
| 451 | + { |
| 452 | + From = new ActivityParty[] |
| 453 | + { |
| 454 | + new ActivityParty |
| 455 | + { |
| 456 | + PartyId = crm.AdminUser |
| 457 | + } |
| 458 | + }, |
| 459 | + To = new ActivityParty[] |
| 460 | + { |
| 461 | + new ActivityParty |
| 462 | + { |
| 463 | + PartyId = testUser1.ToEntityReference() |
| 464 | + } |
| 465 | + }, |
| 466 | + Subject = "Test Email", |
| 467 | + }; |
| 468 | + email.Id = orgAdminUIService.Create(email); |
| 469 | + |
| 470 | + var sendEmailRequest = new SendEmailRequest |
| 471 | + { |
| 472 | + EmailId = email.Id, |
| 473 | + IssueSend = true |
| 474 | + }; |
| 475 | + |
| 476 | + var response = orgAdminUIService.Execute(sendEmailRequest) as SendEmailResponse; |
| 477 | + Assert.NotNull(response); |
| 478 | + Assert.Equal(email.Subject, response.Subject); |
| 479 | + } |
| 480 | + |
| 481 | + [Fact] |
| 482 | + public void TestSendEmailRequestFailsWhenSystemUserRecipientHasNoEmailAddress() |
| 483 | + { |
| 484 | + var userWithNoEmail = new SystemUser |
| 485 | + { |
| 486 | + BusinessUnitId = crm.RootBusinessUnit, |
| 487 | + IsLicensed = true |
| 488 | + }; |
| 489 | + userWithNoEmail = crm.CreateUser(orgAdminService, userWithNoEmail, new System.Guid[0]).ToEntity<SystemUser>(); |
| 490 | + |
| 491 | + var email = new Email |
| 492 | + { |
| 493 | + From = new ActivityParty[] |
| 494 | + { |
| 495 | + new ActivityParty |
| 496 | + { |
| 497 | + PartyId = crm.AdminUser |
| 498 | + } |
| 499 | + }, |
| 500 | + To = new ActivityParty[] |
| 501 | + { |
| 502 | + new ActivityParty |
| 503 | + { |
| 504 | + PartyId = userWithNoEmail.ToEntityReference() |
| 505 | + } |
| 506 | + }, |
| 507 | + Subject = "Test Email", |
| 508 | + }; |
| 509 | + email.Id = orgAdminUIService.Create(email); |
| 510 | + |
| 511 | + var sendEmailRequest = new SendEmailRequest |
| 512 | + { |
| 513 | + EmailId = email.Id |
| 514 | + }; |
| 515 | + |
| 516 | + Assert.Throws<FaultException>(() => orgAdminUIService.Execute(sendEmailRequest)); |
| 517 | + } |
396 | 518 | } |
397 | 519 | } |
0 commit comments