Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. Account a = new Account(Name='Test Account Name');
  2. insert a;
  3.  
  4. Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
  5. insert c;
  6.  
  7. User user = new User();
  8. user.ProfileID = [Select Id From Profile Where Name='CustomerCommunity User Profile'].id;
  9. user.EmailEncodingKey = 'ISO-8859-1';
  10. user.LanguageLocaleKey = 'en_US';
  11. user.TimeZoneSidKey = 'America/New_York';
  12. user.LocaleSidKey = 'en_US';
  13. user.FirstName = 'first';
  14. user.LastName = 'last';
  15. user.Username = 'test@appirio.com';
  16. user.CommunityNickname = 'testUser123';
  17. user.Alias = 't1';
  18. user.Email = 'no@email.com';
  19. user.IsActive = true;
  20. user.ContactId = c.Id;
  21.  
  22. insert user;
  23.  
  24. System.RunAs(user) {
  25. // do all of my tests as
  26. }
  27.  
  28. public void getContactDetails(){
  29.  
  30. conList = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,Contact_Type__c,AccountId
  31. FROM Contact where AccountID=:currentUser[0].AccountId];
  32.  
  33. }
  34.  
  35.  
  36. public void getAccountDetails(){
  37. accList = [SELECT id, name, BillingStreet, BillingCity, BillingState, BillingPostalCode,
  38. website,phone FROM Account where id=: currentUser[0].AccountId];
  39. }
  40.  
  41. @isTest
  42. public class CommunityUser_Test
  43. {
  44. /*
  45. * This method prepares the test data of this class.
  46. */
  47. @testSetup static void prepareSetupData()
  48. {
  49. Account a = new Account(Name='Test Account Name');
  50. insert a;
  51.  
  52. Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
  53. insert c;
  54.  
  55. User user = new User();
  56. user.ProfileID = [Select Id From Profile Where Name='Customer Community User'].id;
  57. user.EmailEncodingKey = 'ISO-8859-1';
  58. user.LanguageLocaleKey = 'en_US';
  59. user.TimeZoneSidKey = 'America/New_York';
  60. user.LocaleSidKey = 'en_US';
  61. user.FirstName = 'first';
  62. user.LastName = 'last';
  63. user.Username = 'test@appirio2.com';
  64. user.CommunityNickname = 'testUser123';
  65. user.Alias = 't1';
  66. user.Email = 'no@email.com';
  67. user.IsActive = true;
  68. user.ContactId = c.Id;
  69. insert user;
  70. }
  71.  
  72.  
  73. static testMethod void testforActualScenarios()
  74. {
  75. User userObj = [SELECT Id,ContactId, AccountId FROM User WHERE Username='test@appirio2.com'];
  76. System.RunAs(userObj) {
  77. //retrieve the contact.
  78. Contact contactObj = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
  79. FROM Contact where Id=: userObj.ContactId];
  80.  
  81. System.assertEquals(contactObj.LastName,'Contact Last Name');
  82.  
  83.  
  84. List<Contact> conList = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
  85. FROM Contact where AccountID=:userObj.AccountId];
  86.  
  87. System.assertEquals(conList[0].LastName,'Contact Last Name');
  88.  
  89. //retrieve the account
  90. Account acct = [SELECT Id, Name FROM Account WHERE Id=:userObj.AccountId];
  91. System.assertEquals(acct.Name,'Test Account Name');
  92.  
  93. }
  94.  
  95. }
  96. }
  97.  
  98. @isTest
  99. public class CommunityUser_Test
  100. {
  101. /*
  102. * This method prepares the test data of this class.
  103. */
  104. @testSetup static void prepareSetupData()
  105. {
  106. Account a = new Account(Name='Test Account Name');
  107. insert a;
  108.  
  109. Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
  110. insert c;
  111.  
  112. User user = new User();
  113. user.ProfileID = [Select Id From Profile Where Name='Customer Community User'].id;
  114. user.EmailEncodingKey = 'ISO-8859-1';
  115. user.LanguageLocaleKey = 'en_US';
  116. user.TimeZoneSidKey = 'America/New_York';
  117. user.LocaleSidKey = 'en_US';
  118. user.FirstName = 'first';
  119. user.LastName = 'last';
  120. user.Username = 'test@appirio2.com';
  121. user.CommunityNickname = 'testUser123';
  122. user.Alias = 't1';
  123. user.Email = 'no@email.com';
  124. user.IsActive = true;
  125. user.ContactId = c.Id;
  126. insert user;
  127. }
  128.  
  129.  
  130. static testMethod void testforActualScenarios()
  131. {
  132. User userObj = [SELECT Id,ContactId, AccountId FROM User WHERE Username='test@appirio2.com'];
  133. System.RunAs(userObj) {
  134. //retrieve the contact.
  135. Contact contactObj = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
  136. FROM Contact where Id=: userObj.ContactId];
  137.  
  138. System.assertEquals(contactObj.LastName,'Contact Last Name');
  139.  
  140.  
  141. List<Contact> conList = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
  142. FROM Contact where AccountID=:userObj.AccountId];
  143.  
  144. System.assertEquals(conList[0].LastName,'Contact Last Name');
  145.  
  146. //retrieve the account
  147. Account acct = [SELECT Id, Name FROM Account WHERE Id=:userObj.AccountId];
  148. System.assertEquals(acct.Name,'Test Account Name');
  149.  
  150. }
  151.  
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement