public async Task TestApiKeys() { ApiKey apiKeyToSend = new ApiKey { Acl = new List <string> { "search" }, Description = "A description", Indexes = new List <string> { "indexes" }, MaxHitsPerQuery = 1000, MaxQueriesPerIPPerHour = 1000, QueryParameters = "typoTolerance=strict", Referers = new List <string> { "referer" }, Validity = 600 }; AddApiKeyResponse addKeyResponse = await BaseTest.SearchClient.AddApiKeyAsync(apiKeyToSend); _apiKey = addKeyResponse.Key; apiKeyToSend.Value = _apiKey; addKeyResponse.Wait(); var addedKey = await BaseTest.SearchClient.GetApiKeyAsync(_apiKey); Assert.IsTrue(TestHelper.AreObjectsEqual(apiKeyToSend, addedKey, "CreatedAt", "Validity", "GetApiKeyDelegate", "Key")); ListApiKeysResponse allKeys = await BaseTest.SearchClient.ListApiKeysAsync(); Assert.IsTrue(allKeys.Keys.Exists(x => x.Value.Equals(_apiKey))); apiKeyToSend.MaxHitsPerQuery = 42; var updateKey = await BaseTest.SearchClient.UpdateApiKeyAsync(apiKeyToSend); updateKey.Wait(); var getUpdatedKey = await BaseTest.SearchClient.GetApiKeyAsync(_apiKey); Assert.IsTrue(getUpdatedKey.MaxHitsPerQuery == 42); var deleteApiKey = await BaseTest.SearchClient.DeleteApiKeyAsync(_apiKey); deleteApiKey.Wait(); var restoreAPIKey = await BaseTest.SearchClient.RestoreApiKeyAsync(_apiKey); restoreAPIKey.Wait(); await BaseTest.SearchClient.GetApiKeyAsync(_apiKey); await BaseTest.SearchClient.DeleteApiKeyAsync(_apiKey); }
public async Task TestApiKeys() { ApiKey apiKeyToSend = new ApiKey { Acl = new List <string> { "search" }, Description = "A description", Indexes = new List <string> { "indexes" }, MaxHitsPerQuery = 1000, MaxQueriesPerIPPerHour = 1000, QueryParameters = "typoTolerance=strict", Referers = new List <string> { "referer" }, Validity = 600 }; AddApiKeyResponse addKeyResponse = await BaseTest.SearchClient.AddApiKeyAsync(apiKeyToSend); _apiKey = addKeyResponse.Key; apiKeyToSend.Value = _apiKey; addKeyResponse.Wait(); var addedKey = await BaseTest.SearchClient.GetApiKeyAsync(_apiKey); Assert.IsTrue(TestHelper.AreObjectsEqual(apiKeyToSend, addedKey, "CreatedAt", "Validity", "GetApiKeyDelegate", "Key")); ListApiKeysResponse allKeys = await BaseTest.SearchClient.ListApiKeysAsync(); Assert.IsTrue(allKeys.Keys.Exists(x => x.Value.Equals(_apiKey))); apiKeyToSend.MaxHitsPerQuery = 42; var updateKey = await BaseTest.SearchClient.UpdateApiKeyAsync(apiKeyToSend); updateKey.Wait(); var getUpdatedKey = await BaseTest.SearchClient.GetApiKeyAsync(_apiKey); Assert.That(getUpdatedKey.MaxHitsPerQuery, Is.EqualTo(42)); var deleteApiKey = await BaseTest.SearchClient.DeleteApiKeyAsync(_apiKey); deleteApiKey.Wait(); TestHelper.Retry(async() => { bool shouldRetry; try { var restoreAPIKey = await BaseTest.SearchClient.RestoreApiKeyAsync(_apiKey); restoreAPIKey.Wait(); shouldRetry = false; } catch (AlgoliaApiException e) { shouldRetry = e.HttpErrorCode == 404 && e.Message == "Key already exists"; } return(shouldRetry); }, TimeSpan.FromSeconds(1), 10); await BaseTest.SearchClient.GetApiKeyAsync(_apiKey); await BaseTest.SearchClient.DeleteApiKeyAsync(_apiKey); }