|
| 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 | + |
| 16 | +namespace Microsoft.Azure.Commands.Test.RemoteApp |
| 17 | +{ |
| 18 | + using Common; |
| 19 | + using Microsoft.Azure.Management.RemoteApp.Cmdlets; |
| 20 | + using Microsoft.Azure.Management.RemoteApp.Models; |
| 21 | + using System; |
| 22 | + using System.Collections.Generic; |
| 23 | + using System.Management.Automation; |
| 24 | + using VisualStudio.TestTools.UnitTesting; |
| 25 | + |
| 26 | + // Get-AzureRemoteAppCollectionUsageDetails, Get-AzureRemoteAppCollectionUsageSummary, |
| 27 | + [TestClass] |
| 28 | + public class RemoteAppCollectionTest : RemoteAppClientTest |
| 29 | + { |
| 30 | + |
| 31 | + [TestMethod] |
| 32 | + public void GetAllCollections() |
| 33 | + { |
| 34 | + int countOfExpectedCollections = 0; |
| 35 | + GetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon<GetAzureRemoteAppCollection>(); |
| 36 | + |
| 37 | + // Setup the environment for testing this cmdlet |
| 38 | + countOfExpectedCollections = MockObject.SetUpDefaultRemoteAppCollection(remoteAppManagementClientMock, collectionName); |
| 39 | + mockCmdlet.ResetPipelines(); |
| 40 | + |
| 41 | + Log("Calling Get-AzureRemoteAppCollection which should have {0} collections.", countOfExpectedCollections); |
| 42 | + |
| 43 | + mockCmdlet.ExecuteCmdlet(); |
| 44 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 45 | + { |
| 46 | + Assert.Fail( |
| 47 | + String.Format("Get-AzureRemoteAppCollection returned the following error {0}.", |
| 48 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 49 | + ) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + List<Collection> collections = MockObject.ConvertList<Collection>(mockCmdlet.runTime().OutputPipeline); |
| 54 | + Assert.IsNotNull(collections); |
| 55 | + |
| 56 | + Assert.IsTrue(collections.Count == countOfExpectedCollections, |
| 57 | + String.Format("The expected number of collections returned {0} does not match the actual {1}.", |
| 58 | + countOfExpectedCollections, |
| 59 | + collections.Count |
| 60 | + ) |
| 61 | + ); |
| 62 | + |
| 63 | + Assert.IsTrue(MockObject.HasExpectedResults<Collection>(collections, MockObject.ContainsExpectedCollection), |
| 64 | + "The actual result does not match the expected." |
| 65 | + ); |
| 66 | + |
| 67 | + Log("The test for Get-AzureRemoteAppCollection with {0} collections completed successfully", countOfExpectedCollections); |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + [TestMethod] |
| 72 | + public void GetCollectionsByName() |
| 73 | + { |
| 74 | + int countOfExpectedCollections = 1; |
| 75 | + GetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon<GetAzureRemoteAppCollection>(); |
| 76 | + |
| 77 | + // Required parameters for this test |
| 78 | + mockCmdlet.CollectionName = collectionName; |
| 79 | + |
| 80 | + // Setup the environment for testing this cmdlet |
| 81 | + MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName); |
| 82 | + mockCmdlet.ResetPipelines(); |
| 83 | + |
| 84 | + Log("Calling Get-AzureRemoteAppCollection to get this collection {0}.", mockCmdlet.CollectionName); |
| 85 | + |
| 86 | + mockCmdlet.ExecuteCmdlet(); |
| 87 | + |
| 88 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 89 | + { |
| 90 | + Assert.Fail( |
| 91 | + String.Format("Get-AzureRemoteAppUser returned the following error {0}.", |
| 92 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 93 | + ) |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + List<Collection> collections = MockObject.ConvertList<Collection>(mockCmdlet.runTime().OutputPipeline); |
| 98 | + Assert.IsNotNull(collections); |
| 99 | + |
| 100 | + Assert.IsTrue(collections.Count == countOfExpectedCollections, |
| 101 | + String.Format("The expected number of collections returned {0} does not match the actual {1}.", |
| 102 | + countOfExpectedCollections, |
| 103 | + collections.Count |
| 104 | + ) |
| 105 | + ); |
| 106 | + |
| 107 | + Assert.IsTrue(MockObject.HasExpectedResults<Collection>(collections, MockObject.ContainsExpectedCollection), |
| 108 | + "The actual result does not match the expected." |
| 109 | + ); |
| 110 | + |
| 111 | + Log("The test for Get-AzureRemoteAppCollection with {0} collections completed successfully", countOfExpectedCollections); |
| 112 | + } |
| 113 | + |
| 114 | + |
| 115 | + [TestMethod] |
| 116 | + public void AddCollection() |
| 117 | + { |
| 118 | + List<TrackingResult> trackingIds = null; |
| 119 | + int countOfExpectedCollections = 0; |
| 120 | + NewAzureRemoteAppCollection mockCmdlet = SetUpTestCommon<NewAzureRemoteAppCollection>(); |
| 121 | + |
| 122 | + // Required parameters for this test |
| 123 | + mockCmdlet.CollectionName = collectionName; |
| 124 | + mockCmdlet.Region = region; |
| 125 | + mockCmdlet.BillingPlan = billingPlan; |
| 126 | + mockCmdlet.ImageName = templateName; |
| 127 | + mockCmdlet.Description = description; |
| 128 | + mockCmdlet.CustomRdpProperty = customRDPString; |
| 129 | + |
| 130 | + // Setup the environment for testing this cmdlet |
| 131 | + countOfExpectedCollections = MockObject.SetUpDefaultRemoteAppCollectionCreate(remoteAppManagementClientMock, mockCmdlet.CollectionName, mockCmdlet.Region, mockCmdlet.BillingPlan, mockCmdlet.ImageName, mockCmdlet.Description, mockCmdlet.CustomRdpProperty, trackingId); |
| 132 | + mockCmdlet.ResetPipelines(); |
| 133 | + |
| 134 | + mockCmdlet.ExecuteCmdlet(); |
| 135 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 136 | + { |
| 137 | + Assert.Fail( |
| 138 | + String.Format("New-AzureRemoteAppCollection returned the following error {0}", |
| 139 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 140 | + ) |
| 141 | + ); |
| 142 | + } |
| 143 | + |
| 144 | + trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline); |
| 145 | + Assert.IsNotNull(trackingIds); |
| 146 | + |
| 147 | + Assert.IsTrue(trackingIds.Count == countOfExpectedCollections, |
| 148 | + String.Format("The expected number of collections returned {0} does not match the actual {1}", |
| 149 | + countOfExpectedCollections, |
| 150 | + trackingIds.Count |
| 151 | + ) |
| 152 | + ); |
| 153 | + |
| 154 | + Assert.IsTrue(MockObject.HasExpectedResults<TrackingResult>(trackingIds, MockObject.ContainsExpectedTrackingId), |
| 155 | + "The actual result does not match the expected." |
| 156 | + ); |
| 157 | + |
| 158 | + Log("The test for New-AzureRemoteAppCollection completed successfully"); |
| 159 | + } |
| 160 | + |
| 161 | + [TestMethod] |
| 162 | + public void UpdateCollection() |
| 163 | + { |
| 164 | + List<TrackingResult> trackingIds = null; |
| 165 | + int countOfExpectedCollections = 0; |
| 166 | + UpdaAzureRemoteAppCollection mockCmdlet = SetUpTestCommon<UpdaAzureRemoteAppCollection>(); |
| 167 | + |
| 168 | + // Required parameters for this test |
| 169 | + mockCmdlet.CollectionName = collectionName; |
| 170 | + mockCmdlet.ImageName = templateName; |
| 171 | + |
| 172 | + // Setup the environment for testing this cmdlet |
| 173 | + MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, mockCmdlet.CollectionName); |
| 174 | + countOfExpectedCollections = MockObject.SetUpDefaultRemoteAppCollectionSet(remoteAppManagementClientMock, mockCmdlet.CollectionName, subscriptionId, String.Empty, mockCmdlet.ImageName, null, String.Empty, trackingId); |
| 175 | + mockCmdlet.ResetPipelines(); |
| 176 | + |
| 177 | + mockCmdlet.ExecuteCmdlet(); |
| 178 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 179 | + { |
| 180 | + Assert.Fail( |
| 181 | + String.Format("New-AzureRemoteAppCollection returned the following error {0}", |
| 182 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 183 | + ) |
| 184 | + ); |
| 185 | + } |
| 186 | + |
| 187 | + trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline); |
| 188 | + Assert.IsNotNull(trackingIds); |
| 189 | + |
| 190 | + Assert.IsTrue(trackingIds.Count == countOfExpectedCollections, |
| 191 | + String.Format("The expected number of collections returned {0} does not match the actual {1}", |
| 192 | + countOfExpectedCollections, |
| 193 | + trackingIds.Count |
| 194 | + ) |
| 195 | + ); |
| 196 | + |
| 197 | + Assert.IsTrue(MockObject.HasExpectedResults<TrackingResult>(trackingIds, MockObject.ContainsExpectedTrackingId), |
| 198 | + "The actual result does not match the expected." |
| 199 | + ); |
| 200 | + |
| 201 | + Log("The test for Update-AzureRemoteAppCollection completed successfully"); |
| 202 | + } |
| 203 | + |
| 204 | + [TestMethod] |
| 205 | + public void SetCollection() |
| 206 | + { |
| 207 | + List<TrackingResult> trackingIds = null; |
| 208 | + int countOfExpectedCollections = 0; |
| 209 | + SetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon<SetAzureRemoteAppCollection>(); |
| 210 | + |
| 211 | + System.Security.SecureString password = new System.Security.SecureString(); |
| 212 | + password.AppendChar('p'); |
| 213 | + |
| 214 | + // Required parameters for this test |
| 215 | + mockCmdlet.CollectionName = collectionName; |
| 216 | + mockCmdlet.BillingPlan = billingPlan; |
| 217 | + mockCmdlet.Credential = new PSCredential(@"MyDomain\Administrator", password); |
| 218 | + |
| 219 | + // Setup the environment for testing this cmdlet |
| 220 | + MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, mockCmdlet.CollectionName); |
| 221 | + countOfExpectedCollections = MockObject.SetUpDefaultRemoteAppCollectionSet(remoteAppManagementClientMock, mockCmdlet.CollectionName, subscriptionId, mockCmdlet.BillingPlan, String.Empty, mockCmdlet.Credential, domainName, trackingId); |
| 222 | + mockCmdlet.ResetPipelines(); |
| 223 | + |
| 224 | + mockCmdlet.ExecuteCmdlet(); |
| 225 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 226 | + { |
| 227 | + Assert.Fail( |
| 228 | + String.Format("New-AzureRemoteAppCollection returned the following error {0}", |
| 229 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 230 | + ) |
| 231 | + ); |
| 232 | + } |
| 233 | + |
| 234 | + trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline); |
| 235 | + Assert.IsNotNull(trackingIds); |
| 236 | + |
| 237 | + Assert.IsTrue(trackingIds.Count == countOfExpectedCollections, |
| 238 | + String.Format("The expected number of collections returned {0} does not match the actual {1}", |
| 239 | + countOfExpectedCollections, |
| 240 | + trackingIds.Count |
| 241 | + ) |
| 242 | + ); |
| 243 | + |
| 244 | + Assert.IsTrue(MockObject.HasExpectedResults<TrackingResult>(trackingIds, MockObject.ContainsExpectedTrackingId), |
| 245 | + "The actual result does not match the expected." |
| 246 | + ); |
| 247 | + |
| 248 | + Log("The test for New-AzureRemoteAppCollection completed successfully"); |
| 249 | + } |
| 250 | + |
| 251 | + [TestMethod] |
| 252 | + public void RemoveCollection() |
| 253 | + { |
| 254 | + List<TrackingResult> trackingIds = null; |
| 255 | + RemoveAzureRemoteAppCollection mockCmdlet = SetUpTestCommon<RemoveAzureRemoteAppCollection>(); |
| 256 | + |
| 257 | + // Required parameters for this test |
| 258 | + mockCmdlet.CollectionName = collectionName; |
| 259 | + |
| 260 | + // Setup the environment for testing this cmdlet |
| 261 | + MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName); |
| 262 | + MockObject.SetUpDefaultRemoteAppCollectionDelete(remoteAppManagementClientMock, mockCmdlet.CollectionName, trackingId); |
| 263 | + mockCmdlet.ResetPipelines(); |
| 264 | + |
| 265 | + Log("Calling Remove-AzureRemoteAppCollection"); |
| 266 | + |
| 267 | + mockCmdlet.ExecuteCmdlet(); |
| 268 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 269 | + { |
| 270 | + Assert.Fail( |
| 271 | + String.Format("Remove-AzureRemoteAppCollection returned the following error {0}", |
| 272 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 273 | + ) |
| 274 | + ); |
| 275 | + } |
| 276 | + |
| 277 | + trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline); |
| 278 | + Assert.IsNotNull(trackingIds); |
| 279 | + |
| 280 | + Assert.IsTrue(MockObject.HasExpectedResults<TrackingResult>(trackingIds, MockObject.ContainsExpectedTrackingId), |
| 281 | + "The actual result does not match the expected." |
| 282 | + ); |
| 283 | + |
| 284 | + Log("The test for Remove-AzureRemoteAppCollection completed successfully"); |
| 285 | + } |
| 286 | + |
| 287 | + [TestMethod] |
| 288 | + public void GetRegionList() |
| 289 | + { |
| 290 | + List<Region> regionList = null; |
| 291 | + List<string> regions = null; |
| 292 | + GetAzureRemoteAppRegionList mockCmdlet = SetUpTestCommon<GetAzureRemoteAppRegionList>(); |
| 293 | + |
| 294 | + // Setup the environment for testing this cmdlet |
| 295 | + MockObject.SetUpDefaultRemoteAppRegionList(remoteAppManagementClientMock); |
| 296 | + mockCmdlet.ResetPipelines(); |
| 297 | + |
| 298 | + Log("Calling Get-AzureRemoteAppRegionList"); |
| 299 | + |
| 300 | + mockCmdlet.ExecuteCmdlet(); |
| 301 | + if (mockCmdlet.runTime().ErrorStream.Count != 0) |
| 302 | + { |
| 303 | + Assert.Fail( |
| 304 | + String.Format("Get-AzureRemoteAppRegionList returned the following error {0}.", |
| 305 | + mockCmdlet.runTime().ErrorStream[0].Exception.Message |
| 306 | + ) |
| 307 | + ); |
| 308 | + } |
| 309 | + |
| 310 | + Assert.IsNotNull(regionList); |
| 311 | + regionList = MockObject.ConvertList<Region>(mockCmdlet.runTime().OutputPipeline); |
| 312 | + |
| 313 | + Assert.IsTrue(MockObject.HasExpectedResults<string>(regions, MockObject.ContainsExpectedRegion), // This is expecting a List<string> instead of LocalModels.RegionList |
| 314 | + "The actual result does not match the expected." |
| 315 | + ); |
| 316 | + |
| 317 | + Log("The test for Get-AzureRemoteAppRegionList"); |
| 318 | + } |
| 319 | + |
| 320 | + } |
| 321 | +} |
0 commit comments