< Summary

Class:Microsoft.Azure.Management.Search.Tests.QueryKeyTests
Assembly:Search.Management.Tests
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\tests\Tests\QueryKeyTests.cs
Covered lines:0
Uncovered lines:58
Coverable lines:58
Total lines:93
Line coverage:0% (0 of 58)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
CanListQueryKeys()-0%100%
CanCreateAndDeleteQueryKeys()-0%100%
DeleteQueryKeyIsIdempotent()-0%100%
AssertIsDefaultKey(...)-0%100%
AssertIsValidKey(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Management.Search\tests\Tests\QueryKeyTests.cs

#LineLine coverage
 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
 5namespace 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        {
 017            Run(() =>
 018            {
 019                SearchManagementClient searchMgmt = GetSearchManagementClient();
 020
 021                var queryKeys =
 022                    searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName);
 023
 024                Assert.NotNull(queryKeys);
 025
 026                QueryKey onlyKey = queryKeys.Single();
 027
 028                AssertIsValidKey(onlyKey);
 029                AssertIsDefaultKey(onlyKey);
 030            });
 031        }
 32
 33        [Fact]
 34        public void CanCreateAndDeleteQueryKeys()
 35        {
 036            Run(() =>
 037            {
 038                SearchManagementClient searchMgmt = GetSearchManagementClient();
 039
 040                var queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName)
 041
 042                AssertIsDefaultKey(queryKeys.Single());
 043
 044                QueryKey newKey = searchMgmt.QueryKeys.Create(Data.ResourceGroupName, Data.SearchServiceName, "my key");
 045
 046                AssertIsValidKey(newKey, "my key");
 047
 048                queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName);
 049
 050                Assert.Equal(2, queryKeys.Count());
 051                AssertIsDefaultKey(queryKeys.First());
 052
 053                Assert.Equal(newKey.Name, queryKeys.ElementAt(1).Name);
 054                Assert.Equal(newKey.Key, queryKeys.ElementAt(1).Key);
 055
 056                searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key);
 057
 058                queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName);
 059
 060                AssertIsDefaultKey(queryKeys.Single());
 061            });
 062        }
 63
 64        [Fact]
 65        public void DeleteQueryKeyIsIdempotent()
 66        {
 067            Run(() =>
 068            {
 069                SearchManagementClient searchMgmt = GetSearchManagementClient();
 070                QueryKey newKey = searchMgmt.QueryKeys.Create(Data.ResourceGroupName, Data.SearchServiceName, "my key");
 071                searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key);
 072                searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key);
 073            });
 074        }
 75
 76        private static void AssertIsDefaultKey(QueryKey key)
 77        {
 078            Assert.Null(key.Name);   // Default key has no name.
 079        }
 80
 81        private static void AssertIsValidKey(QueryKey key, string expectedName = null)
 82        {
 083            Assert.NotNull(key);
 084            Assert.NotNull(key.Key);
 085            Assert.NotEmpty(key.Key);
 86
 087            if (expectedName != null)
 88            {
 089                Assert.Equal(expectedName, key.Name);
 90            }
 091        }
 92    }
 93}