Skip to content

Commit 698d2b8

Browse files
committed
Merge pull request #741 from amarsi/release-0.9.7
RemoteApp: RestartVm teanat admin cmdlet
2 parents a2d4b68 + af3234f commit 698d2b8

File tree

11 files changed

+349
-7
lines changed

11 files changed

+349
-7
lines changed

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Commands.RemoteApp.Test.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</ItemGroup>
4141
<ItemGroup>
4242
<Compile Include="Collection\RemoteAppCollection.cs" />
43+
<Compile Include="Common\VmObjects.cs" />
4344
<Compile Include="Common\CollectionObjects.cs" />
4445
<Compile Include="Common\MockObject.cs" />
4546
<Compile Include="Common\RemoteApp.cs" />
@@ -53,6 +54,7 @@
5354
<Compile Include="RemoteProgram\RemoteAppProgram.cs" />
5455
<Compile Include="SecurityPrincipals\RemoteAppSecurityPrincipals.cs" />
5556
<Compile Include="Templates\RemoteAppTemplates.cs" />
57+
<Compile Include="Vm\RemoteAppVm.cs" />
5658
<Compile Include="VNet\RemoteAppVNet.cs" />
5759
<Compile Include="Workspace\RemoteAppWorkspace.cs" />
5860
</ItemGroup>
@@ -138,7 +140,7 @@
138140
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
139141
</Reference>
140142
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp">
141-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.0\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
143+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.2\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
142144
</Reference>
143145
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
144146
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/MockObject.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public partial class MockObject
4343
{
4444
internal static IList<Collection> mockCollectionList { get; set; }
4545

46+
internal static IList<RemoteAppVm> mockVmList { get; set; }
47+
4648
internal static IList<Region> mockRegionList {get; set;}
4749

4850
internal static IList<VNet> mockVNetList { get; set; }
@@ -104,6 +106,10 @@ private static List<T> ExpectedResult<T>()
104106
{
105107
expectedResults = ConvertList<T>(mockCollectionList);
106108
}
109+
else if (typeof(T) == typeof(RemoteAppVm))
110+
{
111+
expectedResults = ConvertList<T>(mockVmList);
112+
}
107113
else if (typeof(T) == typeof(Region))
108114
{
109115
expectedResults = ConvertList <T>(mockRegionList);

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public abstract class RemoteAppClientTest : TestBase
4343

4444
protected const string collectionName = "test1";
4545

46+
protected const string vmName = "testVm";
47+
48+
protected const string loggedInUserUpn = "[email protected]";
49+
4650
protected const string templateName = "Fake_Windows.vhd";
4751

4852
protected const string billingPlan = "Standard";
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.WindowsAzure.Commands.RemoteApp.Test.Common
16+
{
17+
using Microsoft.WindowsAzure.Management.RemoteApp;
18+
using Microsoft.WindowsAzure.Management.RemoteApp.Models;
19+
using Moq;
20+
using Moq.Language.Flow;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using System.Net;
24+
using System.Threading;
25+
using System.Threading.Tasks;
26+
27+
public partial class MockObject
28+
{
29+
public static int SetUpDefaultRemoteAppVm(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string vmName, string userUpn, string trackingId)
30+
{
31+
CollectionVmsListResult response = new CollectionVmsListResult();
32+
OperationResultWithTrackingId restartResponse = new OperationResultWithTrackingId()
33+
{
34+
StatusCode = System.Net.HttpStatusCode.Accepted,
35+
TrackingId = trackingId,
36+
RequestId = "111-2222-4444"
37+
};
38+
39+
response.Vms = new List<RemoteAppVm>()
40+
{
41+
new RemoteAppVm()
42+
{
43+
VirtualMachineName = vmName,
44+
LoggedOnUserUpns = { userUpn, "[email protected]" }
45+
},
46+
47+
new RemoteAppVm()
48+
{
49+
VirtualMachineName = "testVm2",
50+
LoggedOnUserUpns = { "[email protected]" }
51+
}
52+
};
53+
54+
mockVmList = new List<RemoteAppVm>();
55+
foreach (RemoteAppVm vm in response.Vms)
56+
{
57+
RemoteAppVm mockVm = new RemoteAppVm()
58+
{
59+
VirtualMachineName = vm.VirtualMachineName,
60+
LoggedOnUserUpns = vm.LoggedOnUserUpns
61+
};
62+
mockVmList.Add(mockVm);
63+
}
64+
65+
ISetup<IRemoteAppManagementClient, Task<CollectionVmsListResult>> setup = clientMock.Setup(c => c.Collections.ListVmsAsync(collectionName, It.IsAny<CancellationToken>()));
66+
setup.Returns(Task.Factory.StartNew(() => response));
67+
68+
ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setupRestart = clientMock.Setup(c => c.Collections.RestartVmAsync(collectionName, It.IsAny<RestartVmCommandParameter>(),It.IsAny<CancellationToken>()));
69+
setupRestart.Returns(Task.Factory.StartNew(() => restartResponse));
70+
71+
return mockVmList.Count;
72+
}
73+
}
74+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
17+
namespace Microsoft.WindowsAzure.Commands.RemoteApp.Test
18+
{
19+
using Common;
20+
using Microsoft.WindowsAzure.Management.RemoteApp;
21+
using Microsoft.WindowsAzure.Management.RemoteApp.Cmdlets;
22+
using Microsoft.WindowsAzure.Management.RemoteApp.Models;
23+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
24+
using Moq;
25+
using Moq.Language.Flow;
26+
using System;
27+
using System.Collections.Generic;
28+
using System.Linq;
29+
using System.Management.Automation;
30+
using System.Threading;
31+
using System.Threading.Tasks;
32+
using Xunit;
33+
34+
// Get-AzureRemoteAppCollectionUsageDetails, Get-AzureRemoteAppCollectionUsageSummary,
35+
public class RemoteAppVmTest : RemoteAppClientTest
36+
{
37+
38+
[Fact]
39+
[Trait(Category.AcceptanceType, Category.CheckIn)]
40+
public void RestartVm()
41+
{
42+
int countOfExpectedCollections = 0;
43+
RestartAzureRemoteAppVm mockCmdlet = SetUpTestCommon<RestartAzureRemoteAppVm>();
44+
IEnumerable<TrackingResult> trackingIds = null;
45+
46+
// Required parameters for this test
47+
mockCmdlet.CollectionName = collectionName;
48+
mockCmdlet.UserUpn = loggedInUserUpn;
49+
50+
// Setup the environment for testing this cmdlet
51+
countOfExpectedCollections = MockObject.SetUpDefaultRemoteAppVm(remoteAppManagementClientMock, collectionName, vmName, loggedInUserUpn, trackingId);
52+
mockCmdlet.ResetPipelines();
53+
54+
Log("Calling Restart-AzureRemoteAppVm which should return tracking id.");
55+
56+
mockCmdlet.ExecuteCmdlet();
57+
if (mockCmdlet.runTime().ErrorStream.Count != 0)
58+
{
59+
Assert.True(false,
60+
String.Format("Restart-AzureRemoteAppVm returned the following error {0}.",
61+
mockCmdlet.runTime().ErrorStream[0].Exception.Message
62+
)
63+
);
64+
}
65+
66+
LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast<TrackingResult>();
67+
trackingIds = LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast<TrackingResult>();
68+
Assert.NotNull(trackingIds);
69+
70+
Assert.Equal(1, trackingIds.Count());
71+
72+
Assert.True(trackingIds.Any(t => t.TrackingId == trackingId), "The actual result does not match the expected.");
73+
}
74+
}
75+
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<package id="Microsoft.Rest.ClientRuntime" version="1.2.0" targetFramework="net45" />
1414
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="0.9.3" targetFramework="net45" />
1515
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
16-
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.0" targetFramework="net45" />
16+
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.2" targetFramework="net45" />
1717
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
1818
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
1919
<package id="xunit" version="1.9.2" targetFramework="net45" />

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.Designer.cs

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.7.0.3\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
122122
</Reference>
123123
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp">
124-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.0\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
124+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.2\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
125125
</Reference>
126126
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
127127
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.1.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
@@ -206,6 +206,7 @@
206206
<Compile Include="TemplateImage\RemoveAzureRemoteAppTemplateImage.cs" />
207207
<Compile Include="TemplateImage\RenameAzureRemoteAppTemplateImage.cs" />
208208
<Compile Include="TemplateImage\TemplateImage.cs" />
209+
<Compile Include="Vm\RestartAzureRemoteAppVm.cs" />
209210
<Compile Include="Vnet\GetAzureRemoteAppVnet.cs" />
210211
<Compile Include="Vnet\GetAzureRemoteAppVpnDeviceConfigScript.cs" />
211212
<Compile Include="Vnet\GetAzureRemoteAppVpnDevice.cs" />
@@ -248,4 +249,4 @@
248249
<Target Name="AfterBuild">
249250
</Target>
250251
-->
251-
</Project>
252+
</Project>

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.resx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<root>
33
<!--
44
Microsoft ResX Schema
5-
5+
66
Version 2.0
77
88
The primary goals of this format is to allow a simple XML format
@@ -255,4 +255,16 @@
255255
<data name="UsageDetails" xml:space="preserve">
256256
<value>Get usage details</value>
257257
</data>
258+
<data name="DefaultLogoffMessage" xml:space="preserve">
259+
<value>Please save your work and logoff. You will be logged off automatically after {0} seconds.</value>
260+
</data>
261+
<data name="NoVmInCollectionForUser" xml:space="preserve">
262+
<value>No VM was found for user {0} in collection {1}.</value>
263+
</data>
264+
<data name="RestartVmWarningCaption" xml:space="preserve">
265+
<value>Restart VM {0}</value>
266+
</data>
267+
<data name="RestartVmWarningMessage" xml:space="preserve">
268+
<value>User {0} is on VM {1}. These users also have active sessions on this VM and will be logged off when the VM is rebooted: {2}</value>
269+
</data>
258270
</root>

0 commit comments

Comments
 (0)