Skip to content
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 @@ -8,6 +8,8 @@
using Microsoft.Rest.Azure;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Xunit;

namespace DataFactory.Tests.ScenarioTests
Expand All @@ -16,28 +18,35 @@ public class DataFactoryScenarioTests : ScenarioTestBase<DataFactoryScenarioTest
{
[Fact]
[Trait(TraitName.TestType, TestType.Scenario)]
public void DataFactoryCrud()
public async Task DataFactoryCrud()
{
var expectedFactory = new Factory(location: FactoryLocation);

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

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

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

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

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

this.RunTest(action, finallyAction);
await this.RunTest(action, finallyAction);
}

private void ValidateFactory(Factory actualFactory)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using DataFactory.Tests.Utils;
using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Management.DataFactory.Models;
using Microsoft.Rest.Azure;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Xunit;

namespace DataFactory.Tests.ScenarioTests
{
public class LinkedServiceScenarioTests : ScenarioTestBase<LinkedServiceScenarioTests>
{
[Fact]
[Trait(TraitName.TestType, TestType.Scenario)]
public async Task LinkedServiceCrud()
{
string linkedServiceName = "TestDataLakeStore";
var expectedLinkedService = new LinkedServiceResource()
{
Properties = new AzureDataLakeStoreLinkedService()
{
DataLakeStoreUri = "adl://test.azuredatalakestore.net/"
}
};

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

AzureOperationResponse<LinkedServiceResource> createResponse = await client.LinkedServices.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, 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);
this.ValidateLinkedService(expectedLinkedService, getResponse.Body, linkedServiceName);
Assert.Equal(HttpStatusCode.OK, getResponse.Response.StatusCode);

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

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

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

await this.RunTest(action, finallyAction);
}

private void ValidateLinkedService(LinkedServiceResource expected, LinkedServiceResource actual, string expectedName)
{
this.ValidateSubResource(actual, expectedName, "linkedservices");
Assert.IsType<AzureDataLakeStoreLinkedService>(actual.Properties);
Assert.Equal(((AzureDataLakeStoreLinkedService)expected.Properties).DataLakeStoreUri, ((AzureDataLakeStoreLinkedService)actual.Properties).DataLakeStoreUri);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Azure.Management.DataFactory.Models;
using System;
using System.Net;
using System.Threading.Tasks;
using Xunit;

namespace DataFactory.Tests.ScenarioTests
Expand All @@ -15,11 +16,11 @@ public class PipelineRunScenarioTests : ScenarioTestBase<PipelineRunScenarioTest
{
[Fact]
[Trait(TraitName.TestType, TestType.Scenario)]
public void CancelPipelineRun()
public async Task CancelPipelineRun()
{
var expectedFactory = new Factory(location: FactoryLocation);

Action<DataFactoryManagementClient> action = async (client) =>
Func<DataFactoryManagementClient, Task> action = async (client) =>
{
Factory createResponse = client.Factories.CreateOrUpdate(ResourceGroupName, DataFactoryName, expectedFactory);
ErrorResponseException exception = await Assert.ThrowsAsync<ErrorResponseException>(async () =>
Expand All @@ -30,11 +31,11 @@ public void CancelPipelineRun()
Assert.Equal(exception.Response.StatusCode, HttpStatusCode.BadRequest);
};

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

using Microsoft.Azure.Management.DataFactory;
using Microsoft.Azure.Management.DataFactory.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Xunit;

namespace DataFactory.Tests.ScenarioTests
{
Expand All @@ -16,23 +19,33 @@ public abstract class ScenarioTestBase<T>
protected const string FactoryLocation = "East US 2";
protected static string ClassName = typeof(T).FullName;

protected void RunTest(Action<DataFactoryManagementClient> initialAction, Action<DataFactoryManagementClient> finallyAction = null, [CallerMemberName] string methodName = "")
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))
{
DataFactoryManagementClient client = mockContext.GetServiceClient<DataFactoryManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
this.Client = mockContext.GetServiceClient<DataFactoryManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
try
{
initialAction.Invoke(client);
await initialAction(this.Client);
}
finally
{
if (finallyAction != null)
{
finallyAction.Invoke(client);
await finallyAction(this.Client);
}
}
}
}

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