Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ADF tests to latest resource manager client #3828

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -29,5 +29,6 @@
<ItemGroup>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Update="Microsoft.Rest.ClientRuntime.Azure.TestFramework" Version="1.7.2" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Management.DataFactory.Models;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Linq;
using System.Net;
Expand All @@ -24,34 +25,34 @@ public async Task DataFactoryCrud()

Func<DataFactoryManagementClient, Task> action = async (client) =>
{
AzureOperationResponse<Factory> createResponse = await client.Factories.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, DataFactoryName, expectedFactory);
this.ValidateFactory(createResponse.Body);
AzureOperationResponse<Factory> createResponse = await client.Factories.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName, expectedFactory);
this.ValidateFactory(createResponse.Body, this.DataFactoryName);
Assert.Equal(HttpStatusCode.OK, createResponse.Response.StatusCode);

AzureOperationResponse<Factory> getResponse = await client.Factories.GetWithHttpMessagesAsync(ResourceGroupName, DataFactoryName);
this.ValidateFactory(getResponse.Body);
AzureOperationResponse<Factory> getResponse = await client.Factories.GetWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName);
this.ValidateFactory(getResponse.Body, this.DataFactoryName);
Assert.Equal(HttpStatusCode.OK, getResponse.Response.StatusCode);

AzureOperationResponse<IPage<Factory>> listByResourceGroupResponse = await client.Factories.ListByResourceGroupWithHttpMessagesAsync(ResourceGroupName);
this.ValidateFactory(listByResourceGroupResponse.Body.First());
AzureOperationResponse<IPage<Factory>> listByResourceGroupResponse = await client.Factories.ListByResourceGroupWithHttpMessagesAsync(this.ResourceGroupName);
this.ValidateFactory(listByResourceGroupResponse.Body.First(), this.DataFactoryName);
Assert.Equal(HttpStatusCode.OK, listByResourceGroupResponse.Response.StatusCode);
};

Func<DataFactoryManagementClient, Task> finallyAction = async (client) =>
{
AzureOperationResponse deleteResponse = await client.Factories.DeleteWithHttpMessagesAsync(ResourceGroupName, DataFactoryName);
AzureOperationResponse deleteResponse = await client.Factories.DeleteWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName);
Assert.Equal(HttpStatusCode.OK, deleteResponse.Response.StatusCode);

deleteResponse = await client.Factories.DeleteWithHttpMessagesAsync(ResourceGroupName, DataFactoryName);
deleteResponse = await client.Factories.DeleteWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName);
Assert.Equal(HttpStatusCode.NoContent, deleteResponse.Response.StatusCode);
};

await this.RunTest(action, finallyAction);
}

private void ValidateFactory(Factory actualFactory)
private void ValidateFactory(Factory actualFactory, string expectedFactoryName)
{
Assert.Equal(DataFactoryName, actualFactory.Name);
Assert.Equal(expectedFactoryName, actualFactory.Name);
Assert.Equal(FactoryLocation, actualFactory.Location);
Assert.Equal("Succeeded", actualFactory.ProvisioningState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ public async Task LinkedServiceCrud()

Func<DataFactoryManagementClient, Task> action = async (client) =>
{
client.Factories.CreateOrUpdate(ResourceGroupName, DataFactoryName, new Factory(location: FactoryLocation));
client.Factories.CreateOrUpdate(this.ResourceGroupName, this.DataFactoryName, new Factory(location: FactoryLocation));

AzureOperationResponse<LinkedServiceResource> createResponse = await client.LinkedServices.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, DataFactoryName, linkedServiceName, expectedLinkedService);
AzureOperationResponse<LinkedServiceResource> createResponse = await client.LinkedServices.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName, linkedServiceName, expectedLinkedService);
this.ValidateLinkedService(expectedLinkedService, createResponse.Body, linkedServiceName);
Assert.Equal(HttpStatusCode.OK, createResponse.Response.StatusCode);

AzureOperationResponse<LinkedServiceResource> getResponse = await client.LinkedServices.GetWithHttpMessagesAsync(ResourceGroupName, DataFactoryName, linkedServiceName);
AzureOperationResponse<LinkedServiceResource> getResponse = await client.LinkedServices.GetWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName, linkedServiceName);
this.ValidateLinkedService(expectedLinkedService, getResponse.Body, linkedServiceName);
Assert.Equal(HttpStatusCode.OK, getResponse.Response.StatusCode);

AzureOperationResponse<IPage<LinkedServiceResource>> listResponse = await client.LinkedServices.ListByFactoryWithHttpMessagesAsync(ResourceGroupName, DataFactoryName);
AzureOperationResponse<IPage<LinkedServiceResource>> listResponse = await client.LinkedServices.ListByFactoryWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName);
this.ValidateLinkedService(expectedLinkedService, listResponse.Body.First(), linkedServiceName);
Assert.Equal(HttpStatusCode.OK, listResponse.Response.StatusCode);

AzureOperationResponse deleteResponse = await client.LinkedServices.DeleteWithHttpMessagesAsync(ResourceGroupName, DataFactoryName, linkedServiceName);
AzureOperationResponse deleteResponse = await client.LinkedServices.DeleteWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName, linkedServiceName);
Assert.Equal(HttpStatusCode.OK, deleteResponse.Response.StatusCode);
};

