| | 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.Search.Tests.Utilities |
| | 6 | | { |
| | 7 | | using System.Linq; |
| | 8 | | using Management.ResourceManager; |
| | 9 | | using Management.ResourceManager.Models; |
| | 10 | | using Microsoft.Rest.ClientRuntime.Azure.TestFramework; |
| | 11 | | using Xunit; |
| | 12 | |
|
| | 13 | | public class ResourceGroupFixture : IResourceFixture |
| | 14 | | { |
| | 15 | | private const string SearchNamespace = "Microsoft.Search"; |
| | 16 | |
|
| 1806 | 17 | | public string Location { get; private set; } |
| | 18 | |
|
| 4214 | 19 | | public string ResourceGroupName { get; private set; } |
| | 20 | |
|
| | 21 | | public virtual void Initialize(MockContext context) |
| | 22 | | { |
| 602 | 23 | | ResourceManagementClient client = context.GetServiceClient<ResourceManagementClient>(); |
| | 24 | |
|
| | 25 | | // Register subscription and get a valid location for search services. |
| 602 | 26 | | Provider provider = client.Providers.Register(SearchNamespace); |
| 602 | 27 | | Assert.NotNull(provider); |
| | 28 | |
|
| | 29 | | // We only support one resource type. |
| 602 | 30 | | Location = provider.ResourceTypes.First().Locations.First(); |
| | 31 | |
|
| | 32 | | // Create resource group |
| 602 | 33 | | ResourceGroupName = SearchTestUtilities.GenerateName(); |
| 602 | 34 | | ResourceGroup resourceGroup = |
| 602 | 35 | | client.ResourceGroups.CreateOrUpdate(ResourceGroupName, new ResourceGroup() { Location = Location }); |
| 602 | 36 | | Assert.NotNull(resourceGroup); |
| 602 | 37 | | } |
| | 38 | |
|
| | 39 | | public virtual void Cleanup() |
| | 40 | | { |
| | 41 | | // Nothing to cleanup. |
| 602 | 42 | | } |
| | 43 | | } |
| | 44 | | } |