Skip to content

Commit

Permalink
Fixing the project structure with the new Test project
Browse files Browse the repository at this point in the history
  • Loading branch information
vrdmr committed Nov 14, 2017
1 parent 7ccbb20 commit 45a1b45
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 399 deletions.
7 changes: 3 additions & 4 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- To enable LocalFeed for testing uncomment the following line -->
<add key="NugetOfficialV3" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="tools/LocalNugetFeed" />
</packageSources>
<add key="NugetOfficialV3" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="C:\aa\azure-sdk-for-net\tools\LocalNugetFeed" />
</packageSources>
</configuration>
94 changes: 18 additions & 76 deletions src/SDKs/Automation/Automation.Tests/Automation.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,96 +1,38 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" />
<PropertyGroup>
<Description>Test Project for Automation tests</Description>
<VersionPrefix>2.0.0-preview</VersionPrefix>
<AssemblyName>Automation.Tests</AssemblyName>
<PackageId>Automation.Tests</PackageId>
<!--<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>-->
<PackageTags>Microsoft AutoRest ClientRuntime REST</PackageTags>
<AssemblyName>Automation.Tests</AssemblyName>
<VersionPrefix>2.0.0-preview</VersionPrefix>
<Description>Test Project for Automation tests</Description>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
<TestProjectType>true</TestProjectType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Microsoft.Azure.Management.Automation" Version="2.0.3" />

<PackageReference Include="Hyak.Common" Version="1.1.3" />
<PackageReference Include="Microsoft.Azure.Common " Version="2.1.3" />
<PackageReference Include="Microsoft.Azure.ResourceManager" Version="1.1.0-preview" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Compile Remove="Customizations\**" />
<EmbeddedResource Remove="Customizations\**" />
<None Remove="Customizations\**" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="[14.0.0-preview,16.0)" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<ProjectReference Include="..\Management.Automation\Microsoft.Azure.Management.Automation.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteCredential.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteRunbook.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteSchedule.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteVariable.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteWebhook.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
<!--
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{62F8139E-0CA4-4234-B5E3-6D2689ED743C}</ProjectGuid>
<RootNamespace>Automation.Tests</RootNamespace>
<AssemblyName>Automation.Tests</AssemblyName>
</PropertyGroup>
<Import Project="..\..\..\..\tools\Library.Settings.targets" />
<Import Project="$(LibraryToolsFolder)\Test.Dependencies.target" />
<ItemGroup>
<Compile Include="Customizations\ResponseWithSkipToken.cs" />
<Compile Include="Helpers\RecordedDelegatingHandler.cs" />
<Compile Include="Helpers\ResourceGroupHelper.cs" />
<Compile Include="Helpers\RunbookDefinition.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Customizations\AutomationManagementClient.Customization.cs" />
<Compile Include="ScenarioTests\AutomationTests.cs" />
<Compile Include="TestSupport\AutomationTestBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteCredential.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteRunbook.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteSchedule.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteVariable.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Management.Automation.Testing.AutomationTest\CanCreateUpdateDeleteWebhook.json">
<None Update="SessionRecords\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<!--Do not remove until VS Test Tools fixes #472-->
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
</Project>
-->
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

using System;
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.WindowsAzure.Management.Automation;

