public void CanCreateAD() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); HttpStatusCode[] statusSuccess = { HttpStatusCode.OK, HttpStatusCode.Accepted }; ActiveDirectoryConfigParameter payload = new ActiveDirectoryConfigParameter() { DomainName = "MyDomain", UserName = "******", Password = "******" }; OperationResultWithTrackingId result = null; Assert.DoesNotThrow(() => { result = remoteAppManagementClient.Collections.SetAd("testd112", payload); }); Assert.NotNull(result); Assert.True(result.StatusCode == HttpStatusCode.OK || result.StatusCode == HttpStatusCode.Accepted); if (result.StatusCode == HttpStatusCode.Accepted) { Assert.NotNull(result.TrackingId); } } }
public void CanGetCollectionUsageDetails() { using (var undoContext = UndoContext.Current) { undoContext.Start(); var client = GetRemoteAppManagementClient(); CollectionUsageDetailsResult usageDetails = client.Collections.GetUsageDetails("simple", "2015", "2", "en-us"); Assert.NotNull(usageDetails); Assert.Equal(HttpStatusCode.OK, usageDetails.StatusCode); Assert.NotNull(usageDetails.UsageDetails.OperationTrackingId); Assert.NotNull(usageDetails.UsageDetails.SasUri); // ensure that the tracking id is valid one and can get the operation status AssertLongrunningOperation(client, RemoteAppOperationStatus.Success, usageDetails.UsageDetails.OperationTrackingId); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); if (mode == HttpRecorderMode.Record) { // these tests only can be executed during the record mode as the URI is not valid without the proper creds WebClient webClient = new WebClient(); byte[] detailUsage = webClient.DownloadData(new Uri(usageDetails.UsageDetails.SasUri)); Assert.NotNull(detailUsage); Assert.NotEmpty(detailUsage); } } }
private HttpClient CreateHttpClient( HttpRecorderMode mode, [CallerMemberName] string testName = "", IInteractionRepository repository = null) => new HttpClient(new HttpRecorderDelegatingHandler(testName, mode: mode, repository: repository)) { BaseAddress = _fixture.ServerUri, };
static BaseTests() { #if RECORD_MODE TrainingKey = ""; RecorderMode = HttpRecorderMode.Record; HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); var executingAssemblyPath = new Uri(typeof(BaseTests).GetTypeInfo().Assembly.CodeBase); HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath.AbsolutePath), @"..\..\..\SessionRecords"); #endif }
public void CanCreateVnet() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); string vnetName = "hkutvnet1"; VNetParameter payload = new VNetParameter() { Region = "West US", VnetAddressSpaces = new List <string> { "172.16.0.0/16" }, LocalAddressSpaces = new List <string> { "11.0.0.0/16" }, DnsServers = new List <string>() { "10.0.0.1" }, VpnAddress = "13.0.0.1", GatewayType = GatewayType.StaticRouting }; Assert.DoesNotThrow(() => { OperationResultWithTrackingId result = remoteAppManagementClient.VNet.CreateOrUpdate(vnetName, payload); Assert.NotNull(result); Assert.True(result.StatusCode == HttpStatusCode.OK || result.StatusCode == HttpStatusCode.Accepted, "StatusCode = " + result.StatusCode + "is not one of the expected"); if (result.StatusCode == HttpStatusCode.Accepted) { Assert.NotNull(result.TrackingId); } // verify the creation VNetResult vnet = remoteAppManagementClient.VNet.Get(vnetName, false); Assert.NotNull(vnet); Assert.Equal(HttpStatusCode.OK, vnet.StatusCode); Assert.NotNull(vnet.VNet); Assert.Equal(vnetName, vnet.VNet.Name); Assert.Equal(payload.VpnAddress, vnet.VNet.VpnAddress); Assert.Equal(payload.GatewayType, vnet.VNet.GatewayType); Assert.Equal(payload.Region, vnet.VNet.Region); }); } }
public void CanGetUploadScript() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); UploadScriptResult scriptResult = remoteAppManagementClient.TemplateImages.GetUploadScript(); Assert.NotNull(scriptResult); Assert.NotNull(scriptResult.Script); } }
public void CanEnsureStorageInRegion() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); // Assume region to be "West US" for test purposes OperationResultWithTrackingId ensureResult = remoteAppManagementClient.TemplateImages.EnsureStorageInRegion("West US"); Assert.NotNull(ensureResult); } }
/// <summary> /// Initializes a new instance of the <see cref="HttpRecorderDelegatingHandler" /> class. /// </summary> /// <param name="interactionName"> /// The name of the interaction. /// If you use the default <see cref="IInteractionRepository"/>, this will be the path to the HAR file (relative or absolute) and /// if no file extension is provided, .har will be used. /// </param> /// <param name="mode">The <see cref="HttpRecorderMode" />. Defaults to <see cref="HttpRecorderMode.Auto" />.</param> /// <param name="matcher"> /// The <see cref="IRequestMatcher"/> to use to match interactions with incoming <see cref="HttpRequestMessage"/>. /// Defaults to matching Once by <see cref="HttpMethod"/> and <see cref="HttpRequestMessage.RequestUri"/>. /// <see cref="RulesMatcher.ByHttpMethod"/> and <see cref="RulesMatcher.ByRequestUri"/>. /// </param> /// <param name="repository"> /// The <see cref="IInteractionRepository"/> to use to read/write the interaction. /// Defaults to <see cref="HttpArchiveInteractionRepository"/>. /// </param> /// <param name="anonymizer"> /// The <see cref="IInteractionAnonymizer"/> to use to anonymize the interaction. /// Defaults to <see cref="RulesInteractionAnonymizer.Default"/>. /// </param> public HttpRecorderDelegatingHandler( string interactionName, HttpRecorderMode mode = HttpRecorderMode.Auto, IRequestMatcher matcher = null, IInteractionRepository repository = null, IInteractionAnonymizer anonymizer = null) { InteractionName = interactionName; Mode = mode; _matcher = matcher ?? RulesMatcher.MatchOnce.ByHttpMethod().ByRequestUri(); _repository = repository ?? new HttpArchiveInteractionRepository(); _anonymizer = anonymizer ?? RulesInteractionAnonymizer.Default; }
/// <summary> /// Initializes a new instance of the <see cref="HttpRecorderDelegatingHandler" /> class. /// </summary> /// <param name="interactionName"> /// The name of the interaction. /// If you use the default <see cref="IInteractionRepository"/>, this will be the path to the HAR file (relative or absolute) and /// if no file extension is provided, .har will be used. /// </param> /// <param name="mode">The <see cref="HttpRecorderMode" />. Defaults to <see cref="HttpRecorderMode.Auto" />.</param> /// <param name="innerHandler">The inner <see cref="HttpMessageHandler" /> to configure. If not provided, <see cref="HttpClientHandler" /> will be used.</param> /// <param name="matcher"> /// The <see cref="IRequestMatcher"/> to use to match interactions with incoming <see cref="HttpRequestMessage"/>. /// Defaults to matching Once by <see cref="HttpMethod"/> and <see cref="HttpRequestMessage.RequestUri"/>. /// <see cref="RulesMatcher.ByHttpMethod"/> and <see cref="RulesMatcher.ByRequestUri"/>. /// </param> /// <param name="repository"> /// The <see cref="IInteractionRepository"/> to use to read/write the interaction. /// Defaults to <see cref="HttpArchiveInteractionRepository"/>. /// </param> public HttpRecorderDelegatingHandler( string interactionName, HttpRecorderMode mode = HttpRecorderMode.Auto, HttpMessageHandler innerHandler = null, IRequestMatcher matcher = null, IInteractionRepository repository = null) : base(innerHandler ?? new HttpClientHandler()) { InteractionName = interactionName; Mode = mode; _matcher = matcher ?? RulesMatcher.MatchOnce.ByHttpMethod().ByRequestUri(); _repository = repository ?? new HttpArchiveInteractionRepository(); }
static BaseTests() { ProjectId = Guid.Parse("32cb8dd6-19f8-4f08-afef-360b2e46274e"); #if RECORD_MODE PredictionKey = ""; RecorderMode = HttpRecorderMode.Record; HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); var executingAssemblyPath = new Uri(typeof(BaseTests).GetTypeInfo().Assembly.CodeBase); HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath.AbsolutePath), @"..\..\..\SessionRecords"); #endif }
public void CanResetVpnSharedKey() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); Assert.DoesNotThrow(() => { string vNet = "hkutvnet1"; // lets remember the vpn shared key before the reset request VNetResult vnetBefore = remoteAppManagementClient.VNet.Get(vNet, true); Assert.Equal(HttpStatusCode.OK, vnetBefore.StatusCode); Assert.NotNull(vnetBefore.VNet); Assert.Equal(vNet, vnetBefore.VNet.Name); Assert.NotNull(vnetBefore.VNet.SharedKey); // now reset the key OperationResultWithTrackingId result = remoteAppManagementClient.VNet.ResetVpnSharedKey(vNet); Assert.NotNull(result); Assert.InRange(result.StatusCode, HttpStatusCode.OK, HttpStatusCode.Accepted); if (result.StatusCode == HttpStatusCode.Accepted) { Assert.NotNull(result.TrackingId); TrackingId = result.TrackingId; } VNetOperationStatusResult vnetOperationResult = remoteAppManagementClient.VNet.GetResetVpnSharedKeyOperationStatus(TrackingId); Assert.NotNull(vnetOperationResult); Assert.Equal(HttpStatusCode.OK, vnetOperationResult.StatusCode); // lets check if the key is actually reset VNetResult vnetAfter = remoteAppManagementClient.VNet.Get(vNet, true); Assert.Equal(HttpStatusCode.OK, vnetAfter.StatusCode); Assert.NotNull(vnetAfter.VNet); Assert.Equal(vNet, vnetAfter.VNet.Name); Assert.NotNull(vnetAfter.VNet.SharedKey); // make sure that the key before and after does not match Assert.NotEqual(vnetBefore.VNet.SharedKey, vnetAfter.VNet.SharedKey); }); } }
public void CanListTemplateImagesSuccessfully() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); Assert.DoesNotThrow(() => { TemplateImageListResult response = remoteAppManagementClient.TemplateImages.List(); IList <TemplateImage> templateImageList = response.RemoteAppTemplateImageList; }); } }
public void CanExportUserDisk() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); string collectionName = "collectionname"; string accountKey = "accountkey"; string accountName = "accountname"; string containerName = "containername"; OperationResultWithTrackingId result = remoteAppManagementClient.UserDisks.Migrate(collectionName, accountName, accountKey, containerName, true); Assert.NotNull(result); } }
public void CanDeleteVnet() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); VNet vnet = null; // verify the creation VNetListResult vnetList = null; Assert.DoesNotThrow(() => { vnetList = remoteAppManagementClient.VNet.List(); }); Assert.NotNull(vnetList); Assert.Equal(HttpStatusCode.OK, vnetList.StatusCode); Assert.NotNull(vnetList.VNetList); Assert.NotEmpty(vnetList.VNetList); foreach (VNet v in vnetList.VNetList) { if (Regex.IsMatch(v.Name, @"^hkutvnet")) { // found a match if (v.State == VNetState.Connecting || v.State == VNetState.Ready) { vnet = v; break; } } } Assert.NotNull(vnet); OperationResultWithTrackingId deleteResult = remoteAppManagementClient.VNet.Delete(vnet.Name); Assert.NotNull(deleteResult); Assert.True(deleteResult.StatusCode == HttpStatusCode.OK || deleteResult.StatusCode == HttpStatusCode.Accepted, "StatusCode = " + deleteResult.StatusCode + "is not one of the expected"); if (deleteResult.StatusCode == HttpStatusCode.Accepted) { Assert.NotNull(deleteResult.TrackingId); } } }
private HttpClient CreateHttpClient( [CallerMemberName] string testName = "", [CallerFilePath] string filePath = "", HttpRecorderMode mode = HttpRecorderMode.Auto, IRequestMatcher matcher = null) { var interactionName = Path.Join( Path.GetDirectoryName(filePath), $"{Path.GetFileNameWithoutExtension(filePath)}Fixtures", testName); return(new HttpClient(new HttpRecorderDelegatingHandler(interactionName, mode: mode, matcher: matcher)) { BaseAddress = new Uri("https://reqres.in/"), }); }
/// <summary> /// Adds <see cref="HttpRecorderDelegatingHandler"/> as a HttpMessageHandler in the client pipeline. /// </summary> /// <param name="httpClientBuilder">The <see cref="IHttpClientBuilder"/>.</param> /// <param name="interactionName"> /// The name of the interaction. /// If you use the default <see cref="IInteractionRepository"/>, this will be the path to the HAR file (relative or absolute) and /// if no file extension is provided, .har will be used. /// </param> /// <param name="mode">The <see cref="HttpRecorderMode" />. Defaults to <see cref="HttpRecorderMode.Auto" />.</param> /// <param name="matcher"> /// The <see cref="IRequestMatcher"/> to use to match interactions with incoming <see cref="HttpRequestMessage"/>. /// Defaults to matching Once by <see cref="HttpMethod"/> and <see cref="HttpRequestMessage.RequestUri"/>. /// <see cref="RulesMatcher.ByHttpMethod"/> and <see cref="RulesMatcher.ByRequestUri"/>. /// </param> /// <param name="repository"> /// The <see cref="IInteractionRepository"/> to use to read/write the interaction. /// Defaults to <see cref="HttpArchiveInteractionRepository"/>. /// </param> /// <param name="anonymizer"> /// The <see cref="IInteractionAnonymizer"/> to use to anonymize the interaction. /// Defaults to <see cref="RulesInteractionAnonymizer.Default"/>. /// </param> /// <returns>The updated <see cref="IHttpClientBuilder"/>.</returns> public static IHttpClientBuilder AddHttpRecorder( this IHttpClientBuilder httpClientBuilder, string interactionName, HttpRecorderMode mode = HttpRecorderMode.Auto, IRequestMatcher matcher = null, IInteractionRepository repository = null, IInteractionAnonymizer anonymizer = null) { var recorder = new HttpRecorderDelegatingHandler( interactionName, mode: mode, matcher: matcher, repository: repository, anonymizer: anonymizer); return(httpClientBuilder.AddHttpMessageHandler((sp) => recorder)); }
public void CanGetVpnConfigScript() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); Assert.DoesNotThrow(() => { string vNet = TestVnet; VNetConfigScriptResult result = remoteAppManagementClient.VNet.GetVpnDeviceConfigScript(vNet, "Cisco Systems, Inc.", "ASA 5500 Series Adaptive Security Appliances", "ASA Software 8.3"); Assert.NotNull(result); Assert.Equal(HttpStatusCode.OK, result.StatusCode); AssertNotNullOrEmpty(result.ConfigScript); }); } }
public void CanGetVnetList() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); Assert.DoesNotThrow(() => { VNetListResult result = remoteAppManagementClient.VNet.List(); Assert.NotNull(result); Assert.Equal(HttpStatusCode.OK, result.StatusCode); AssertNotNullOrEmpty(result.RequestId); ValidateVnets(result.VNetList); }); } }
static BaseTests() { #if RECORD_MODE TrainingKey = ""; RecorderMode = HttpRecorderMode.Record; HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); var executingAssemblyPath = new Uri(typeof(BaseTests).GetTypeInfo().Assembly.CodeBase); HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath.AbsolutePath), @"..\..\..\SessionRecords"); // Clean up previous run of projects at the start of this test. var client = new CustomVisionTrainingClient() { ApiKey = TrainingKey, Endpoint = Endpoint }; ProjectBuilderHelper.CleanUpOldProjects(client); #endif }
public void CanGetVpnDevices() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); Assert.DoesNotThrow(() => { string vNet = TestVnet; VNetVpnDeviceResult result = remoteAppManagementClient.VNet.GetVpnDevices(vNet); Assert.NotNull(result); Assert.Equal(HttpStatusCode.OK, result.StatusCode); ValidateVendors(result.Vendors); }); } }
public void CanGetVnet() { using (UndoContext context = UndoContext.Current) { context.Start(); HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient remoteAppManagementClient = GetRemoteAppManagementClient(); Assert.DoesNotThrow(() => { string vNet = GetVNetName(); bool includeSharedKey = false; VNetResult result = remoteAppManagementClient.VNet.Get(vNet, includeSharedKey); Assert.NotNull(result); Assert.Equal(HttpStatusCode.OK, result.StatusCode); AssertNotNullOrEmpty(result.RequestId); ValidateVnet(result.VNet); }); } }
public static void Initialize(string callerIdentity, string testIdentity, HttpRecorderMode mode) { CallerIdentity = callerIdentity; TestIdentity = testIdentity; Mode = mode; names = new AssetNames(); servers = new List <HttpMockServer>(); records = new Records(Matcher); Variables = new Dictionary <string, string>(); if (Mode == HttpRecorderMode.Playback) { string recordDir = Path.Combine(RecordsDirectory, CallerIdentity); var fileName = Path.GetFullPath(Path.Combine(recordDir, testIdentity.Replace(".json", "") + ".json")); if (!HttpMockServer.FileSystemUtilsObject.DirectoryExists(recordDir) || !HttpMockServer.FileSystemUtilsObject.FileExists(fileName)) { throw new ArgumentException( string.Format("Unable to find recorded mock file '{0}'.", fileName), "callerIdentity"); } else { RecordEntryPack pack = RecordEntryPack.Deserialize(fileName); foreach (var entry in pack.Entries) { records.Enqueue(entry); } foreach (var func in pack.Names.Keys) { pack.Names[func].ForEach(n => names.Enqueue(func, n)); } Variables = pack.Variables; if (Variables == null) { Variables = new Dictionary <string, string>(); } } } initialized = true; }
static BaseTests() { #if RECORD_MODE PredictionKey = ""; RecorderMode = HttpRecorderMode.Record; HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); var executingAssemblyPath = new Uri(typeof(BaseTests).GetTypeInfo().Assembly.CodeBase); HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath.AbsolutePath), @"..\..\..\SessionRecords"); ICustomVisionTrainingClient trainingClient = new CustomVisionTrainingClient(); trainingClient.ApiKey = ""; trainingClient.Endpoint = Endpoint; HttpMockServer.Initialize(typeof(BaseTests).Name, "Unused", RecorderMode); var predictionResourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{predictionResourceName}"; ClassificationProjectId = ProjectBuilderHelper.CreateTrainedImageClassificationProject(trainingClient, predictionResourceId).ProjectId; ObjectDetectionProjectId = ProjectBuilderHelper.CreateTrainedObjDetectionProject(trainingClient, predictionResourceId).ProjectId; #endif }
public void TestCreateUpdateGetDataMaskingRules() { string testPrefix = "sqldatamaskingcrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); // Create database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, }); Assert.NotNull(db1); // Create server firewall rule sqlClient.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, "sqltestrule", new FirewallRule() { StartIpAddress = "0.0.0.0", EndIpAddress = "255.255.255.255" }); // Create test table with columns // This is not needed in playback because in playback, there is no actual database to execute against HttpRecorderMode testMode = HttpMockServer.GetCurrentMode(); if (testMode != HttpRecorderMode.Playback) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder() { DataSource = string.Format(server.FullyQualifiedDomainName, server.Name), UserID = SqlManagementTestUtilities.DefaultLogin, Password = SqlManagementTestUtilities.DefaultPassword, InitialCatalog = dbName }; using (SqlConnection conn = new SqlConnection(builder.ConnectionString)) { conn.Open(); SqlCommand command = new SqlCommand("create table table1 (column1 int, column2 nvarchar(max))", conn); command.ExecuteNonQuery(); } } // Verify Policy is disabled to begin with DataMaskingPolicy policy = sqlClient.DataMaskingPolicies.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal(DataMaskingState.Disabled, policy.DataMaskingState); // Create a Number data masking rule (enables the data masking policy) DataMaskingRule numberRule = new DataMaskingRule() { SchemaName = "dbo", TableName = "table1", ColumnName = "column1", MaskingFunction = DataMaskingFunction.Number, NumberFrom = "0", NumberTo = "10" }; // Create a Text data masking rule DataMaskingRule textRule = new DataMaskingRule() { SchemaName = "dbo", TableName = "table1", ColumnName = "column2", MaskingFunction = DataMaskingFunction.Text, PrefixSize = "1", SuffixSize = "1", ReplacementString = "teststring" }; // Not creating datamasking rule names because name is ignored when creating the rules anyway sqlClient.DataMaskingRules.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, "name", numberRule); sqlClient.DataMaskingRules.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, "name2", textRule); // Verify Policy is now enabled policy = sqlClient.DataMaskingPolicies.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal(DataMaskingState.Enabled, policy.DataMaskingState); // List data masking rules IEnumerable <DataMaskingRule> rules = sqlClient.DataMaskingRules.ListByDatabase(resourceGroup.Name, server.Name, dbName); Assert.Equal(2, rules.Count()); // Verify number rule numberRule = rules.FirstOrDefault(rule => rule.MaskingFunction == DataMaskingFunction.Number); Assert.Equal("dbo", numberRule.SchemaName); Assert.Equal("table1", numberRule.TableName); Assert.Equal("column1", numberRule.ColumnName); Assert.Equal("0", numberRule.NumberFrom); Assert.Equal("10", numberRule.NumberTo); // Verify text rule textRule = rules.FirstOrDefault(rule => rule.MaskingFunction == DataMaskingFunction.Text); Assert.Equal("dbo", textRule.SchemaName); Assert.Equal("table1", textRule.TableName); Assert.Equal("column2", textRule.ColumnName); Assert.Equal("1", textRule.PrefixSize); Assert.Equal("1", textRule.SuffixSize); Assert.Equal("teststring", textRule.ReplacementString); // Delete one rule through PUT numberRule.RuleState = DataMaskingRuleState.Disabled; sqlClient.DataMaskingRules.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, "name", numberRule); // List data masking rules rules = sqlClient.DataMaskingRules.ListByDatabase(resourceGroup.Name, server.Name, dbName); Assert.Equal(1, rules.Count()); // Verify Policy now enabled policy = sqlClient.DataMaskingPolicies.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal(DataMaskingState.Enabled, policy.DataMaskingState); // Disable data masking policy (this deletes data masking rules) sqlClient.DataMaskingPolicies.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new DataMaskingPolicy() { DataMaskingState = DataMaskingState.Disabled }); // Verify policy is disabled policy = sqlClient.DataMaskingPolicies.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal(DataMaskingState.Disabled, policy.DataMaskingState); // Verify no rules are returned rules = sqlClient.DataMaskingRules.ListByDatabase(resourceGroup.Name, server.Name, dbName); Assert.Equal(0, rules.Count()); }; }
public KeyVaultTestFixture() { // Initialize has bug which causes null reference exception HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); _mode = HttpMockServer.GetCurrentMode(); }
public void CanCreateTemplateImagesSuccessfully() { using (UndoContext context = UndoContext.Current) { context.Start(); string imageName = "my_unit_test_created_templateimage"; string returnedImageName = null; HttpRecorderMode mode = HttpMockServer.GetCurrentMode(); RemoteAppManagementClient client = GetRemoteAppManagementClient(); TemplateImageResult setResponse; AzureOperationResponse deleteResponse; TemplateImageListResult listResponse = null; IList <TemplateImage> imageList; TemplateImage myImage = null; bool foundTestImage = false; string newName = "renamed_my_test_image"; TemplateImageDetails renameDetails = null; TemplateImageDetails newImageDetails = new TemplateImageDetails() { Name = imageName, Region = "West US" }; Assert.DoesNotThrow(() => { setResponse = client.TemplateImages.Set(newImageDetails); }); // now check the list Assert.DoesNotThrow(() => { listResponse = client.TemplateImages.List(); imageList = listResponse.RemoteAppTemplateImageList; foreach (TemplateImage image in imageList) { if ((image.Name == imageName)) { foreach (string region in image.RegionList) { if (region == newImageDetails.Region) { foundTestImage = true; // cleanup returnedImageName = image.Name; myImage = image; break; } } } } }); Assert.True(foundTestImage); Assert.False(string.IsNullOrEmpty(returnedImageName)); Assert.NotNull(myImage); // rename the image renameDetails = new TemplateImageDetails() { Id = myImage.Id, Name = newName, Region = "West US" }; setResponse = null; Assert.DoesNotThrow(() => { setResponse = client.TemplateImages.Set(renameDetails); }); Assert.NotNull(setResponse); Assert.NotNull(setResponse.TemplateImage); Assert.Equal(System.Net.HttpStatusCode.OK, setResponse.StatusCode); // verify that we have an image with the new name TemplateImageResult imageResponse = null; Assert.DoesNotThrow(() => { imageResponse = client.TemplateImages.Get(newName); }); Assert.NotNull(imageResponse); Assert.NotNull(imageResponse.TemplateImage); Assert.Equal(newName, imageResponse.TemplateImage.Name); Assert.True(imageResponse.TemplateImage.RegionList.Contains("West US"), "Unexpected region of the renamed image: " + String.Join(", ", imageResponse.TemplateImage.RegionList)); Assert.DoesNotThrow(() => { deleteResponse = client.TemplateImages.Delete(newName); }); } }
public static void Initialize(Type callerIdentity, string testIdentity, HttpRecorderMode mode) { Initialize(callerIdentity.Name, testIdentity, mode); }
public static void Initialize(string callerIdentity, string testIdentity, HttpRecorderMode mode) { CallerIdentity = callerIdentity; TestIdentity = testIdentity; Mode = mode; names = new AssetNames(); servers = new List <HttpMockServer>(); records = new Records(Matcher); Variables = new Dictionary <string, string>(); string location = string.Empty; #if FullNetFx var asmCollection = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly asm in asmCollection) { if (asm.GetType(CallerIdentity) != null) { location = asm.Location; break; } } #elif !FullNetFx //netcoreapp11 || netcoreapp20 location = AppContext.BaseDirectory; #endif RecordsDirectory = Path.Combine(location, RecordsDirectory); if (Mode == HttpRecorderMode.Playback) { string recordDir = Path.Combine(RecordsDirectory, CallerIdentity); var fileName = Path.GetFullPath(Path.Combine(recordDir, testIdentity.Replace(".json", "") + ".json")); if (!HttpMockServer.FileSystemUtilsObject.DirectoryExists(recordDir) || !HttpMockServer.FileSystemUtilsObject.FileExists(fileName)) { throw new ArgumentException( string.Format("Unable to find recorded mock file '{0}'.", fileName), "callerIdentity"); } else { RecordEntryPack pack = RecordEntryPack.Deserialize(fileName); lock (records) { foreach (var entry in pack.Entries) { records.Enqueue(entry); } } foreach (var func in pack.Names.Keys) { pack.Names[func].ForEach(n => names.Enqueue(func, n)); } Variables = pack.Variables; if (Variables == null) { Variables = new Dictionary <string, string>(); } } } initialized = true; }
public KeyVaultTestFixture() { // Initialize has bug which causes null reference exception HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); mode = HttpMockServer.GetCurrentMode(); }