Skip to content

RemoteApp: RestartVm tenant admin cmdlet #717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Collection\RemoteAppCollection.cs" />
<Compile Include="Common\VmObjects.cs" />
<Compile Include="Common\CollectionObjects.cs" />
<Compile Include="Common\MockObject.cs" />
<Compile Include="Common\RemoteApp.cs" />
Expand All @@ -53,6 +54,7 @@
<Compile Include="RemoteProgram\RemoteAppProgram.cs" />
<Compile Include="SecurityPrincipals\RemoteAppSecurityPrincipals.cs" />
<Compile Include="Templates\RemoteAppTemplates.cs" />
<Compile Include="Vm\RemoteAppVm.cs" />
<Compile Include="VNet\RemoteAppVNet.cs" />
<Compile Include="Workspace\RemoteAppWorkspace.cs" />
</ItemGroup>
Expand Down Expand Up @@ -138,7 +140,7 @@
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.0\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.2\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public partial class MockObject
{
internal static IList<Collection> mockCollectionList { get; set; }

internal static IList<RemoteAppVm> mockVmList { get; set; }

internal static IList<Region> mockRegionList {get; set;}

internal static IList<VNet> mockVNetList { get; set; }
Expand Down Expand Up @@ -104,6 +106,10 @@ private static List<T> ExpectedResult<T>()
{
expectedResults = ConvertList<T>(mockCollectionList);
}
else if (typeof(T) == typeof(RemoteAppVm))
{
expectedResults = ConvertList<T>(mockVmList);
}
else if (typeof(T) == typeof(Region))
{
expectedResults = ConvertList <T>(mockRegionList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public abstract class RemoteAppClientTest : TestBase

protected const string collectionName = "test1";

protected const string vmName = "testVm";

protected const string loggedInUserUpn = "[email protected]";

protected const string templateName = "Fake_Windows.vhd";

protected const string billingPlan = "Standard";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.WindowsAzure.Commands.RemoteApp.Test.Common
{
using Microsoft.WindowsAzure.Management.RemoteApp;
using Microsoft.WindowsAzure.Management.RemoteApp.Models;
using Moq;
using Moq.Language.Flow;
using System.Collections.Generic;
using System.Management.Automation;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

public partial class MockObject
{
public static int SetUpDefaultRemoteAppVm(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string vmName, string userUpn, string trackingId)
{
CollectionVmsListResult response = new CollectionVmsListResult();
OperationResultWithTrackingId restartResponse = new OperationResultWithTrackingId()
{
StatusCode = System.Net.HttpStatusCode.Accepted,
TrackingId = trackingId,
RequestId = "111-2222-4444"
};

response.Vms = new List<RemoteAppVm>()
{
new RemoteAppVm()
{
VirtualMachineName = vmName,
LoggedOnUserUpns = { userUpn, "[email protected]" }
},

new RemoteAppVm()
{
VirtualMachineName = "testVm2",
LoggedOnUserUpns = { "[email protected]" }
}
};

mockVmList = new List<RemoteAppVm>();
foreach (RemoteAppVm vm in response.Vms)
{
RemoteAppVm mockVm = new RemoteAppVm()
{
VirtualMachineName = vm.VirtualMachineName,
LoggedOnUserUpns = vm.LoggedOnUserUpns
};
mockVmList.Add(mockVm);
}

ISetup<IRemoteAppManagementClient, Task<CollectionVmsListResult>> setup = clientMock.Setup(c => c.Collections.ListVmsAsync(collectionName, It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));

ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setupRestart = clientMock.Setup(c => c.Collections.RestartVmAsync(collectionName, It.IsAny<RestartVmCommandParameter>(),It.IsAny<CancellationToken>()));
setupRestart.Returns(Task.Factory.StartNew(() => restartResponse));

return mockVmList.Count;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;

namespace Microsoft.WindowsAzure.Commands.RemoteApp.Test
{
using Common;
using Microsoft.WindowsAzure.Management.RemoteApp;
using Microsoft.WindowsAzure.Management.RemoteApp.Cmdlets;
using Microsoft.WindowsAzure.Management.RemoteApp.Models;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Moq;
using Moq.Language.Flow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

// Get-AzureRemoteAppCollectionUsageDetails, Get-AzureRemoteAppCollectionUsageSummary,
public class RemoteAppVmTest : RemoteAppClientTest
{

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RestartVm()
{
int countOfExpectedCollections = 0;
RestartAzureRemoteAppVm mockCmdlet = SetUpTestCommon<RestartAzureRemoteAppVm>();
IEnumerable<TrackingResult> trackingIds = null;

// Required parameters for this test
mockCmdlet.CollectionName = collectionName;
mockCmdlet.UserUpn = loggedInUserUpn;

// Setup the environment for testing this cmdlet
countOfExpectedCollections = MockObject.SetUpDefaultRemoteAppVm(remoteAppManagementClientMock, collectionName, vmName, loggedInUserUpn, trackingId);
mockCmdlet.ResetPipelines();

Log("Calling Restart-AzureRemoteAppVm which should return tracking id.");

mockCmdlet.ExecuteCmdlet();
if (mockCmdlet.runTime().ErrorStream.Count != 0)
{
Assert.True(false,
String.Format("Restart-AzureRemoteAppVm returned the following error {0}.",
mockCmdlet.runTime().ErrorStream[0].Exception.Message
)
);
}

LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast<TrackingResult>();
trackingIds = LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast<TrackingResult>();
Assert.NotNull(trackingIds);

Assert.Equal(1, trackingIds.Count());

Assert.True(trackingIds.Any(t => t.TrackingId == trackingId), "The actual result does not match the expected.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<package id="Microsoft.Rest.ClientRuntime" version="1.2.0" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="0.9.3" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.2" targetFramework="net45" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.7.0.3\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.0\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.2\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.1.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
Expand Down Expand Up @@ -206,6 +206,7 @@
<Compile Include="TemplateImage\RemoveAzureRemoteAppTemplateImage.cs" />
<Compile Include="TemplateImage\RenameAzureRemoteAppTemplateImage.cs" />
<Compile Include="TemplateImage\TemplateImage.cs" />
<Compile Include="Vm\RestartAzureRemoteAppVm.cs" />
<Compile Include="Vnet\GetAzureRemoteAppVnet.cs" />
<Compile Include="Vnet\GetAzureRemoteAppVpnDeviceConfigScript.cs" />
<Compile Include="Vnet\GetAzureRemoteAppVpnDevice.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
Expand Down Expand Up @@ -255,4 +255,16 @@
<data name="UsageDetails" xml:space="preserve">
<value>Get usage details</value>
</data>
<data name="DefaultLogoffMessage" xml:space="preserve">
<value>Please save your work and logoff. You will be logged off automatically after {0} seconds.</value>
</data>
<data name="NoVmInCollectionForUser" xml:space="preserve">
<value>No VM was found for user {0} in collection {1}.</value>
</data>
<data name="RestartVmWarningCaption" xml:space="preserve">
<value>Restart VM {0}</value>
</data>
<data name="RestartVmWarningMessage" xml:space="preserve">
<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>
</data>
</root>
Loading