|
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; |
@@ -393,5 +394,77 @@ public void TestSendEmailRequestFailsWhenRecipientHasNoEmailAddress1() |
393 | 394 |
|
394 | 395 | Assert.Throws<FaultException>(() => orgAdminUIService.Execute(sendEmailRequest)); |
395 | 396 | } |
| 397 | + |
| 398 | + [Fact] |
| 399 | + public void TestSendEmailRequestSuccessWithSystemUserRecipient() |
| 400 | + { |
| 401 | + var email = new Email |
| 402 | + { |
| 403 | + From = new ActivityParty[] |
| 404 | + { |
| 405 | + new ActivityParty |
| 406 | + { |
| 407 | + PartyId = crm.AdminUser |
| 408 | + } |
| 409 | + }, |
| 410 | + To = new ActivityParty[] |
| 411 | + { |
| 412 | + new ActivityParty |
| 413 | + { |
| 414 | + PartyId = testUser1.ToEntityReference() |
| 415 | + } |
| 416 | + }, |
| 417 | + Subject = "Test Email", |
| 418 | + }; |
| 419 | + email.Id = orgAdminUIService.Create(email); |
| 420 | + |
| 421 | + var sendEmailRequest = new SendEmailRequest |
| 422 | + { |
| 423 | + EmailId = email.Id, |
| 424 | + IssueSend = true |
| 425 | + }; |
| 426 | + |
| 427 | + var response = orgAdminUIService.Execute(sendEmailRequest) as SendEmailResponse; |
| 428 | + Assert.NotNull(response); |
| 429 | + Assert.Equal(email.Subject, response.Subject); |
| 430 | + } |
| 431 | + |
| 432 | + [Fact] |
| 433 | + public void TestSendEmailRequestFailsWhenSystemUserRecipientHasNoEmailAddress() |
| 434 | + { |
| 435 | + var userWithNoEmail = new SystemUser |
| 436 | + { |
| 437 | + BusinessUnitId = crm.RootBusinessUnit, |
| 438 | + IsLicensed = true |
| 439 | + }; |
| 440 | + userWithNoEmail = crm.CreateUser(orgAdminService, userWithNoEmail, new System.Guid[0]).ToEntity<SystemUser>(); |
| 441 | + |
| 442 | + var email = new Email |
| 443 | + { |
| 444 | + From = new ActivityParty[] |
| 445 | + { |
| 446 | + new ActivityParty |
| 447 | + { |
| 448 | + PartyId = crm.AdminUser |
| 449 | + } |
| 450 | + }, |
| 451 | + To = new ActivityParty[] |
| 452 | + { |
| 453 | + new ActivityParty |
| 454 | + { |
| 455 | + PartyId = userWithNoEmail.ToEntityReference() |
| 456 | + } |
| 457 | + }, |
| 458 | + Subject = "Test Email", |
| 459 | + }; |
| 460 | + email.Id = orgAdminUIService.Create(email); |
| 461 | + |
| 462 | + var sendEmailRequest = new SendEmailRequest |
| 463 | + { |
| 464 | + EmailId = email.Id |
| 465 | + }; |
| 466 | + |
| 467 | + Assert.Throws<FaultException>(() => orgAdminUIService.Execute(sendEmailRequest)); |
| 468 | + } |
396 | 469 | } |
397 | 470 | } |
0 commit comments