Skip to content

Commit 05516e5

Browse files
author
Hovsep Mkrtchyan
committed
Merge branch 'sergey-entity' of https://github.com/sergey-shandar/azure-powershell into sergey-entity
# Conflicts: # src/ResourceManager/Common/Commands.Common.Strategies/Commands.Common.Strategies.csproj
2 parents bfb518a + d5cbdcc commit 05516e5

29 files changed

+559
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies.UnitTest</RootNamespace>
10+
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies.UnitTest</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
</ItemGroup>
40+
<Choose>
41+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
42+
<ItemGroup>
43+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
44+
</ItemGroup>
45+
</When>
46+
<Otherwise>
47+
<ItemGroup>
48+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
49+
</ItemGroup>
50+
</Otherwise>
51+
</Choose>
52+
<ItemGroup>
53+
<Compile Include="TimeSlotTest.cs" />
54+
<Compile Include="Properties\AssemblyInfo.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ProjectReference Include="..\Commands.Common.Strategies\Commands.Common.Strategies.csproj">
58+
<Project>{eea69772-d41b-482a-9252-2b4595c59e53}</Project>
59+
<Name>Commands.Common.Strategies</Name>
60+
</ProjectReference>
61+
</ItemGroup>
62+
<Choose>
63+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
64+
<ItemGroup>
65+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
66+
<Private>False</Private>
67+
</Reference>
68+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
69+
<Private>False</Private>
70+
</Reference>
71+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
72+
<Private>False</Private>
73+
</Reference>
74+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
75+
<Private>False</Private>
76+
</Reference>
77+
</ItemGroup>
78+
</When>
79+
</Choose>
80+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
81+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
82+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
83+
Other similar extension points exist, see Microsoft.Common.targets.
84+
<Target Name="BeforeBuild">
85+
</Target>
86+
<Target Name="AfterBuild">
87+
</Target>
88+
-->
89+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Commands.Common.Strategies.UnitTest")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Commands.Common.Strategies.UnitTest")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("5c052681-da3c-4fea-8e02-7dfbb2a18b22")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace Microsoft.Azure.Commands.Common.Strategies.UnitTest
4+
{
5+
[TestClass]
6+
public class TimeSlotTest
7+
{
8+
[TestMethod]
9+
public void AddTest()
10+
{
11+
var first = new TimeSlot();
12+
13+
Assert.AreEqual(0, first.Duration);
14+
Assert.AreEqual(0, first.TaskCount);
15+
Assert.AreEqual(null, first.Next);
16+
17+
var next = first.AddTask(50);
18+
19+
Assert.AreEqual(50, first.Duration);
20+
Assert.AreEqual(1, first.TaskCount);
21+
Assert.AreEqual(next, first.Next);
22+
23+
Assert.AreEqual(10.0, first.GetTaskProgress(10));
24+
25+
Assert.AreEqual(0, next.Duration);
26+
Assert.AreEqual(0, next.TaskCount);
27+
Assert.AreEqual(null, next.Next);
28+
29+
var next2 = first.AddTask(50);
30+
31+
Assert.AreEqual(50, first.Duration);
32+
Assert.AreEqual(2, first.TaskCount);
33+
Assert.AreEqual(next2, first.Next);
34+
Assert.AreEqual(next, first.Next);
35+
36+
Assert.AreEqual(20.0, first.GetTaskProgress(40));
37+
38+
Assert.AreEqual(0, next2.Duration);
39+
Assert.AreEqual(0, next2.TaskCount);
40+
Assert.AreEqual(null, next2.Next);
41+
42+
var next3 = first.AddTask(30);
43+
Assert.AreEqual(30, first.Duration);
44+
Assert.AreEqual(3, first.TaskCount);
45+
Assert.AreEqual(next3, first.Next);
46+
47+
Assert.AreEqual(3.0, first.GetTaskProgress(9));
48+
49+
Assert.AreEqual(20, next3.Duration);
50+
Assert.AreEqual(2, next3.TaskCount);
51+
Assert.AreEqual(next2, next3.Next);
52+
Assert.AreEqual(next, next3.Next);
53+
54+
Assert.AreEqual(10.0 + 5, first.GetTaskProgress(40));
55+
56+
Assert.AreEqual(0, next2.Duration);
57+
Assert.AreEqual(0, next2.TaskCount);
58+
Assert.AreEqual(null, next2.Next);
59+
60+
var next4 = first.AddTask(75);
61+
Assert.AreEqual(25, next2.Duration);
62+
Assert.AreEqual(1, next2.TaskCount);
63+
Assert.AreEqual(next4, next2.Next);
64+
65+
Assert.AreEqual((30.0 / 4) + (20.0 / 3) + 20, first.GetTaskProgress(70));
66+
67+
Assert.AreEqual(0, next4.Duration);
68+
Assert.AreEqual(0, next4.TaskCount);
69+
Assert.AreEqual(null, next4.Next);
70+
}
71+
}
72+
}

src/ResourceManager/Common/Commands.Common.Strategies/Commands.Common.Strategies.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@
7373
<Compile Include="IReportProgress.cs" />
7474
<Compile Include="IResourceConfig.cs" />
7575
<Compile Include="IResourceConfigVisitor.cs" />
76+
<Compile Include="IResourceStrategy.cs" />
7677
<Compile Include="IShouldProcess.cs" />
7778
<Compile Include="Network\LoadBalancerStrategy.cs" />
79+
<Compile Include="ProgressMap.cs" />
80+
<Compile Include="TimeSlot.cs" />
7881
<Compile Include="StateOperationContext.cs" />
7982
<Compile Include="Compute\ComputeStrategy.cs" />
8083
<Compile Include="Compute\VirtualMachineStrategy.cs" />
8184
<Compile Include="SyncTaskScheduler.cs" />
85+
<Compile Include="TimeSlotExtensions.cs" />
8286
<Compile Include="UpdateStateExtensions.cs" />
8387
<Compile Include="CreateOrUpdateAsyncParams.cs" />
8488
<Compile Include="EntityConfigExtensions.cs" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="..\..\..\..\tools\Common.Netcore.Dependencies.targets" />
4+
5+
<PropertyGroup>
6+
<TargetFramework>netcoreapp2.0</TargetFramework>
7+
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies</AssemblyName>
8+
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
9+
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies</RootNamespace>
10+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
11+
</PropertyGroup>
12+
13+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
14+
<SignAssembly>True</SignAssembly>
15+
<DelaySign>True</DelaySign>
16+
<AssemblyOriginatorKeyFile>MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
17+
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN</DefineConstants>
18+
</PropertyGroup>
19+
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
21+
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
22+
<DelaySign>false</DelaySign>
23+
</PropertyGroup>
24+
25+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
26+
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
27+
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="16.3.0" />
28+
<PackageReference Include="Microsoft.Azure.Management.Network" Version="10.1.0-preview" />
29+
</ItemGroup>
30+
</Project>

src/ResourceManager/Common/Commands.Common.Strategies/Compute/ComputeStrategy.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
2626
string header,
2727
Func<ComputeManagementClient, TOperations> getOperations,
2828
Func<TOperations, GetAsyncParams, Task<TModel>> getAsync,
29-
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync)
29+
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync,
30+
Func<TModel, int> createTime)
3031
where TModel : Resource
3132
=> ResourceStrategy.Create(
3233
type,
@@ -35,6 +36,7 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
3536
getAsync,
3637
createOrUpdateAsync,
3738
config => config.Location,
38-
(config, location) => config.Location = location);
39+
(config, location) => config.Location = location,
40+
createTime);
3941
}
4042
}

src/ResourceManager/Common/Commands.Common.Strategies/Compute/VirtualMachineStrategy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static class VirtualMachineStrategy
2929
(o, p) => o.GetAsync(
3030
p.ResourceGroupName, p.Name, null, p.CancellationToken),
3131
(o, p) => o.CreateOrUpdateAsync(
32-
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
32+
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
33+
_ => 120);
3334

3435
public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
3536
this ResourceConfig<ResourceGroup> resourceGroup,

src/ResourceManager/Common/Commands.Common.Strategies/IReportProgress.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ namespace Microsoft.Azure.Commands.Common.Strategies
1616
{
1717
public interface IProgressReport
1818
{
19-
void Report<TModel>(ResourceConfig<TModel> config, double progress)
20-
where TModel : class;
19+
void Start<TModel>(ResourceConfig<TModel> config)
20+
where TModel : class;
21+
22+
void Done<TModel>(ResourceConfig<TModel> config, double progress)
23+
where TModel : class;
2124
}
2225
}

src/ResourceManager/Common/Commands.Common.Strategies/IResourceConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace Microsoft.Azure.Commands.Common.Strategies
1818
{
1919
public interface IResourceConfig : IEntityConfig
2020
{
21+
new IResourceStrategy Strategy { get; }
22+
2123
string ResourceGroupName { get; }
2224

2325
IEnumerable<IEntityConfig> Dependencies { get; }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Microsoft.Azure.Commands.Common.Strategies
2+
{
3+
public interface IResourceStrategy : IEntityStrategy
4+
{
5+
string Type { get; }
6+
}
7+
}

src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkInterfaceStrategy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public static class NetworkInterfaceStrategy
2828
(o, p) => o.GetAsync(
2929
p.ResourceGroupName, p.Name, null, p.CancellationToken),
3030
(o, p) => o.CreateOrUpdateAsync(
31-
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
31+
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
32+
_ => 5);
3233

3334
public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig(
3435
this ResourceConfig<ResourceGroup> resourceGroup,

src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkSecurityGroupPolicy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static class NetworkSecurityGroupStrategy
2929
(o, p) => o.GetAsync(
3030
p.ResourceGroupName, p.Name, null, p.CancellationToken),
3131
(o, p) => o.CreateOrUpdateAsync(
32-
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
32+
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
33+
_ => 15);
3334

3435
public static ResourceConfig<NetworkSecurityGroup> CreateNetworkSecurityGroupConfig(
3536
this ResourceConfig<ResourceGroup> resourceGroup, string name, int[] openPorts)

src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkStrategy.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
2626
string header,
2727
Func<NetworkManagementClient, TOperations> getOperations,
2828
Func<TOperations, GetAsyncParams, Task<TModel>> getAsync,
29-
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync)
29+
Func<TOperations, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync,
30+
Func<TModel, int> createTime)
3031
where TModel : Resource
3132
=> ResourceStrategy.Create(
3233
type,
@@ -35,6 +36,7 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
3536
getAsync,
3637
createOrUpdateAsync,
3738
model => model.Location,
38-
(model, location) => model.Location = location);
39+
(model, location) => model.Location = location,
40+
createTime);
3941
}
4042
}

src/ResourceManager/Common/Commands.Common.Strategies/Network/PublicIPAddressStrategy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public static class PublicIPAddressStrategy
2828
(o, p) => o.GetAsync(
2929
p.ResourceGroupName, p.Name, null, p.CancellationToken),
3030
(o, p) => o.CreateOrUpdateAsync(
31-
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
31+
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
32+
_ => 15);
3233

3334
public static ResourceConfig<PublicIPAddress> CreatePublicIPAddressConfig(
3435
this ResourceConfig<ResourceGroup> resourceGroup,

src/ResourceManager/Common/Commands.Common.Strategies/Network/VirtualNetworkStrategy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public static class VirtualNetworkStrategy
2828
(o, p) => o.GetAsync(
2929
p.ResourceGroupName, p.Name, null, p.CancellationToken),
3030
(o, p) => o.CreateOrUpdateAsync(
31-
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken));
31+
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
32+
_ => 15);
3233

3334
public static ResourceConfig<VirtualNetwork> CreateVirtualNetworkConfig(
3435
this ResourceConfig<ResourceGroup> resourceGroup,

0 commit comments

Comments
 (0)