Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Account a = new Account(Name='Test Account Name');
- insert a;
- Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
- insert c;
- User user = new User();
- user.ProfileID = [Select Id From Profile Where Name='CustomerCommunity User Profile'].id;
- user.EmailEncodingKey = 'ISO-8859-1';
- user.LanguageLocaleKey = 'en_US';
- user.TimeZoneSidKey = 'America/New_York';
- user.LocaleSidKey = 'en_US';
- user.FirstName = 'first';
- user.LastName = 'last';
- user.Username = 'test@appirio.com';
- user.CommunityNickname = 'testUser123';
- user.Alias = 't1';
- user.Email = 'no@email.com';
- user.IsActive = true;
- user.ContactId = c.Id;
- insert user;
- System.RunAs(user) {
- // do all of my tests as
- }
- public void getContactDetails(){
- conList = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,Contact_Type__c,AccountId
- FROM Contact where AccountID=:currentUser[0].AccountId];
- }
- public void getAccountDetails(){
- accList = [SELECT id, name, BillingStreet, BillingCity, BillingState, BillingPostalCode,
- website,phone FROM Account where id=: currentUser[0].AccountId];
- }
- @isTest
- public class CommunityUser_Test
- {
- /*
- * This method prepares the test data of this class.
- */
- @testSetup static void prepareSetupData()
- {
- Account a = new Account(Name='Test Account Name');
- insert a;
- Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
- insert c;
- User user = new User();
- user.ProfileID = [Select Id From Profile Where Name='Customer Community User'].id;
- user.EmailEncodingKey = 'ISO-8859-1';
- user.LanguageLocaleKey = 'en_US';
- user.TimeZoneSidKey = 'America/New_York';
- user.LocaleSidKey = 'en_US';
- user.FirstName = 'first';
- user.LastName = 'last';
- user.Username = 'test@appirio2.com';
- user.CommunityNickname = 'testUser123';
- user.Alias = 't1';
- user.Email = 'no@email.com';
- user.IsActive = true;
- user.ContactId = c.Id;
- insert user;
- }
- static testMethod void testforActualScenarios()
- {
- User userObj = [SELECT Id,ContactId, AccountId FROM User WHERE Username='test@appirio2.com'];
- System.RunAs(userObj) {
- //retrieve the contact.
- Contact contactObj = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
- FROM Contact where Id=: userObj.ContactId];
- System.assertEquals(contactObj.LastName,'Contact Last Name');
- List<Contact> conList = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
- FROM Contact where AccountID=:userObj.AccountId];
- System.assertEquals(conList[0].LastName,'Contact Last Name');
- //retrieve the account
- Account acct = [SELECT Id, Name FROM Account WHERE Id=:userObj.AccountId];
- System.assertEquals(acct.Name,'Test Account Name');
- }
- }
- }
- @isTest
- public class CommunityUser_Test
- {
- /*
- * This method prepares the test data of this class.
- */
- @testSetup static void prepareSetupData()
- {
- Account a = new Account(Name='Test Account Name');
- insert a;
- Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
- insert c;
- User user = new User();
- user.ProfileID = [Select Id From Profile Where Name='Customer Community User'].id;
- user.EmailEncodingKey = 'ISO-8859-1';
- user.LanguageLocaleKey = 'en_US';
- user.TimeZoneSidKey = 'America/New_York';
- user.LocaleSidKey = 'en_US';
- user.FirstName = 'first';
- user.LastName = 'last';
- user.Username = 'test@appirio2.com';
- user.CommunityNickname = 'testUser123';
- user.Alias = 't1';
- user.Email = 'no@email.com';
- user.IsActive = true;
- user.ContactId = c.Id;
- insert user;
- }
- static testMethod void testforActualScenarios()
- {
- User userObj = [SELECT Id,ContactId, AccountId FROM User WHERE Username='test@appirio2.com'];
- System.RunAs(userObj) {
- //retrieve the contact.
- Contact contactObj = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
- FROM Contact where Id=: userObj.ContactId];
- System.assertEquals(contactObj.LastName,'Contact Last Name');
- List<Contact> conList = [SELECT Name,FirstName,LastName,Account.Name, Title, email,Phone,AccountId
- FROM Contact where AccountID=:userObj.AccountId];
- System.assertEquals(conList[0].LastName,'Contact Last Name');
- //retrieve the account
- Account acct = [SELECT Id, Name FROM Account WHERE Id=:userObj.AccountId];
- System.assertEquals(acct.Name,'Test Account Name');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement