Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@echo off
set autoRestVersion=1.0.1-20170419-2300-nightly
if "%1" == "" (
set specFile="https://raw.githubusercontent.com/Azure/azure-rest-api-specs/933056da11d6c332da7ce05cd701848356d81010/arm-recoveryservicessiteRecovery/2016-12-01/readme.md"
set specFile="https://github.com/Azure/azure-rest-api-specs/blob/master/arm-recoveryservicessiterecovery/2016-08-10/swagger/service.json"
) else (
set specFile="%1"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ namespace SiteRecovery.Tests
{
public class SiteRecoveryTestsBase : TestBase
{
public static string MyVaultName;
public static string MyResourceGroupName;
public static string VaultKey;
public static string ResourceNamespace;
public static string ResourceType;
public static string VaultKey = "CIK";

protected readonly RecordedDelegatingHandler CustomHttpHandler
= new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };
Expand All @@ -33,7 +29,7 @@ public string GenerateAgentAuthenticationHeader(string clientRequestId)
cikTokenDetails.NotBeforeTimestamp = TimeZoneInfo.ConvertTime(currentDateTime, TimeZoneInfo.Utc);
cikTokenDetails.NotAfterTimestamp = cikTokenDetails.NotBeforeTimestamp.AddHours(6);
cikTokenDetails.ClientRequestId = clientRequestId;
cikTokenDetails.Version = new System.Version(1, 2);
cikTokenDetails.Version = new Version(1, 2);
cikTokenDetails.PropertyBag = new Dictionary<string, object>();

string shaInput = JsonConvert.SerializeObject(cikTokenDetails);
Expand All @@ -46,6 +42,26 @@ public string GenerateAgentAuthenticationHeader(string clientRequestId)
return JsonConvert.SerializeObject(cikTokenDetails);
}

public Dictionary<string, List<string>> GetRequestHeaders(bool shouldSignRequest = true)
{
Dictionary<string, List<string>> customHeaders = new Dictionary<string, List<string>>();

string clientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-P";

customHeaders.Add("x-ms-client-request-id", new List<string> { clientRequestId });

if (shouldSignRequest)
{
customHeaders.Add("Agent-Authentication", new List<string> { this.GenerateAgentAuthenticationHeader(clientRequestId) });
}
else
{
customHeaders.Add("Agent-Authentication", new List<string> { "" });
}

return customHeaders;
}

#region CIK

public class CikTokenDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Tests
{
public class TestHelper: IDisposable
{
private const string resourceNamespace = "Microsoft.RecoveryServices";
private const string resourceGroupName = "resourceGroupPS1";
private const string vaultName = "vault1";
private const string location = "southeastasia";
private const string fabricName = "Azure";
private const string resourceGroupName = "siterecoveryprod1";
private const string vaultName = "SDKVault";
private const string location = "westus";

public RecoveryServicesClient VaultClient { get; private set; }

Expand Down Expand Up @@ -87,61 +88,6 @@ public void DisposeVaults()
}
}

public void WaitForJobCompletion(string jobId)
{
string jobStatus = string.Empty;

RetryActionWithTimeout(
() => jobStatus = GetJobStatus(jobId),
() => !IsJobInProgress(jobStatus),
TimeSpan.FromHours(3),
statusCode =>
{
TestUtilities.Wait(5000);
return true;
});
}

public string GetJobStatus(string jobId)
{
return "Completed";
}

public bool IsJobInProgress(string jobStatus)
{
return jobStatus.CompareTo("InProgress") == 0 || jobStatus.CompareTo("Cancelling") == 0;
}

public void RetryActionWithTimeout(Action action, Func<bool> validator, TimeSpan timeout, Func<System.Net.HttpStatusCode, bool> shouldRetry)
{
DateTime timedOut = DateTime.Now + timeout;
do
{
try
{
action();
}
catch (CloudException exception)
{
if (!shouldRetry(exception.Response.StatusCode))
{
throw;
}
}
}

while (DateTime.Now < timedOut && !validator());
}

private void ValidateOperationResponse(AzureOperationResponse response)
{
Assert.NotNull(response);
Assert.Equal(System.Net.HttpStatusCode.Accepted, response.Response.StatusCode);
Assert.True(response.Response.Headers.Contains("Location"));
Assert.True(response.Response.Headers.Contains("Azure-AsyncOperation"));
Assert.True(response.Response.Headers.Contains("Retry-After"));
}

public void Dispose()
{
SiteRecoveryClient.Dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avneeshrai please reference 1.5.0-preview of Resource manager in your test project.
With the new resource manager, you will be using the new nuget (might need to add new namespace) and then record your tests.
Don't worry if you see the older version of resource mangaer in your project, that is going to be there as it's a common dependency (we want to remove this dependency soon)
Record all your tests and that should solve the testing issue, I had mentioned earlier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shahabhijeet as discussed offline...we dont have dependency on Resource manager in our projects. Have removed all the stale references that we had.

<Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" />
<PropertyGroup>
<PackageId>RecoveryServices.SiteRecovery.Tests</PackageId>
Expand Down
Loading