/// <summary> /// Initializes a new instance of the <see cref="UserImportRequest"/> class by verifying /// the supplied user's <c>IEnumerable</c> is valid (non-empty and not greater than /// <c>MaxImportUsers</c>), and a valid <see cref="UserImportHash"/> is supplied when a /// password is provided to at least one of the users. /// </summary> /// <param name="usersToImport">List of users to be imported.</param> /// <param name="options">Options for user imports. Possibly null.</param> internal UserImportRequest( IEnumerable <ImportUserRecordArgs> usersToImport, UserImportOptions options) { if (usersToImport == null || usersToImport.Count() == 0) { throw new ArgumentException("Users must not be null or empty."); } if (usersToImport.Count() > MaxImportUsers) { throw new ArgumentException( $"Users list must not contain more than {MaxImportUsers} items."); } this.Users = usersToImport.Select((user) => user.ToRequest()); if (usersToImport.Any((user) => user.HasPassword())) { if (options?.Hash == null) { throw new ArgumentException( "UserImportHash option is required when at least one user has a password."); } this.HashProperties = options.GetHashProperties(); } }
public void Serialize() { var options = new UserImportOptions() { Hash = new Md5 { Rounds = 5 }, }; var expectedResult = new Dictionary <string, object> { { "rounds", 5 }, { "hashAlgorithm", "MD5" }, }; Assert.Equal(expectedResult, options.GetHashProperties()); }
public void UserImportOptionsNoHash() { var options = new UserImportOptions(); Assert.Throws <ArgumentException>(() => options.GetHashProperties()); }