/// <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>
        /// Create cache.
        /// </summary>
        /// <param name="name">Name of the cache.</param>
        /// <param name="sku">Name of the SKU.</param>
        /// <param name="cacheSize">Size of cache.</param>
        /// <param name="identity">Cache identity type.</param>
        /// <param name="keyVaultResourceId">Describes a resource Id to source Key vault.</param>
        /// <param name="encryptionKeyURL">The URL referencing a key encryption key in key vault.</param>
        /// <param name="skipGet">Skip get cache before creating it.</param>
        /// <returns>Cache object.</returns>
        public Cache Create(string name, string sku, int cacheSize, CacheIdentity identity, KeyVaultKeyReferenceSourceVault keyVaultResourceId = null, string encryptionKeyURL = null, bool skipGet = false,
                            CacheNetworkSettings networkSettings = null, CacheSecuritySettings securitySettings = null)
        {
            Cache cache;
            CacheEncryptionSettings cacheEncryptionSettings;
            CacheNetworkSettings    cacheNetworkSettings;
            CacheSecuritySettings   cacheSecuritySettings;
            KeyVaultKeyReference    keyVaultKeyReference;

            if (!skipGet)
            {
                try
                {
                    cache = this.Get(name);
                }
                catch (CloudErrorException ex)
                {
                    if (ex.Body.Error.Code == "ResourceNotFound")
                    {
                        cache = null;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                cache = null;
            }

            if (cache == null)
            {
                var cacheSku = new CacheSku()
                {
                    Name = sku
                };
                var subnetUri = $"/subscriptions/{this.subscriptionId}/resourcegroups/{this.resourceGroup.Name}/providers/Microsoft.Network/virtualNetworks/{this.virtualNetwork.Name}/subnets/{this.subNet.Name}";
                if (encryptionKeyURL is null || keyVaultResourceId is null)
                {
                    keyVaultKeyReference = new KeyVaultKeyReference()
                    {
                    };
                    cacheEncryptionSettings = new CacheEncryptionSettings()
                    {
                    };
                }
                else
                {
                    keyVaultKeyReference = new KeyVaultKeyReference()
                    {
                        KeyUrl      = encryptionKeyURL,
                        SourceVault = keyVaultResourceId,
                    };
                    cacheEncryptionSettings = new CacheEncryptionSettings()
                    {
                        KeyEncryptionKey = keyVaultKeyReference,
                    };
                }

                if (networkSettings is null)
                {
                    cacheNetworkSettings = new CacheNetworkSettings();
                }
                else
                {
                    cacheNetworkSettings = networkSettings;
                }

                if (securitySettings is null)
                {
                    cacheSecuritySettings = new CacheSecuritySettings();
                }
                else
                {
                    cacheSecuritySettings = securitySettings;
                }

                var cacheParameters = new Cache()
                {
                    CacheSizeGB        = cacheSize,
                    Location           = this.resourceGroup.Location,
                    Sku                = cacheSku,
                    Subnet             = subnetUri,
                    Identity           = identity,
                    EncryptionSettings = cacheEncryptionSettings,
                    SecuritySettings   = cacheSecuritySettings,
                    NetworkSettings    = cacheNetworkSettings,
                };
                cache = this.StoragecacheManagementClient.Caches.CreateOrUpdate(this.resourceGroup.Name, name, cacheParameters);
            }