| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.Management.Search.Tests |
| | 6 | | { |
| | 7 | | using System.Linq; |
| | 8 | | using Microsoft.Azure.Management.Search.Models; |
| | 9 | | using Microsoft.Azure.Search.Tests.Utilities; |
| | 10 | | using Xunit; |
| | 11 | |
|
| | 12 | | public sealed class QueryKeyTests : SearchTestBase<SearchServiceFixture> |
| | 13 | | { |
| | 14 | | [Fact] |
| | 15 | | public void CanListQueryKeys() |
| | 16 | | { |
| 0 | 17 | | Run(() => |
| 0 | 18 | | { |
| 0 | 19 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 20 | |
|
| 0 | 21 | | var queryKeys = |
| 0 | 22 | | searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName); |
| 0 | 23 | |
|
| 0 | 24 | | Assert.NotNull(queryKeys); |
| 0 | 25 | |
|
| 0 | 26 | | QueryKey onlyKey = queryKeys.Single(); |
| 0 | 27 | |
|
| 0 | 28 | | AssertIsValidKey(onlyKey); |
| 0 | 29 | | AssertIsDefaultKey(onlyKey); |
| 0 | 30 | | }); |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | [Fact] |
| | 34 | | public void CanCreateAndDeleteQueryKeys() |
| | 35 | | { |
| 0 | 36 | | Run(() => |
| 0 | 37 | | { |
| 0 | 38 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 39 | |
|
| 0 | 40 | | var queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName) |
| 0 | 41 | |
|
| 0 | 42 | | AssertIsDefaultKey(queryKeys.Single()); |
| 0 | 43 | |
|
| 0 | 44 | | QueryKey newKey = searchMgmt.QueryKeys.Create(Data.ResourceGroupName, Data.SearchServiceName, "my key"); |
| 0 | 45 | |
|
| 0 | 46 | | AssertIsValidKey(newKey, "my key"); |
| 0 | 47 | |
|
| 0 | 48 | | queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName); |
| 0 | 49 | |
|
| 0 | 50 | | Assert.Equal(2, queryKeys.Count()); |
| 0 | 51 | | AssertIsDefaultKey(queryKeys.First()); |
| 0 | 52 | |
|
| 0 | 53 | | Assert.Equal(newKey.Name, queryKeys.ElementAt(1).Name); |
| 0 | 54 | | Assert.Equal(newKey.Key, queryKeys.ElementAt(1).Key); |
| 0 | 55 | |
|
| 0 | 56 | | searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key); |
| 0 | 57 | |
|
| 0 | 58 | | queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName); |
| 0 | 59 | |
|
| 0 | 60 | | AssertIsDefaultKey(queryKeys.Single()); |
| 0 | 61 | | }); |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | [Fact] |
| | 65 | | public void DeleteQueryKeyIsIdempotent() |
| | 66 | | { |
| 0 | 67 | | Run(() => |
| 0 | 68 | | { |
| 0 | 69 | | SearchManagementClient searchMgmt = GetSearchManagementClient(); |
| 0 | 70 | | QueryKey newKey = searchMgmt.QueryKeys.Create(Data.ResourceGroupName, Data.SearchServiceName, "my key"); |
| 0 | 71 | | searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key); |
| 0 | 72 | | searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key); |
| 0 | 73 | | }); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | private static void AssertIsDefaultKey(QueryKey key) |
| | 77 | | { |
| 0 | 78 | | Assert.Null(key.Name); // Default key has no name. |
| 0 | 79 | | } |
| | 80 | |
|
| | 81 | | private static void AssertIsValidKey(QueryKey key, string expectedName = null) |
| | 82 | | { |
| 0 | 83 | | Assert.NotNull(key); |
| 0 | 84 | | Assert.NotNull(key.Key); |
| 0 | 85 | | Assert.NotEmpty(key.Key); |
| | 86 | |
|
| 0 | 87 | | if (expectedName != null) |
| | 88 | | { |
| 0 | 89 | | Assert.Equal(expectedName, key.Name); |
| | 90 | | } |
| 0 | 91 | | } |
| | 92 | | } |
| | 93 | | } |