Func<DataFactoryManagementClient, Task> finallyAction = async (client) =>
{
await client.Factories.DeleteAsync(ResourceGroupName, DataFactoryName);
await client.Factories.DeleteAsync(this.ResourceGroupName, this.DataFactoryName);
};

await this.RunTest(action, finallyAction);
}

private void ValidateLinkedService(LinkedServiceResource expected, LinkedServiceResource actual, string expectedName)
{
this.ValidateSubResource(actual, expectedName, "linkedservices");
this.ValidateSubResource(actual, this.DataFactoryName, expectedName, "linkedservices");
Assert.IsType<AzureDataLakeStoreLinkedService>(actual.Properties);
Assert.Equal(((AzureDataLakeStoreLinkedService)expected.Properties).DataLakeStoreUri, ((AzureDataLakeStoreLinkedService)actual.Properties).DataLakeStoreUri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using DataFactory.Tests.Utils;
using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Management.DataFactory.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Net;
using System.Threading.Tasks;
Expand All @@ -18,22 +19,20 @@ public class PipelineRunScenarioTests : ScenarioTestBase<PipelineRunScenarioTest
[Trait(TraitName.TestType, TestType.Scenario)]
public async Task CancelPipelineRun()
{
var expectedFactory = new Factory(location: FactoryLocation);

Func<DataFactoryManagementClient, Task> action = async (client) =>
{
Factory createResponse = client.Factories.CreateOrUpdate(ResourceGroupName, DataFactoryName, expectedFactory);
Factory createResponse = client.Factories.CreateOrUpdate(this.ResourceGroupName, this.DataFactoryName, new Factory(location: FactoryLocation));
ErrorResponseException exception = await Assert.ThrowsAsync<ErrorResponseException>(async () =>
{
await client.Factories.CancelPipelineRunWithHttpMessagesAsync(ResourceGroupName, DataFactoryName, "efbe5443-9879-4495-94a6-4d7c394133ad");
await client.Factories.CancelPipelineRunWithHttpMessagesAsync(this.ResourceGroupName, this.DataFactoryName, "efbe5443-9879-4495-94a6-4d7c394133ad");
});

Assert.Equal(exception.Response.StatusCode, HttpStatusCode.BadRequest);
};

Func<DataFactoryManagementClient, Task> finallyAction = async (client) =>
{
await client.Factories.DeleteAsync(ResourceGroupName, DataFactoryName);
await client.Factories.DeleteAsync(this.ResourceGroupName, this.DataFactoryName);
};
await this.RunTest(action, finallyAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// license information.

using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Management.DataFactory.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Runtime.CompilerServices;
Expand All @@ -14,20 +15,28 @@ namespace DataFactory.Tests.ScenarioTests
{
public abstract class ScenarioTestBase<T>
{
protected const string ResourceGroupName = "sdktesting";
protected const string DataFactoryName = "sdktestingfactory";
private const string ResourceGroupNamePrefix = "sdktestingadfrg";
protected const string DataFactoryNamePrefix = "sdktestingfactory";
protected const string FactoryLocation = "East US 2";
protected static string ClassName = typeof(T).FullName;

protected string ResourceGroupName { get; private set; }
protected string DataFactoryName { get; private set; }

protected DataFactoryManagementClient Client { get; private set; }

protected async Task RunTest(Func<DataFactoryManagementClient, Task> initialAction, Func<DataFactoryManagementClient, Task> finallyAction, [CallerMemberName] string methodName = "")
{
using (MockContext mockContext = MockContext.Start(ClassName, methodName))
{
this.ResourceGroupName = TestUtilities.GenerateName(ResourceGroupNamePrefix);
this.DataFactoryName = TestUtilities.GenerateName(DataFactoryNamePrefix);
this.Client = mockContext.GetServiceClient<DataFactoryManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
ResourceManagementClient resourceManagementClient = mockContext.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment());

try
{
resourceManagementClient.ResourceGroups.CreateOrUpdate(this.ResourceGroupName, new ResourceGroup() { Location = FactoryLocation });
await initialAction(this.Client);
}
finally
Expand All @@ -36,13 +45,15 @@ protected async Task RunTest(Func<DataFactoryManagementClient, Task> initialActi
{
await finallyAction(this.Client);
}

resourceManagementClient.ResourceGroups.Delete(this.ResourceGroupName);
}
}
}

protected void ValidateSubResource(SubResource actual, string expectedName, string expectedSubResourceType)
protected void ValidateSubResource(Microsoft.Azure.Management.DataFactory.Models.SubResource actual, string expectedDataFactoryName, string expectedName, string expectedSubResourceType)
{
string expectedResourceID = $"/subscriptions/{this.Client.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.DataFactory/factories/{DataFactoryName}/{expectedSubResourceType}/{expectedName}";
string expectedResourceID = $"/subscriptions/{this.Client.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.DataFactory/factories/{expectedDataFactoryName}/{expectedSubResourceType}/{expectedName}";
Assert.Equal(expectedResourceID, actual.Id);
Assert.Equal(expectedName, actual.Name);
Assert.NotNull(actual.Etag);
Expand Down
Loading