diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Commands.RemoteApp.Test.csproj b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Commands.RemoteApp.Test.csproj index 1ea41f780056..5b2cf07d811b 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Commands.RemoteApp.Test.csproj +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Commands.RemoteApp.Test.csproj @@ -40,6 +40,7 @@ + @@ -53,6 +54,7 @@ + @@ -138,7 +140,7 @@ ..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll - ..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.0\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll + ..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.2\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll ..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/MockObject.cs b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/MockObject.cs index 9e440f01eef9..bdab7a78f70a 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/MockObject.cs +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/MockObject.cs @@ -43,6 +43,8 @@ public partial class MockObject { internal static IList mockCollectionList { get; set; } + internal static IList mockVmList { get; set; } + internal static IList mockRegionList {get; set;} internal static IList mockVNetList { get; set; } @@ -104,6 +106,10 @@ private static List ExpectedResult() { expectedResults = ConvertList(mockCollectionList); } + else if (typeof(T) == typeof(RemoteAppVm)) + { + expectedResults = ConvertList(mockVmList); + } else if (typeof(T) == typeof(Region)) { expectedResults = ConvertList (mockRegionList); diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs index f673bf1cc1e2..9db14847cccd 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs @@ -43,6 +43,10 @@ public abstract class RemoteAppClientTest : TestBase protected const string collectionName = "test1"; + protected const string vmName = "testVm"; + + protected const string loggedInUserUpn = "test@somedomain.com"; + protected const string templateName = "Fake_Windows.vhd"; protected const string billingPlan = "Standard"; diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/VmObjects.cs b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/VmObjects.cs new file mode 100644 index 000000000000..a473bbc35dbf --- /dev/null +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/VmObjects.cs @@ -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 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() + { + new RemoteAppVm() + { + VirtualMachineName = vmName, + LoggedOnUserUpns = { userUpn, "testuser1@somedomain.com" } + }, + + new RemoteAppVm() + { + VirtualMachineName = "testVm2", + LoggedOnUserUpns = { "testuser2@somedomain.com" } + } + }; + + mockVmList = new List(); + foreach (RemoteAppVm vm in response.Vms) + { + RemoteAppVm mockVm = new RemoteAppVm() + { + VirtualMachineName = vm.VirtualMachineName, + LoggedOnUserUpns = vm.LoggedOnUserUpns + }; + mockVmList.Add(mockVm); + } + + ISetup> setup = clientMock.Setup(c => c.Collections.ListVmsAsync(collectionName, It.IsAny())); + setup.Returns(Task.Factory.StartNew(() => response)); + + ISetup> setupRestart = clientMock.Setup(c => c.Collections.RestartVmAsync(collectionName, It.IsAny(),It.IsAny())); + setupRestart.Returns(Task.Factory.StartNew(() => restartResponse)); + + return mockVmList.Count; + } + } +} diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Vm/RemoteAppVm.cs b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Vm/RemoteAppVm.cs new file mode 100644 index 000000000000..b112be74d200 --- /dev/null +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Vm/RemoteAppVm.cs @@ -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(); + IEnumerable 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(); + trackingIds = LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast(); + Assert.NotNull(trackingIds); + + Assert.Equal(1, trackingIds.Count()); + + Assert.True(trackingIds.Any(t => t.TrackingId == trackingId), "The actual result does not match the expected."); + } + } +} diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config index 6efd4e03933f..679565eb19a0 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config @@ -13,7 +13,7 @@ - + diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.Designer.cs b/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.Designer.cs index a6f459a583d9..d020b43b18ca 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.Designer.cs +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -87,6 +87,15 @@ internal static string CreateJobFailedError { } } + /// + /// Looks up a localized string similar to Please save your work and logoff. You will be logged off automatically after {0} seconds.. + /// + internal static string DefaultLogoffMessage { + get { + return ResourceManager.GetString("DefaultLogoffMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to generate the detailed usage informaton. Please try again and if it still does not succeed, then call Microsoft support.. /// @@ -258,6 +267,15 @@ internal static string NoVmImageFoundErrorFormat { } } + /// + /// Looks up a localized string similar to No VM was found for user {0} in collection {1}.. + /// + internal static string NoVmInCollectionForUser { + get { + return ResourceManager.GetString("NoVmInCollectionForUser", resourceCulture); + } + } + /// /// Looks up a localized string similar to Publish RemoteApp. /// @@ -303,6 +321,24 @@ internal static string RequestTimedOutFormat { } } + /// + /// Looks up a localized string similar to Restart VM {0}. + /// + internal static string RestartVmWarningCaption { + get { + return ResourceManager.GetString("RestartVmWarningCaption", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 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}. + /// + internal static string RestartVmWarningMessage { + get { + return ResourceManager.GetString("RestartVmWarningMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Logging off user session.... /// diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj b/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj index a9287fc65eaf..a1b23a799b2b 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj @@ -121,7 +121,7 @@ ..\..\..\packages\Microsoft.WindowsAzure.Management.Network.7.0.3\lib\net40\Microsoft.WindowsAzure.Management.Network.dll - ..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.0\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll + ..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.2\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll ..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.1.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll @@ -206,6 +206,7 @@ + @@ -248,4 +249,4 @@ --> - \ No newline at end of file + diff --git a/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.resx b/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.resx index fe004c0f451c..38f3f3822cb1 100644 --- a/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.resx +++ b/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.resx @@ -2,7 +2,7 @@