У меня есть библиотека, которая работает с Azure AD B2C (я знаю, что она недоступна для новых клиентов). И у меня есть набор тестов для этого. И до недавнего времени все было зеленым. Теперь мне пришлось добавить огромные задержки в тестах, чтобы они могли пройти.
Например, тест:
public async Task EnableUser(string userId)
{
using (_logger.BeginScope(nameof(EnableUser)))
{
try
{
IlgAdUser user = await GetUserById(userId).ConfigureAwait(false) ??
throw new IlgGraphClientException($"Failed to enable user: User with Id={userId} not found in the Directory");
User usr = new()
{
AccountEnabled = true
};
// the returned user value is NULL here, do not use variable
await _graphClient.Users[user.Id].PatchAsync(usr).ConfigureAwait(false);
}
catch (Exception ex)
{
string errMsg = $"Could not enable user with Id={userId}";
LogFailedToEnableUser(userId, ex);
throw new IlgGraphClientException(errMsg, ex);
}
}
}
У меня есть библиотека, которая работает с Azure AD B2C (я знаю, что она недоступна для новых клиентов). И у меня есть набор тестов для этого. И до недавнего времени все было зеленым. Теперь мне пришлось добавить огромные задержки в тестах, чтобы они могли пройти. Например, тест: [code] [Test] public async Task EnableUser() { IlgAdUser b2CUser = await _graphClient.CreateLocalUser(false, false, USER_FIRSTNAME_S, USER_LASTNAME_S, "some-password", USR_EMAIL_S); b2CUser.AccountEnabled.Should().Be(false);
}; ... try { User newUser = await _graphClient.Users.PostAsync(user).ConfigureAwait(false) ?? throw new IlgGraphClientException("Failed to create new user");
if (string.IsNullOrEmpty(newUser.Id)) throw new IlgGraphClientException("Failed to create new user: Id is empty"); IlgAdUser loaded = await GetUserById(newUser.Id).ConfigureAwait(false) ?? throw new IlgGraphClientException($"User with email='{email}' is created but subsequent load operation failed"); return loaded; } catch (ODataError ex) { if (!ex.Message.Equals("A conflicting object with one or more of the specified property values is present in the directory.")) throw;
string errMsg = $"User with same email already exists {email}"; LogFailedToAddUserEmailAlreadyTaken(email, ex); throw new IlgGraphClientUserExistsException(errMsg, ex); } catch (Exception ex) { string errMsg = $"Could not create new user with email='{email}'."; LogFailedToCreateNewUser(email, ex); throw new IlgGraphClientException(errMsg, ex); } } [/code] EnableUser(): [code] public async Task EnableUser(string userId) { using (_logger.BeginScope(nameof(EnableUser))) { try { IlgAdUser user = await GetUserById(userId).ConfigureAwait(false) ?? throw new IlgGraphClientException($"Failed to enable user: User with Id={userId} not found in the Directory");
User usr = new() { AccountEnabled = true };
// the returned user value is NULL here, do not use variable await _graphClient.Users[user.Id].PatchAsync(usr).ConfigureAwait(false); } catch (Exception ex) { string errMsg = $"Could not enable user with Id={userId}"; LogFailedToEnableUser(userId, ex); throw new IlgGraphClientException(errMsg, ex); } } } [/code] GetUserById(): [code] public async Task GetUserById(string userId) { using (_logger.BeginScope(nameof(GetUserById))) { if (string.IsNullOrWhiteSpace(userId)) throw new ArgumentNullException(nameof(userId));
try { IEnumerable users = await GetUsers($"id eq '{userId}'").ConfigureAwait(false); IEnumerable usersArr = users as IlgAdUser[] ?? [..users]; return !usersArr.Any() ? null : usersArr.First(); } catch (Exception ex) { LogFailedToLoadUserById(userId, ex); string errMsg = $"Could not get user with Id={userId}"; throw new IlgGraphClientException(errMsg, ex); } } } [/code] и GetUsers(): [code] public async Task GetUsers(string? filter = null) { using (_logger.BeginScope("GetUsers")) { try { string[] selectAttributes = await MakeUserAttributesList().ConfigureAwait(false);
return await RetrieveUsersForRequestSortedByFullName(userColResp).ConfigureAwait(false); } catch (Exception ex) { LogFailedToLoadUsers(filter, ex); const string ERR_MGS_S = "Could not get all users"; throw new IlgGraphClientException(ERR_MGS_S, ex); } } } [/code] Кто-нибудь знает, почему тест теперь требует огромной задержки?