本文整理汇总了C#中ResourceGroups.Tests.RecordedDelegatingHandler类的典型用法代码示例。如果您正苦于以下问题:C# RecordedDelegatingHandler类的具体用法?C# RecordedDelegatingHandler怎么用?C# RecordedDelegatingHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RecordedDelegatingHandler类属于ResourceGroups.Tests命名空间,在下文中一共展示了RecordedDelegatingHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPreviewedFeatures
public void GetPreviewedFeatures()
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(@"{
'name': 'Providers.Test/DONOTDELETEBETA',
'properties': {
'state': 'NotRegistered'
},
'id': '/subscriptions/fda3b6ba-8803-441c-91fb-6cc798cf6ea0/providers/Microsoft.Features/providers/Providers.Test/features/DONOTDELETEBETA',
'type': 'Microsoft.Features/providers/features'
}
")
};
var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.OK };
var client = GetFeatureClient(handler);
string resourceProviderNamespace = "Providers.Test";
string featureName = "DONOTDELETEBETA";
// ----Verify API calls for get all features under current subid----
var getResult = client.Features.Get( resourceProviderNamespace,featureName);
// Validate headers
Assert.Equal(HttpMethod.Get, handler.Method);
Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));
//Valid payload
//Construct expected URL
string expectedUrl = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/providers/Microsoft.Features/providers/"+Uri.EscapeDataString(resourceProviderNamespace) + "/features/" + Uri.EscapeDataString(featureName) + "?";
expectedUrl = expectedUrl + "api-version=2015-12-01";
string baseUrl = client.BaseUri.AbsoluteUri;
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl[baseUrl.Length - 1] == '/')
{
baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
}
if (expectedUrl[0] == '/')
{
expectedUrl = expectedUrl.Substring(1);
}
expectedUrl = baseUrl + "/" + expectedUrl;
expectedUrl = expectedUrl.Replace(" ", "%20");
Assert.Equal(expectedUrl, handler.Uri.ToString());
// Valid response
Assert.Equal(getResult.StatusCode, HttpStatusCode.OK);
//-------------
}
示例2: CreateListAndDeleteSubscriptionTagValue
public void CreateListAndDeleteSubscriptionTagValue()
{
var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.OK };
using (UndoContext context = UndoContext.Current)
{
context.Start();
string tagName = TestUtilities.GenerateName("csmtg");
string tagValue = TestUtilities.GenerateName("csmtgv");
var client = GetResourceManagementClient(handler);
var createNameResult = client.Tags.CreateOrUpdate(tagName);
var createValueResult = client.Tags.CreateOrUpdateValue(tagName, tagValue);
Assert.Equal(tagName, createNameResult.Tag.Name);
Assert.Equal(tagValue, createValueResult.Value.Value);
var listResult = client.Tags.List();
Assert.True(listResult.Tags.Count > 0);
client.Tags.DeleteValue(tagName, tagValue);
client.Tags.Delete(tagName);
}
}
示例3: ProviderGetValidateMessage
public void ProviderGetValidateMessage()
{
TestUtilities.StartTest();
var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.OK };
var client = GetResourceManagementClient(handler);
var reg = client.Providers.Register(ProviderName);
Assert.NotNull(reg);
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, reg.StatusCode);
var result = client.Providers.Get(ProviderName);
// Validate headers
Assert.Equal(HttpMethod.Get, handler.Method);
Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));
// Validate result
Assert.NotNull(result);
Assert.NotEmpty(result.Provider.Id);
Assert.Equal(ProviderName, result.Provider.Namespace);
Assert.True(ProviderRegistrationState.Registered == result.Provider.RegistrationState ||
ProviderRegistrationState.Registering == result.Provider.RegistrationState,
string.Format("Provider registration state was not 'Registered' or 'Registering', instead it was '{0}'", result.Provider.RegistrationState));
Assert.NotEmpty(result.Provider.ResourceTypes);
Assert.NotEmpty(result.Provider.ResourceTypes[0].Locations);
TestUtilities.EndTest();
}
示例4: DeleteResourceGroupRemovesGroupResources
public void DeleteResourceGroupRemovesGroupResources()
{
TestUtilities.StartTest();
var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.Created };
var client = GetResourceManagementClient(handler);
string location = "westus";
var resourceGroupName = TestUtilities.GenerateName("csmrg");
var resourceName = TestUtilities.GenerateName("csmr");
var createResult = client.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location });
var createResourceResult = client.Resources.CreateOrUpdate(resourceGroupName, new ResourceIdentity
{
ResourceName = resourceName,
ResourceProviderNamespace = "Microsoft.Web",
ResourceType = "sites",
ResourceProviderApiVersion = "2014-04-01"
},
new GenericResource
{
Location = location,
Properties = "{'name':'" + resourceName + "','siteMode': 'Standard','computeMode':'Shared'}"
});
var deleteResult = client.ResourceGroups.Delete(resourceGroupName);
var listGroupsResult = client.ResourceGroups.List(null);
Assert.Throws<CloudException>(() => client.Resources.List(new ResourceListParameters
{
ResourceGroupName = resourceGroupName
}));
Assert.Equal(HttpStatusCode.OK, deleteResult.StatusCode);
Assert.False(listGroupsResult.ResourceGroups.Any(rg => rg.Name == resourceGroupName));
TestUtilities.EndTest();
}
示例5: ProviderListValidateMessage
public void ProviderListValidateMessage()
{
TestUtilities.StartTest();
var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };
var client = GetResourceManagementClient(handler);
var reg = client.Providers.Register(ProviderName);
Assert.NotNull(reg);
Assert.Equal<HttpStatusCode>(HttpStatusCode.OK, reg.StatusCode);
var result = client.Providers.List(null);
// Validate headers
Assert.Equal(HttpMethod.Get, handler.Method);
Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));
// Validate result
Assert.True(result.Providers.Any());
var websiteProvider =
result.Providers.First(
p => p.Namespace.Equals(ProviderName, StringComparison.InvariantCultureIgnoreCase));
Assert.Equal(ProviderName, websiteProvider.Namespace);
Assert.True(ProviderRegistrationState.Registered == websiteProvider.RegistrationState ||
ProviderRegistrationState.Registering == websiteProvider.RegistrationState,
string.Format("Provider registration state was not 'Registered' or 'Registering', instead it was '{0}'", websiteProvider.RegistrationState));
Assert.NotEmpty(websiteProvider.ResourceTypes);
Assert.NotEmpty(websiteProvider.ResourceTypes[0].Locations);
TestUtilities.EndTest();
}
示例6: StorageAccountDeleteTest
public void StorageAccountDeleteTest()
{
var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };
using (var context = UndoContext.Current)
{
context.Start();
var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(handler);
var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler);
// Create resource group
var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);
// Delete an account which does not exist
var deleteRequest = storageMgmtClient.StorageAccounts.Delete(rgname, "missingaccount");
// Create storage account
string accountName = StorageManagementTestUtilities.CreateStorageAccount(storageMgmtClient, rgname);
// Delete an account
deleteRequest = storageMgmtClient.StorageAccounts.Delete(rgname, accountName);
// Delete an account which was just deleted
deleteRequest = storageMgmtClient.StorageAccounts.Delete(rgname, accountName);
}
}
示例7: ProviderGetThrowsExceptions
public void ProviderGetThrowsExceptions()
{
var handler = new RecordedDelegatingHandler();
var client = GetResourceManagementClient(handler);
Assert.Throws<ArgumentNullException>(() => client.Providers.Get(null));
}
示例8: GetFeatureClient
public FeatureClient GetFeatureClient(RecordedDelegatingHandler handler)
{
var token = new TokenCloudCredentials(Guid.NewGuid().ToString(), "abc123");
handler.IsPassThrough = false;
var client = new FeatureClient(token).WithHandler(handler);
HttpMockServer.Mode = HttpRecorderMode.Playback;
return client;
}
示例9: GetStorageManagementClient
public static StorageManagementClient GetStorageManagementClient(RecordedDelegatingHandler handler)
{
if (IsTestTenant)
{
return new StorageManagementClient(GetCreds(), testUri);
}
else
{
handler.IsPassThrough = true;
return TestBase.GetServiceClient<StorageManagementClient>(new CSMTestEnvironmentFactory()).WithHandler(handler);
}
}
示例10: GetResourceManagementClient
public ResourceManagementClient GetResourceManagementClient(RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = this.GetResourceManagementClient();
client = client.WithHandler(handler);
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
{
client.LongRunningOperationInitialTimeout = 0;
client.LongRunningOperationRetryTimeout = 0;
}
return client;
}
示例11: GetResourceManagementClient
public static ResourceManagementClient GetResourceManagementClient(RecordedDelegatingHandler handler)
{
if (IsTestTenant)
{
ResourceManagementClient resourcesClient = new ResourceManagementClient(GetCreds());
return resourcesClient;
}
else
{
handler.IsPassThrough = true;
return TestBase.GetServiceClient<ResourceManagementClient>(new CSMTestEnvironmentFactory()).WithHandler(handler);
}
}
示例12: CreateDummyDeploymentTemplateWorks
public void CreateDummyDeploymentTemplateWorks()
{
var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.Created };
var dictionary = new Dictionary<string, object> {
{"string", new Dictionary<string, object>() {
{"value", "myvalue"},
}},
{"securestring", new Dictionary<string, object>() {
{"value", "myvalue"},
}},
{"int", new Dictionary<string, object>() {
{"value", 42},
}},
{"bool", new Dictionary<string, object>() {
{"value", true},
}}
};
var serializedDictionary = JsonConvert.SerializeObject(dictionary, new JsonSerializerSettings
{
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
TypeNameHandling = TypeNameHandling.None
});
using (UndoContext context = UndoContext.Current)
{
context.Start();
var client = GetResourceManagementClient(handler);
var parameters = new Deployment
{
Properties = new DeploymentProperties()
{
TemplateLink = new TemplateLink
{
Uri = new Uri(DummyTemplateUri)
},
Parameters = serializedDictionary,
Mode = DeploymentMode.Incremental,
}
};
string groupName = TestUtilities.GenerateName("csmrg");
string deploymentName = TestUtilities.GenerateName("csmd");
client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup { Location = "West Europe" });
client.Deployments.CreateOrUpdate(groupName, deploymentName, parameters);
JObject json = JObject.Parse(handler.Request);
Assert.Equal(HttpStatusCode.OK, client.Deployments.Get(groupName, deploymentName).StatusCode);
}
}
示例13: UsageTest
public void UsageTest()
{
var handler = new RecordedDelegatingHandler {StatusCodeToReturn = HttpStatusCode.OK};
using (var context = UndoContext.Current)
{
context.Start();
var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler);
var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler);
var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups");
string resourceGroupName = TestUtilities.GenerateName("csmrg");
resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
new ResourceGroup
{
Location = location
});
string networkSecurityGroupName = TestUtilities.GenerateName();
var networkSecurityGroup = new NetworkSecurityGroup()
{
Location = location,
};
// Put Nsg
var putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup);
Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode);
Assert.Equal("Succeeded", putNsgResponse.Status);
var getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName);
Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode);
// Query for usages
var usagesResponse = networkResourceProviderClient.Usages.List(getNsgResponse.NetworkSecurityGroup.Location.Replace(" ", string.Empty));
Assert.True(usagesResponse.StatusCode == HttpStatusCode.OK);
// Verify that the strings are populated
Assert.NotNull(usagesResponse.Usages);
Assert.True(usagesResponse.Usages.Any());
foreach (var usage in usagesResponse.Usages)
{
Assert.True(usage.Limit > 0);
Assert.NotNull(usage.Name);
Assert.True(!string.IsNullOrEmpty(usage.Name.LocalizedValue));
Assert.True(!string.IsNullOrEmpty(usage.Name.Value));
}
}
}
示例14: ListSubscriptionWorksWithNextLink
public void ListSubscriptionWorksWithNextLink()
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(@"{
'value': [
{
'id':'/subscriptions/38b598fc-e57a-423f-b2e7-dc0ddb631f1f',
'subscriptionId': '38b598fc-e57a-423f-b2e7-dc0ddb631f1f',
'displayName':'test-release-3',
'state': 'Enabled',
'subscriptionPolicies':
{
'locationPlacementId':'Public_2014-09-01',
'quotaId':'MSDN'
}
}
],
'nextLink': 'https://wa.com/subscriptions/mysubid/resourcegroups/TestRG/deployments/test-release-3/operations?$skiptoken=983fknw'
}
")
};
var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };
var client = GetSubscriptionClient(handler);
var result = client.Subscriptions.List();
response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(@"{
'value': []
}")
};
handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };
client = GetSubscriptionClient(handler);
result = client.Subscriptions.ListNext(result.NextLink);
// Validate body
Assert.Equal(HttpMethod.Get, handler.Method);
Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));
Assert.Equal("https://wa.com/subscriptions/mysubid/resourcegroups/TestRG/deployments/test-release-3/operations?$skiptoken=983fknw", handler.Uri.ToString());
// Validate response
Assert.Equal(null, result.NextLink);
}
示例15: ResourceGroupCreateOrUpdateValidateMessage
public void ResourceGroupCreateOrUpdateValidateMessage()
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(@"{
'id': '/subscriptions/abc123/resourcegroups/csmrgr5mfggio',
'name': 'foo',
'location': 'WestEurope',
'tags' : {
'department':'finance',
'tagname':'tagvalue'
},
'properties': {
'provisioningState': 'Succeeded'
}
}")
};
var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };
var client = GetResourceManagementClient(handler);
var result = client.ResourceGroups.CreateOrUpdate("foo", new ResourceGroup
{
Location = "WestEurope",
Tags = new Dictionary<string, string>() { { "department", "finance" }, { "tagname", "tagvalue" } },
});
JObject json = JObject.Parse(handler.Request);
// Validate headers
Assert.Equal("application/json; charset=utf-8", handler.ContentHeaders.GetValues("Content-Type").First());
Assert.Equal(HttpMethod.Put, handler.Method);
Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));
// Validate payload
Assert.Equal("WestEurope", json["location"].Value<string>());
Assert.Equal("finance", json["tags"]["department"].Value<string>());
Assert.Equal("tagvalue", json["tags"]["tagname"].Value<string>());
// Validate response
Assert.Equal("/subscriptions/abc123/resourcegroups/csmrgr5mfggio", result.ResourceGroup.Id);
Assert.Equal("Succeeded", result.ResourceGroup.ProvisioningState);
Assert.Equal("foo", result.ResourceGroup.Name);
Assert.Equal("finance", result.ResourceGroup.Tags["department"]);
Assert.Equal("tagvalue", result.ResourceGroup.Tags["tagname"]);
Assert.Equal("WestEurope", result.ResourceGroup.Location);
}