Last active
December 17, 2015 22:59
-
-
Save tyoshikawa1106/5685992 to your computer and use it in GitHub Desktop.
テストクラスでユーザ作成時にライセンス数の制限が影響するかのテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class UserCreateSample { | |
public UserCreateSample() { | |
} | |
public User getUser(Profile prmProfile, String prmEmail, Integer prmUserNo) { | |
// ユーザ | |
User user = new User(); | |
// 姓 | |
user.LastName = 'testuser'; | |
// 別名 | |
user.Alias = 'user'; | |
// メール | |
user.Email = prmEmail; | |
// ユーザ名 | |
user.UserName = '[email protected]' + String.valueOf(prmUserNo); | |
// コミュニティのニックネーム | |
user.CommunityNickname = 'testuser' + String.valueOf(prmUserNo); | |
// メールの文字コード | |
user.EmailEncodingKey = 'ISO-2022-JP'; | |
// タイムゾーン | |
user.TimeZoneSidKey = 'Asia/Tokyo'; | |
// 地域 | |
user.LocaleSidKey = 'ja_JP'; | |
// 言語 | |
user.LanguageLocaleKey = 'ja'; | |
// プロファイル | |
user.ProfileId = prmProfile.Id; | |
return user; | |
} | |
public List<User> getUsers(Profile prmProfile, String prmEmail, Integer prmLoopCnt) { | |
List<User> users = new List<User>(); | |
for (Integer i = 0; i < prmLoopCnt; i++) { | |
users.add(getUser(prmProfile, prmEmail, i)); | |
} | |
return users; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class UserCreateSampleTest { | |
private static final Integer LOOP_CNT = 201; | |
private static final String PROFILE_NAME = 'システム管理者'; | |
private static final String USER_EMAIL = '[email protected]'; | |
/* | |
* ユーザ1件作成テスト | |
*/ | |
static testMethod void getUserTest() { | |
// プロフィール取得 | |
Profile profile = getProfile(); | |
System.assertEquals(profile.Name, PROFILE_NAME); | |
// 取得結果0件の確認 | |
List<User> checkUsers = getCreateUsers(); | |
System.assertEquals(checkUsers.size(), 0); | |
Test.startTest(); | |
// コンストラクタ | |
UserCreateSample cls = new UserCreateSample(); | |
// ユーザ1件作成 | |
User user = cls.getUser(profile, USER_EMAIL, 1); | |
insert user; | |
Test.stopTest(); | |
// ユーザ取得件数が1件のテスト | |
List<User> createUsers = getCreateUsers(); | |
System.assertEquals(createUsers.size(), 1); | |
System.debug('◆◆UserCnt : ' + createUsers.size()); | |
} | |
/* | |
* ユーザ複数件作成テスト | |
*/ | |
static testMethod void getUsersTest() { | |
// プロフィール取得 | |
Profile profile = getProfile(); | |
System.assertEquals(profile.Name, PROFILE_NAME); | |
// 取得結果0件の確認 | |
List<User> checkUsers = getCreateUsers(); | |
System.assertEquals(checkUsers.size(), 0); | |
Test.startTest(); | |
// コンストラクタ | |
UserCreateSample cls = new UserCreateSample(); | |
// ユーザ複数件作成 | |
List<User> users = cls.getUsers(profile, USER_EMAIL, LOOP_CNT); | |
insert users; | |
Test.stopTest(); | |
// ユーザ取得件数が複数件のテスト | |
List<User> createUsers = getCreateUsers(); | |
System.assertEquals(createUsers.size(), LOOP_CNT); | |
System.debug('◆◆UserCnt : ' + createUsers.size()); | |
} | |
/* | |
* プロファイル取得 | |
*/ | |
private static Profile getProfile() { | |
return [select Id,Name from Profile where Name =: PROFILE_NAME limit 1]; | |
} | |
/* | |
* 作成したユーザのリスト取得 | |
*/ | |
private static List<User> getCreateUsers() { | |
return [select Id from User where Email =: USER_EMAIL and IsActive = true]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment