Skip to content

Commit b356adf

Browse files
author
Hovsep
committed
Merge pull request Azure#1402 from haocs/hovsep-clu
Moved Resource.Test to CLU.
2 parents 3328b11 + 2c9be6f commit b356adf

36 files changed

+826
-637
lines changed

src/CLU/CLUCoreCLR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Ma
2727
EndProject
2828
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Websites.Test", "Microsoft.Azure.Commands.Websites.Test\Microsoft.Azure.Commands.Websites.Test.xproj", "{F4D46F77-36D6-4BDB-95D0-85B1FAD1E160}"
2929
EndProject
30+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Resources.Test", "Microsoft.Azure.Commands.Resources.Test\Microsoft.Azure.Commands.Resources.Test.xproj", "{A9CC2879-D45D-4DCB-A405-6EEDB749B15F}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -81,6 +83,10 @@ Global
8183
{F4D46F77-36D6-4BDB-95D0-85B1FAD1E160}.Debug|Any CPU.Build.0 = Debug|Any CPU
8284
{F4D46F77-36D6-4BDB-95D0-85B1FAD1E160}.Release|Any CPU.ActiveCfg = Release|Any CPU
8385
{F4D46F77-36D6-4BDB-95D0-85B1FAD1E160}.Release|Any CPU.Build.0 = Release|Any CPU
86+
{A9CC2879-D45D-4DCB-A405-6EEDB749B15F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
87+
{A9CC2879-D45D-4DCB-A405-6EEDB749B15F}.Debug|Any CPU.Build.0 = Debug|Any CPU
88+
{A9CC2879-D45D-4DCB-A405-6EEDB749B15F}.Release|Any CPU.ActiveCfg = Release|Any CPU
89+
{A9CC2879-D45D-4DCB-A405-6EEDB749B15F}.Release|Any CPU.Build.0 = Release|Any CPU
8490
EndGlobalSection
8591
GlobalSection(SolutionProperties) = preSolution
8692
HideSolutionNode = FALSE

src/CLU/Commands.ScenarioTests.ResourceManager.Common/Mocks/MockCommandRuntime.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,81 @@
1616
using System.Collections;
1717
using System.Collections.Generic;
1818
using System.Diagnostics.CodeAnalysis;
19+
using System.Globalization;
1920
using System.Management.Automation;
21+
using System.Management.Automation.Host;
2022

2123
namespace Microsoft.Azure.Commands.Common.Test.Mocks
2224
{
2325
public class MockCommandRuntime : ICommandRuntime
2426
{
27+
/*public class PSHostConcrete : System.Management.Automation.Host.PSHost
28+
{
29+
public override CultureInfo CurrentCulture
30+
{
31+
get
32+
{
33+
throw new NotImplementedException();
34+
}
35+
}
36+
37+
public override CultureInfo CurrentUICulture
38+
{
39+
get
40+
{
41+
throw new NotImplementedException();
42+
}
43+
}
44+
45+
public override Guid InstanceId
46+
{
47+
get
48+
{
49+
throw new NotImplementedException();
50+
}
51+
}
52+
53+
public override bool IsInputRedirected
54+
{
55+
get
56+
{
57+
throw new NotImplementedException();
58+
}
59+
}
60+
61+
public override bool IsOutputRedirected
62+
{
63+
get
64+
{
65+
throw new NotImplementedException();
66+
}
67+
}
68+
69+
public override string Name
70+
{
71+
get
72+
{
73+
throw new NotImplementedException();
74+
}
75+
}
76+
77+
public override PSHostUserInterface UI
78+
{
79+
get
80+
{
81+
throw new NotImplementedException();
82+
}
83+
}
84+
85+
public override Version Version
86+
{
87+
get
88+
{
89+
throw new NotImplementedException();
90+
}
91+
}
92+
}*/
93+
2594
public List<ErrorRecord> ErrorStream = new List<ErrorRecord>();
2695
public List<object> OutputPipeline = new List<object>();
2796
public List<string> WarningStream = new List<string>();

src/CLU/Microsoft.Azure.Commands.Resources.Test/Features/GetAzureProviderFeatureCmdletTests.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace Microsoft.Azure.Commands.Resources.Test
2020
using Microsoft.Azure.Management.Resources;
2121
using Microsoft.Azure.Management.Resources.Models;
2222
using Moq;
23+
using Rest.Azure;
24+
using ScenarioTest;
2325
using System;
2426
using System.Linq;
2527
using System.Management.Automation;
@@ -46,14 +48,14 @@ public class GetAzureProviderFeatureCmdletTests : RMTestBase
4648
/// <summary>
4749
/// A mock of the client
4850
/// </summary>
49-
private readonly Mock<IFeatures> featureOperationsMock;
51+
private readonly Mock<IFeaturesOperations> featureOperationsMock;
5052

5153
/// <summary>
5254
/// Initializes a new instance of the <see cref="GetAzureProviderFeatureCmdletTests"/> class.
5355
/// </summary>
5456
public GetAzureProviderFeatureCmdletTests()
5557
{
56-
this.featureOperationsMock = new Mock<IFeatures>();
58+
this.featureOperationsMock = new Mock<IFeaturesOperations>();
5759
var featureClient = new Mock<IFeatureClient>();
5860

5961
featureClient
@@ -64,12 +66,13 @@ public GetAzureProviderFeatureCmdletTests()
6466

6567
this.cmdlet = new GetAzureProviderFeatureCmdletTest
6668
{
67-
CommandRuntime = commandRuntimeMock.Object,
69+
//CommandRuntime = commandRuntimeMock.Object,
6870
ProviderFeatureClient = new ProviderFeatureClient
6971
{
7072
FeaturesManagementClient = featureClient.Object
7173
}
7274
};
75+
System.Reflection.TypeExtensions.GetProperty(cmdlet.GetType(), "CommandRuntime").SetValue(cmdlet, commandRuntimeMock.Object);
7376
}
7477

7578
/// <summary>
@@ -86,56 +89,46 @@ public void GetProviderFeatureTests()
8689
const string Provider2Namespace = "Providers.Test2";
8790
const string Feature2Name = "feature2";
8891

89-
var provider1RegisteredFeature = new FeatureResponse
92+
var provider1RegisteredFeature = new FeatureResult
9093
{
9194
Id = "featureId1",
9295
Name = Provider1Namespace + "/" + Feature1Name,
9396
Properties = new FeatureProperties
9497
{
9598
State = ProviderFeatureClient.RegisteredStateName,
9699
},
97-
RequestId = "requestId",
98-
StatusCode = HttpStatusCode.OK,
99100
Type = "Microsoft.Features/feature"
100101
};
101102

102-
var provider1UnregisteredFeature = new FeatureResponse
103+
var provider1UnregisteredFeature = new FeatureResult
103104
{
104105
Id = "featureId1",
105106
Name = Provider1Namespace + "/" + Feature2Name,
106107
Properties = new FeatureProperties
107108
{
108109
State = "Unregistered",
109110
},
110-
RequestId = "requestId",
111-
StatusCode = HttpStatusCode.OK,
112111
Type = "Microsoft.Features/feature"
113112
};
114113

115-
var provider2UnregisteredFeature = new FeatureResponse
114+
var provider2UnregisteredFeature = new FeatureResult
116115
{
117116
Id = "featureId2",
118117
Name = Provider2Namespace + "/" + Feature1Name,
119118
Properties = new FeatureProperties
120119
{
121120
State = "Unregistered",
122121
},
123-
RequestId = "requestId",
124-
StatusCode = HttpStatusCode.OK,
125122
Type = "Microsoft.Features/feature"
126123
};
127124

128-
var listResult = new FeatureOperationsListResult
129-
{
130-
Features = new[] { provider1RegisteredFeature, provider1UnregisteredFeature, provider2UnregisteredFeature },
131-
NextLink = null,
132-
RequestId = "requestId",
133-
StatusCode = HttpStatusCode.OK
134-
};
125+
var listResult = new Page<FeatureResult>();
126+
var pagableResult = new[] { provider1RegisteredFeature, provider1UnregisteredFeature, provider2UnregisteredFeature };
127+
System.Reflection.TypeExtensions.GetProperty(listResult.GetType(), "Items").SetValue(listResult, pagableResult);
135128

136129
this.featureOperationsMock
137130
.Setup(f => f.ListAllAsync(It.IsAny<CancellationToken>()))
138-
.Returns(() => Task.FromResult(listResult));
131+
.Returns(() => Task.FromResult((IPage<FeatureResult>)listResult));
139132

140133
// 1. List only registered features of providers
141134
this.commandRuntimeMock
@@ -168,7 +161,7 @@ public void GetProviderFeatureTests()
168161
{
169162
Assert.IsType<PSProviderFeature[]>(obj);
170163
var features = (PSProviderFeature[])obj;
171-
Assert.Equal(listResult.Features.Count, features.Length);
164+
Assert.Equal(listResult.Count(), features.Length);
172165
});
173166

174167
this.cmdlet.ExecuteCmdlet();
@@ -179,12 +172,14 @@ public void GetProviderFeatureTests()
179172
string providerOfChoice = Provider1Namespace;
180173
this.cmdlet.ListAvailable = false;
181174
this.cmdlet.ProviderNamespace = providerOfChoice;
182-
listResult.Features = new[] { provider1RegisteredFeature, provider1UnregisteredFeature };
175+
System.Reflection.TypeExtensions
176+
.GetProperty(listResult.GetType(), "Items")
177+
.SetValue(listResult, new[] { provider1RegisteredFeature, provider1UnregisteredFeature });
183178

184179
this.featureOperationsMock
185180
.Setup(f => f.ListAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
186181
.Callback((string providerName, CancellationToken ignored) => Assert.Equal(providerOfChoice, providerName, StringComparer.OrdinalIgnoreCase))
187-
.Returns(() => Task.FromResult(listResult));
182+
.Returns(() => Task.FromResult((IPage<FeatureResult>)listResult ));
188183

189184
this.commandRuntimeMock
190185
.Setup(m => m.WriteObject(It.IsAny<object>()))
@@ -211,7 +206,9 @@ public void GetProviderFeatureTests()
211206
providerOfChoice = Provider2Namespace;
212207
this.cmdlet.ListAvailable = false;
213208
this.cmdlet.ProviderNamespace = providerOfChoice;
214-
listResult.Features = new[] { provider2UnregisteredFeature };
209+
System.Reflection.TypeExtensions
210+
.GetProperty(listResult.GetType(), "Items")
211+
.SetValue(listResult, new[] { provider2UnregisteredFeature });
215212

216213
this.commandRuntimeMock
217214
.Setup(m => m.WriteObject(It.IsAny<object>()))
@@ -231,7 +228,9 @@ public void GetProviderFeatureTests()
231228
providerOfChoice = Provider1Namespace;
232229
this.cmdlet.ProviderNamespace = providerOfChoice;
233230
this.cmdlet.ListAvailable = true;
234-
listResult.Features = new[] { provider1RegisteredFeature, provider1UnregisteredFeature };
231+
System.Reflection.TypeExtensions
232+
.GetProperty(listResult.GetType(), "Items")
233+
.SetValue(listResult, new[] { provider1RegisteredFeature, provider1UnregisteredFeature });
235234

236235
this.commandRuntimeMock
237236
.Setup(m => m.WriteObject(It.IsAny<object>()))

src/CLU/Microsoft.Azure.Commands.Resources.Test/Features/RegisterProviderFeatureCmdletTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.Azure.Commands.Resources.Test
2020
using Microsoft.Azure.Management.Resources;
2121
using Microsoft.Azure.Management.Resources.Models;
2222
using Moq;
23+
using ScenarioTest;
2324
using System;
2425
using System.Management.Automation;
2526
using System.Net;
@@ -40,7 +41,7 @@ public class RegisterAzureProviderFeatureCmdletTests : RMTestBase
4041
/// <summary>
4142
/// A mock of the client
4243
/// </summary>
43-
private readonly Mock<IFeatures> featureOperationsMock;
44+
private readonly Mock<IFeaturesOperations> featureOperationsMock;
4445

4546
/// <summary>
4647
/// A mock of the command runtime
@@ -52,7 +53,7 @@ public class RegisterAzureProviderFeatureCmdletTests : RMTestBase
5253
/// </summary>
5354
public RegisterAzureProviderFeatureCmdletTests()
5455
{
55-
this.featureOperationsMock = new Mock<IFeatures>();
56+
this.featureOperationsMock = new Mock<IFeaturesOperations>();
5657
var featureClient = new Mock<IFeatureClient>();
5758

5859
featureClient
@@ -67,12 +68,13 @@ public RegisterAzureProviderFeatureCmdletTests()
6768

6869
this.cmdlet = new RegisterAzureProviderFeatureCmdlet()
6970
{
70-
CommandRuntime = commandRuntimeMock.Object,
71+
//CommandRuntime = commandRuntimeMock.Object,
7172
ProviderFeatureClient = new ProviderFeatureClient
7273
{
7374
FeaturesManagementClient = featureClient.Object
7475
}
7576
};
77+
System.Reflection.TypeExtensions.GetProperty(cmdlet.GetType(), "CommandRuntime").SetValue(cmdlet, commandRuntimeMock.Object);
7678
}
7779

7880
/// <summary>
@@ -85,16 +87,14 @@ public void RegisterResourceProviderFeatureTests()
8587
const string ProviderName = "Providers.Test";
8688
const string FeatureName = "Feature1";
8789

88-
var registeredFeature = new FeatureResponse
90+
var registeredFeature = new FeatureResult
8991
{
9092
Id = "featureId1",
9193
Name = ProviderName + "/" + FeatureName,
9294
Properties = new FeatureProperties
9395
{
9496
State = ProviderFeatureClient.RegisteredStateName,
9597
},
96-
RequestId = "requestId",
97-
StatusCode = HttpStatusCode.OK,
9898
Type = "Microsoft.Features/feature"
9999
};
100100

src/CLU/Microsoft.Azure.Commands.Resources.Test/Microsoft.Azure.Commands.Resources.Test.xproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
1212
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
1313
</PropertyGroup>
14-
1514
<PropertyGroup>
1615
<SchemaVersion>2.0</SchemaVersion>
1716
</PropertyGroup>
17+
<ItemGroup>
18+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
19+
</ItemGroup>
1820
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
1921
</Project>

src/CLU/Microsoft.Azure.Commands.Resources.Test/Models.ResourceGroups/ExtensionsTests.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)