namespace Microsoft.WindowsAzure.Management.Automation
namespace Automation.Tests.Customizations
{
public partial class AutomationManagementClient
public class AutomationManagementClient
{
public static List<T> ContinuationTokenHandler<T>(Func<string, ResponseWithSkipToken<T>> listFunc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Management.Automation;
using Microsoft.Azure.Management.Automation.Testing;
using Microsoft.Azure.Management.Resources;
//using Microsoft.Azure.Test;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Net.Http;
//using Microsoft.Azure.Test;

namespace Microsoft.Azure.Management.Automation.Testing
namespace Automation.Tests.Helpers
{
public static class ResourceGroupHelper
{

public static AutomationManagementClient GetAutomationClient(MockContext context, RecordedDelegatingHandler handler)
public static AutomationClient GetAutomationClient(MockContext context, RecordedDelegatingHandler handler)
{
//return TestBase.GetServiceClient<AutomationManagementClient>(new CSMTestEnvironmentFactory());
return context.GetServiceClient<AutomationManagementClient>(false, handler);
return context.GetServiceClient<AutomationClient>(false, handler);
}

public static ResourceManagementClient GetResourcesClient(MockContext context, RecordedDelegatingHandler handler)
Expand Down
112 changes: 57 additions & 55 deletions src/SDKs/Automation/Automation.Tests/ScenarioTests/AutomationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Hyak.Common;
using System.Linq;
using Automation.Tests.TestSupport;
using Microsoft.Azure.Management.Automation.Models;
using Microsoft.Rest.Azure;
//using Microsoft.Azure.Test;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Newtonsoft.Json;
Expand All @@ -21,40 +23,40 @@ public void CanCreateUpdateDeleteRunbook()
using (var context = MockContext.Start(this.GetType().FullName))
{
//undoContext.Start();
using (AutomationTestBase _testFixture = new AutomationTestBase(context))
using (var testFixture = new AutomationTestBase(context))
{
string runbookName = RunbookDefinition.TestFasterWorkflow.RunbookName;
string runbookContent = RunbookDefinition.TestFasterWorkflow.PsScript;
var runbookName = RunbookDefinition.TestFasterWorkflow.RunbookName;
var runbookContent = RunbookDefinition.TestFasterWorkflow.PsScript;

_testFixture.CreateRunbook(runbookName, runbookContent);
var runbook = _testFixture.GetRunbook(runbookName);
testFixture.CreateRunbook(runbookName, runbookContent);
var runbook = testFixture.GetRunbook(runbookName);
Assert.NotNull(runbook);

_testFixture.PublishRunbook(runbook.Name);
runbook = _testFixture.GetRunbook(runbookName);
Assert.Equal("Published", runbook.Properties.State);
testFixture.PublishRunbook(runbook.Name);
runbook = testFixture.GetRunbook(runbookName);
Assert.Equal("Published", runbook.State);

var description = "description of runbook";
runbook.Properties.LogProgress = true;
runbook.Properties.Description = description;
const string description = "description of runbook";
runbook.LogProgress = true;
runbook.Description = description;

_testFixture.UpdateRunbook(runbook);
var updatedRunbook = _testFixture.GetRunbook(runbookName);
Assert.Equal(runbook.Properties.LogProgress, true);
Assert.Equal(runbook.Properties.LogVerbose, false);
Assert.Equal(runbook.Properties.Description, updatedRunbook.Properties.Description);
testFixture.UpdateRunbook(runbook);
var updatedRunbook = testFixture.GetRunbook(runbookName);
Assert.Equal(runbook.LogProgress, true);
Assert.Equal(runbook.LogVerbose, false);
Assert.Equal(runbook.Description, updatedRunbook.Description);

string runbookContentV2 = RunbookDefinition.TestFasterWorkflow_V2.PsScript;
_testFixture.UpdateRunbookContent(runbookName, runbookContentV2);
var runbookContentV2 = RunbookDefinition.TestFasterWorkflow_V2.PsScript;
testFixture.UpdateRunbookContent(runbookName, runbookContentV2);

string updatedContent = _testFixture.GetRunbookContent(runbookName);
Assert.Equal(runbookContentV2, updatedContent);
var updatedContent = testFixture.GetRunbookContent(runbookName);
Assert.Equal(runbookContentV2, updatedContent.ToString());

_testFixture.DeleteRunbook(runbookName);
testFixture.DeleteRunbook(runbookName);

Assert.Throws<CloudException>(() =>
{
runbook = _testFixture.GetRunbook(runbookName);
runbook = testFixture.GetRunbook(runbookName);
});
}
}
Expand All @@ -69,26 +71,26 @@ public void CanCreateUpdateDeleteSchedule()
{
//undoContext.Start();

using (AutomationTestBase _testFixture = new AutomationTestBase(context))
using (var _testFixture = new AutomationTestBase(context))
{
var scheduleName = TestUtilities.GenerateName("hourlySche");
var startTime = DateTimeOffset.Now.AddMinutes(30);
var expiryTime = startTime.AddDays(5);

Schedule schedule = _testFixture.CreateHourlySchedule(scheduleName, startTime, expiryTime);
var schedule = _testFixture.CreateHourlySchedule(scheduleName, startTime, expiryTime);
Assert.NotNull(schedule);

schedule = _testFixture.GetSchedule(schedule.Name);
Assert.NotNull(schedule);
Assert.Equal((byte)1, schedule.Properties.Interval);
Assert.Equal(ScheduleFrequency.Hour.ToString(), schedule.Properties.Frequency);
Assert.Equal((byte)1, schedule.Interval);
Assert.Equal(ScheduleFrequency.Hour.ToString(), schedule.Frequency);

schedule.Properties.IsEnabled = false;
schedule.Properties.Description = "hourly schedule";
schedule.IsEnabled = false;
schedule.Description = "hourly schedule";
_testFixture.UpdateSchedule(schedule);
var updatedSchedule = _testFixture.GetSchedule(schedule.Name);
Assert.False(updatedSchedule.Properties.IsEnabled);
Assert.Equal(schedule.Properties.Description, updatedSchedule.Properties.Description);
Assert.False(updatedSchedule.IsEnabled);
Assert.Equal(schedule.Description, updatedSchedule.Description);

_testFixture.DeleteSchedule(schedule.Name);

Expand All @@ -114,22 +116,22 @@ public void CanCreateUpdateDeleteVariable()
var variableName = TestUtilities.GenerateName("variable");
var value = 10;

Variable variable = _testFixture.CreateVariable(variableName, value);
var variable = _testFixture.CreateVariable(variableName, value);
Assert.NotNull(variable);

variable = _testFixture.GetVariable(variable.Name);
Assert.NotNull(variable);
Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject<object>(variable.Properties.Value)));
Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject<object>(variable.Value)));

value = 20;
variable.Properties.Value = JsonConvert.SerializeObject(value);
variable.Properties.Description = "int typed variable";
variable.Value = JsonConvert.SerializeObject(value);
variable.Description = "int typed variable";
_testFixture.UpdateVariable(variable);
var variables = _testFixture.GetVariables();
Assert.Equal(1, variables.Count);
var updatedVariable = variables[0];
Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject<object>(updatedVariable.Properties.Value)));
Assert.Equal(variable.Properties.Description, updatedVariable.Properties.Description);
Assert.Equal(1, variables.ToList().Count);
var updatedVariable = variables.ToList()[0];
Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject<object>(updatedVariable.Value)));
Assert.Equal(variable.Description, updatedVariable.Description);

