/// <summary> /// Initializes a new instance of the <see cref="StorageCacheTestFixture"/> class. /// </summary> public StorageCacheTestFixture() { notes = new List <string>(); notes.Add("Starting StorageCacheTestFixture"); using (this.Context = new StorageCacheTestContext(this)) { notes.Add("StorageCacheTestFixture Using New Context"); notes.Add(Context.notes.ToString()); this.Context = new StorageCacheTestContext(this); try { notes.Add("StorageCacheTestFixture Using Second New Context"); notes.Add(Context.notes.ToString()); notes.Add("StorageCacheTestFixture After Second StorageCacheTestContext"); StorageCacheManagementClient storagecacheMgmtClient = this.Context.GetClient <StorageCacheManagementClient>(); storagecacheMgmtClient.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion; notes.Add("StorageCacheTestFixture After GetClient."); notes.Add(Context.notes.ToString()); if (string.IsNullOrEmpty(StorageCacheTestEnvironmentUtilities.ResourceGroupName) && string.IsNullOrEmpty(StorageCacheTestEnvironmentUtilities.CacheName)) { this.resGroupName = StorageCacheTestUtilities.GenerateName(StorageCacheTestEnvironmentUtilities.ResourcePrefix); this.virNetworkName = "VNet-" + this.resGroupName; this.subnetName = "Subnet-" + this.resGroupName; this.cacheName = "Cache-" + this.resGroupName; notes.Add($"StorageCacheTestFixture ResourceGroupName && CacheName is null or empty, using Group Name {resGroupName}, Vnet {virNetworkName}, Subnet {subnetName}, Cache {cacheName}."); } else { this.resGroupName = StorageCacheTestEnvironmentUtilities.ResourceGroupName; this.cacheName = StorageCacheTestEnvironmentUtilities.CacheName; this.ResourceGroup = this.Context.GetOrCreateResourceGroup(this.resGroupName, StorageCacheTestEnvironmentUtilities.Location); this.Cache = this.Context.GetCacheIfExists(this.ResourceGroup, this.cacheName); notes.Add($"StorageCacheTestFixture ResourceGroupName && CacheName is not null or empty, using Group Name {resGroupName}, Cache {cacheName}."); notes.Add("SCTFixture Get cache if exists."); notes.Add(Context.notes.ToString()); if (this.Cache != null) { Match subnetMatch = SubnetRegex.Match(this.Cache.Subnet); this.virNetworkName = subnetMatch.Groups["VNetName"].Value; this.subnetName = subnetMatch.Groups["SubnetName"].Value; notes.Add($"SCTFixture Cache is not null using vnet {virNetworkName} and subnet {subnetName}"); } else { this.virNetworkName = "VNet-" + this.resGroupName; this.subnetName = "Subnet-" + this.resGroupName; notes.Add($"SCTFixture Cache is null using vnet {virNetworkName} and subnet {subnetName}"); } } if (this.ResourceGroup == null) { notes.Add("SCTFixture ResourceGroup is null. Get or create resource group"); this.ResourceGroup = this.Context.GetOrCreateResourceGroup(this.resGroupName, StorageCacheTestEnvironmentUtilities.Location); notes.Add(Context.notes.ToString()); } this.VirtualNetwork = this.Context.GetOrCreateVirtualNetwork(this.ResourceGroup, this.virNetworkName); this.SubNet = this.Context.GetOrCreateSubnet(this.ResourceGroup, this.VirtualNetwork, this.subnetName); notes.Add("SCTFixture Get or create vnet and subnet."); notes.Add(Context.notes.ToString()); this.SubscriptionID = StorageCacheTestEnvironmentUtilities.SubscriptionId(); notes.Add($"SCTFixture Using subscription id {SubscriptionID.ToString()}."); this.CacheHelper = new CacheHelper(this.SubscriptionID, storagecacheMgmtClient, this.ResourceGroup, this.VirtualNetwork, this.SubNet); notes.Add($"SCTFixture New CacheHelper"); notes.Add(CacheHelper.notes.ToString()); var sku = StorageCacheTestEnvironmentUtilities.CacheSku; var size = StorageCacheTestEnvironmentUtilities.CacheSize; var int_size = int.Parse(size); if (this.Cache == null) { this.Cache = null; CacheIdentity cacheIdentity; if (StorageCacheTestEnvironmentUtilities.APIVersion == "2019-11-01") { cacheIdentity = new CacheIdentity() { Type = CacheIdentityType.None }; } else { cacheIdentity = new CacheIdentity() { Type = CacheIdentityType.SystemAssigned }; } CacheNetworkSettings cacheNetworkSettings = new CacheNetworkSettings(); cacheNetworkSettings.NtpServer = "time.windows.com"; cacheNetworkSettings.Mtu = 1500; // Build up cache security settings. CacheSecuritySettings cacheSecuritySettings = new CacheSecuritySettings(); NfsAccessPolicy nfsAccessPolicy = new NfsAccessPolicy(); nfsAccessPolicy.Name = "testAccessPolicy"; NfsAccessRule nfsAccessRule = new NfsAccessRule { Access = "rw", Scope = "default", Suid = false, SubmountAccess = true, RootSquash = false }; List <NfsAccessRule> accessRules = new List <NfsAccessRule>(); accessRules.Add(nfsAccessRule); nfsAccessPolicy.AccessRules = accessRules; List <NfsAccessPolicy> accessPolicies = new List <NfsAccessPolicy>(); accessPolicies.Add(nfsAccessPolicy); cacheSecuritySettings.AccessPolicies = accessPolicies; notes.Add("SCTFixture CacheHelper Create Cache"); this.Cache = this.CacheHelper.Create(this.cacheName, sku, int_size, identity: cacheIdentity, networkSettings: cacheNetworkSettings); if (HttpMockServer.Mode == HttpRecorderMode.Record) { notes.Add("SCTFixture CacheHelper Create Cache Record Mode Check Cache State"); this.CacheHelper.CheckCacheState(this.cacheName); } } } catch (Exception) { this.Context.Dispose(); throw; } } notes.Add("SCTFixture End"); }
/// <summary> /// Initializes a new instance of the <see cref="StorageCacheTestFixture"/> class. /// </summary> public StorageCacheTestFixture() { using (this.Context = new StorageCacheTestContext(this)) { this.Context = new StorageCacheTestContext(this); try { StorageCacheManagementClient storagecacheMgmtClient = this.Context.GetClient <StorageCacheManagementClient>(); storagecacheMgmtClient.ApiVersion = Constants.DefaultAPIVersion; if (string.IsNullOrEmpty(StorageCacheTestEnvironmentUtilities.ResourceGroupName) && string.IsNullOrEmpty(StorageCacheTestEnvironmentUtilities.CacheName)) { this.resGroupName = StorageCacheTestUtilities.GenerateName(StorageCacheTestEnvironmentUtilities.ResourcePrefix); this.virNetworkName = "VNet-" + this.resGroupName; this.subnetName = "Subnet-" + this.resGroupName; this.cacheName = "Cache-" + this.resGroupName; } else { this.resGroupName = StorageCacheTestEnvironmentUtilities.ResourceGroupName; this.cacheName = StorageCacheTestEnvironmentUtilities.CacheName; this.ResourceGroup = this.Context.GetOrCreateResourceGroup(this.resGroupName, StorageCacheTestEnvironmentUtilities.Location); this.Cache = this.Context.GetCacheIfExists(this.ResourceGroup, this.cacheName); if (this.Cache != null) { Match subnetMatch = SubnetRegex.Match(this.Cache.Subnet); this.virNetworkName = subnetMatch.Groups["VNetName"].Value; this.subnetName = subnetMatch.Groups["SubnetName"].Value; } else { this.virNetworkName = "VNet-" + this.resGroupName; this.subnetName = "Subnet-" + this.resGroupName; } } if (this.ResourceGroup == null) { this.ResourceGroup = this.Context.GetOrCreateResourceGroup(this.resGroupName, StorageCacheTestEnvironmentUtilities.Location); } this.VirtualNetwork = this.Context.GetOrCreateVirtualNetwork(this.ResourceGroup, this.virNetworkName); this.SubNet = this.Context.GetOrCreateSubnet(this.ResourceGroup, this.VirtualNetwork, this.subnetName); this.SubscriptionID = StorageCacheTestEnvironmentUtilities.SubscriptionId(); this.CacheHelper = new CacheHelper(this.SubscriptionID, storagecacheMgmtClient, this.ResourceGroup, this.VirtualNetwork, this.SubNet); var sku = StorageCacheTestEnvironmentUtilities.CacheSku; var size = StorageCacheTestEnvironmentUtilities.CacheSize; var int_size = int.Parse(size); if (this.Cache == null) { this.Cache = null; this.Cache = this.CacheHelper.Create(this.cacheName, sku, int_size); if (HttpMockServer.Mode == HttpRecorderMode.Record) { this.CacheHelper.CheckCacheState(this.cacheName); } } } catch (Exception) { this.Context.Dispose(); throw; } } }