Skip to content

Commit

Permalink
Merge branch 'sergey-entity' of https://github.com/sergey-shandar/azu…
Browse files Browse the repository at this point in the history
…re-powershell into sergey-entity

# Conflicts:
#	src/ResourceManager/Common/Commands.Common.Strategies/Commands.Common.Strategies.csproj
  • Loading branch information
Hovsep Mkrtchyan committed Dec 5, 2017
2 parents bfb518a + d5cbdcc commit 05516e5
Show file tree
Hide file tree
Showing 29 changed files with 559 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies.UnitTest</RootNamespace>
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies.UnitTest</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="TimeSlotTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Commands.Common.Strategies\Commands.Common.Strategies.csproj">
<Project>{eea69772-d41b-482a-9252-2b4595c59e53}</Project>
<Name>Commands.Common.Strategies</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Commands.Common.Strategies.UnitTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Commands.Common.Strategies.UnitTest")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5c052681-da3c-4fea-8e02-7dfbb2a18b22")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Azure.Commands.Common.Strategies.UnitTest
{
[TestClass]
public class TimeSlotTest
{
[TestMethod]
public void AddTest()
{
var first = new TimeSlot();

Assert.AreEqual(0, first.Duration);
Assert.AreEqual(0, first.TaskCount);
Assert.AreEqual(null, first.Next);

var next = first.AddTask(50);

Assert.AreEqual(50, first.Duration);
Assert.AreEqual(1, first.TaskCount);
Assert.AreEqual(next, first.Next);

Assert.AreEqual(10.0, first.GetTaskProgress(10));

Assert.AreEqual(0, next.Duration);
Assert.AreEqual(0, next.TaskCount);
Assert.AreEqual(null, next.Next);

var next2 = first.AddTask(50);

Assert.AreEqual(50, first.Duration);
Assert.AreEqual(2, first.TaskCount);
Assert.AreEqual(next2, first.Next);
Assert.AreEqual(next, first.Next);

Assert.AreEqual(20.0, first.GetTaskProgress(40));

Assert.AreEqual(0, next2.Duration);
Assert.AreEqual(0, next2.TaskCount);
Assert.AreEqual(null, next2.Next);

var next3 = first.AddTask(30);
Assert.AreEqual(30, first.Duration);
Assert.AreEqual(3, first.TaskCount);
Assert.AreEqual(next3, first.Next);

Assert.AreEqual(3.0, first.GetTaskProgress(9));

Assert.AreEqual(20, next3.Duration);
Assert.AreEqual(2, next3.TaskCount);
Assert.AreEqual(next2, next3.Next);
Assert.AreEqual(next, next3.Next);

Assert.AreEqual(10.0 + 5, first.GetTaskProgress(40));

Assert.AreEqual(0, next2.Duration);
Assert.AreEqual(0, next2.TaskCount);
Assert.AreEqual(null, next2.Next);

var next4 = first.AddTask(75);
Assert.AreEqual(25, next2.Duration);
Assert.AreEqual(1, next2.TaskCount);
Assert.AreEqual(next4, next2.Next);

Assert.AreEqual((30.0 / 4) + (20.0 / 3) + 20, first.GetTaskProgress(70));

Assert.AreEqual(0, next4.Duration);
Assert.AreEqual(0, next4.TaskCount);
Assert.AreEqual(null, next4.Next);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@
<Compile Include="IReportProgress.cs" />
<Compile Include="IResourceConfig.cs" />
<Compile Include="IResourceConfigVisitor.cs" />
<Compile Include="IResourceStrategy.cs" />
<Compile Include="IShouldProcess.cs" />
<Compile Include="Network\LoadBalancerStrategy.cs" />
<Compile Include="ProgressMap.cs" />
<Compile Include="TimeSlot.cs" />
<Compile Include="StateOperationContext.cs" />
<Compile Include="Compute\ComputeStrategy.cs" />
<Compile Include="Compute\VirtualMachineStrategy.cs" />
<Compile Include="SyncTaskScheduler.cs" />
<Compile Include="TimeSlotExtensions.cs" />
<Compile Include="UpdateStateExtensions.cs" />
<Compile Include="CreateOrUpdateAsyncParams.cs" />
<Compile Include="EntityConfigExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\..\tools\Common.Netcore.Dependencies.targets" />

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies</AssemblyName>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<SignAssembly>True</SignAssembly>
<DelaySign>True</DelaySign>
<AssemblyOriginatorKeyFile>MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
<DelaySign>false</DelaySign>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="16.3.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="10.1.0-preview" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
string header,
Func<ComputeManagementClient, TOperations> getOperations,
Func<TOperations, GetAsyncParams, Task<TModel>> getAsync,
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync)
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync,
Func<TModel, int> createTime)
where TModel : Resource
=> ResourceStrategy.Create(
type,
Expand All @@ -35,6 +36,7 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
getAsync,
createOrUpdateAsync,
config => config.Location,
(config, location) => config.Location = location);
(config, location) => config.Location = location,
createTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static class VirtualMachineStrategy
(o, p) => o.GetAsync(
p.ResourceGroupName, p.Name, null, p.CancellationToken),
(o, p) => o.CreateOrUpdateAsync(
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
_ => 120);

public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
this ResourceConfig<ResourceGroup> resourceGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ namespace Microsoft.Azure.Commands.Common.Strategies
{
public interface IProgressReport
{
void Report<TModel>(ResourceConfig<TModel> config, double progress)
where TModel : class;
void Start<TModel>(ResourceConfig<TModel> config)
where TModel : class;

void Done<TModel>(ResourceConfig<TModel> config, double progress)
where TModel : class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Microsoft.Azure.Commands.Common.Strategies
{
public interface IResourceConfig : IEntityConfig
{
new IResourceStrategy Strategy { get; }

string ResourceGroupName { get; }

IEnumerable<IEntityConfig> Dependencies { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Microsoft.Azure.Commands.Common.Strategies
{
public interface IResourceStrategy : IEntityStrategy
{
string Type { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static class NetworkInterfaceStrategy
(o, p) => o.GetAsync(
p.ResourceGroupName, p.Name, null, p.CancellationToken),
(o, p) => o.CreateOrUpdateAsync(
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
_ => 5);

public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig(
this ResourceConfig<ResourceGroup> resourceGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static class NetworkSecurityGroupStrategy
(o, p) => o.GetAsync(
p.ResourceGroupName, p.Name, null, p.CancellationToken),
(o, p) => o.CreateOrUpdateAsync(
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
_ => 15);

public static ResourceConfig<NetworkSecurityGroup> CreateNetworkSecurityGroupConfig(
this ResourceConfig<ResourceGroup> resourceGroup, string name, int[] openPorts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
string header,
Func<NetworkManagementClient, TOperations> getOperations,
Func<TOperations, GetAsyncParams, Task<TModel>> getAsync,
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync)
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync,
Func<TModel, int> createTime)
where TModel : Resource
=> ResourceStrategy.Create(
type,
Expand All @@ -35,6 +36,7 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
getAsync,
createOrUpdateAsync,
model => model.Location,
(model, location) => model.Location = location);
(model, location) => model.Location = location,
createTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static class PublicIPAddressStrategy
(o, p) => o.GetAsync(
p.ResourceGroupName, p.Name, null, p.CancellationToken),
(o, p) => o.CreateOrUpdateAsync(
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
_ => 15);

public static ResourceConfig<PublicIPAddress> CreatePublicIPAddressConfig(
this ResourceConfig<ResourceGroup> resourceGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static class VirtualNetworkStrategy
(o, p) => o.GetAsync(
p.ResourceGroupName, p.Name, null, p.CancellationToken),
(o, p) => o.CreateOrUpdateAsync(
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
_ => 15);

public static ResourceConfig<VirtualNetwork> CreateVirtualNetworkConfig(
this ResourceConfig<ResourceGroup> resourceGroup,
Expand Down
Loading

0 comments on commit 05516e5

Please sign in to comment.