_testFixture.DeleteVariable(variable.Name);

Expand Down Expand Up @@ -159,7 +161,7 @@ public void CanCreateUpdateDeleteWebhook()
_testFixture.CreateRunbook(runbookName, runbookContent);
_testFixture.PublishRunbook(runbookName);
var runbook = _testFixture.GetRunbook(runbookName);
Assert.Equal("Published", runbook.Properties.State);
Assert.Equal("Published", runbook.State);

var uri = _testFixture.GenerateUriForWebhook();

Expand All @@ -168,19 +170,19 @@ public void CanCreateUpdateDeleteWebhook()

webhook = _testFixture.GetWebhook(webhook.Name);
Assert.NotNull(webhook);
Assert.Equal(runbookName, webhook.Properties.Runbook.Name);
Assert.Equal(runbookName, webhook.Runbook.Name);

webhook.Properties.IsEnabled = false;
webhook.IsEnabled = false;
_testFixture.UpdateWebhook(webhook);
var webhooks = _testFixture.GetWebhooks();
Assert.Equal(1, webhooks.Count);
var updatedWebhook = webhooks[0];
Assert.False(updatedWebhook.Properties.IsEnabled);
Assert.Equal(1, webhooks.ToList().Count);
var updatedWebhook = webhooks.ToList()[0];
Assert.False(updatedWebhook.IsEnabled);

webhooks = _testFixture.GetWebhooks(runbookName);
Assert.Equal(1, webhooks.Count);
updatedWebhook = webhooks[0];
Assert.False(updatedWebhook.Properties.IsEnabled);
Assert.Equal(1, webhooks.ToList().Count);
updatedWebhook = webhooks.ToList()[0];
Assert.False(updatedWebhook.IsEnabled);

_testFixture.DeleteWebhook(webhook.Name);
_testFixture.DeleteRunbook(runbookName);
Expand Down Expand Up @@ -213,18 +215,18 @@ public void CanCreateUpdateDeleteCredential()

credential = _testFixture.GetCredential(credential.Name);
Assert.NotNull(credential);
Assert.Equal(userName, credential.Properties.UserName);
Assert.Equal(userName, credential.UserName);

userName = "userName2";
password = "pwd2";
credential.Properties.UserName = userName;
credential.Properties.Description = "description of credential";
credential.Name = userName;
credential.Description = "description of credential";
_testFixture.UpdateCredential(credential, password);
var credentials = _testFixture.GetCredentials();
Assert.Equal(1, credentials.Count);
var updatedCredential = credentials[0];
Assert.Equal(credential.Properties.UserName, updatedCredential.Properties.UserName);
Assert.Equal(credential.Properties.Description, updatedCredential.Properties.Description);
Assert.Equal(1, credentials.ToList().Count);
var updatedCredential = credentials.ToList()[0];
Assert.Equal(credential.UserName, updatedCredential.UserName);
Assert.Equal(credential.Description, updatedCredential.Description);

_testFixture.DeleteCredential(credential.Name);

Expand Down
Loading

0 comments on commit 45a1b45

Please sign in to comment.