|
23 | 23 | using Xunit;
|
24 | 24 | using System;
|
25 | 25 | using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
|
26 |
| -using System.Management.Automation; |
27 | 26 |
|
28 | 27 | namespace Microsoft.Azure.Commands.ResourceManager.Profile.Test
|
29 | 28 | {
|
30 |
| - public class ContextCmdletTestsLive |
| 29 | + public class ContextCmdletTests : RMTestBase |
31 | 30 | {
|
32 | 31 | private MemoryDataStore dataStore;
|
33 | 32 | private MockCommandRuntime commandRuntimeMock;
|
34 | 33 |
|
35 |
| - public ContextCmdletTestsLive() |
| 34 | + public ContextCmdletTests() |
36 | 35 | {
|
37 | 36 | dataStore = new MemoryDataStore();
|
38 | 37 | AzureSession.DataStore = dataStore;
|
39 | 38 | commandRuntimeMock = new MockCommandRuntime();
|
40 |
| - AzureRMCmdlet.DefaultProfile = new AzureRMProfile(); |
| 39 | + AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); |
41 | 40 | }
|
42 |
| - |
| 41 | + |
43 | 42 | [Fact]
|
44 |
| - [Trait(Category.AcceptanceType, Category.LiveOnly)] |
45 |
| - public void SelectAzureContextWithSubscriptionAndTenant() |
| 43 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 44 | + public void GetAzureContext() |
46 | 45 | {
|
47 |
| - var cmdlt = new SelectAzureRMContextCommand(); |
| 46 | + var cmdlt = new GetAzureRMContextCommand(); |
48 | 47 | // Setup
|
49 | 48 | cmdlt.CommandRuntime = commandRuntimeMock;
|
50 |
| - cmdlt.SubscriptionId = "db1ab6f0-4769-4b27-930e-01e2ef9c123c"; |
51 |
| - cmdlt.Tenant = "72f988bf-86f1-41af-91ab-2d7cd011db47"; |
52 | 49 |
|
53 | 50 | // Act
|
54 |
| - Login("2c224e7e-3ef5-431d-a57b-e71f4662e3a6", null); |
55 | 51 | cmdlt.InvokeBeginProcessing();
|
56 | 52 | cmdlt.ExecuteCmdlet();
|
57 | 53 | cmdlt.InvokeEndProcessing();
|
58 | 54 |
|
59 | 55 | // Verify
|
60 |
| - Assert.True(commandRuntimeMock.OutputPipeline.Count == 2); |
61 |
| - var context = (AzureContext)commandRuntimeMock.OutputPipeline[1]; |
62 |
| - Assert.Equal("db1ab6f0-4769-4b27-930e-01e2ef9c123c", context.Subscription.Id.ToString()); |
| 56 | + Assert.True(commandRuntimeMock.OutputPipeline.Count == 1); |
| 57 | + var context = (AzureContext) commandRuntimeMock.OutputPipeline[0]; |
| 58 | + Assert.Equal("test", context.Subscription.Name); |
63 | 59 | }
|
64 |
| - |
| 60 | + |
65 | 61 | [Fact]
|
66 |
| - [Trait(Category.AcceptanceType, Category.LiveOnly)] |
67 |
| - public void SelectAzureContextWithSubscriptionAndNoTenant() |
| 62 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 63 | + public void SelectAzureContextWithSubscriptionAndTenant() |
68 | 64 | {
|
69 |
| - var cmdlt = new SelectAzureRMContextCommand(); |
| 65 | + var cmdlt = new SetAzureRMContextCommand(); |
70 | 66 | // Setup
|
71 | 67 | cmdlt.CommandRuntime = commandRuntimeMock;
|
72 | 68 | cmdlt.SubscriptionId = "db1ab6f0-4769-4b27-930e-01e2ef9c123c";
|
| 69 | + cmdlt.Tenant = "72f988bf-86f1-41af-91ab-2d7cd011db47"; |
73 | 70 |
|
74 | 71 | // Act
|
75 |
| - Login("2c224e7e-3ef5-431d-a57b-e71f4662e3a6", null); |
76 | 72 | cmdlt.InvokeBeginProcessing();
|
77 | 73 | cmdlt.ExecuteCmdlet();
|
78 | 74 | cmdlt.InvokeEndProcessing();
|
79 | 75 |
|
80 | 76 | // Verify
|
81 |
| - Assert.True(commandRuntimeMock.OutputPipeline.Count == 2); |
82 |
| - var context = (AzureContext)commandRuntimeMock.OutputPipeline[1]; |
| 77 | + Assert.True(commandRuntimeMock.OutputPipeline.Count == 1); |
| 78 | + var context = (AzureContext)commandRuntimeMock.OutputPipeline[0]; |
83 | 79 | Assert.Equal("db1ab6f0-4769-4b27-930e-01e2ef9c123c", context.Subscription.Id.ToString());
|
84 | 80 | Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", context.Tenant.Id.ToString());
|
85 | 81 | }
|
86 | 82 |
|
87 | 83 | [Fact]
|
88 |
| - [Trait(Category.AcceptanceType, Category.LiveOnly)] |
89 |
| - public void SelectAzureContextWithNoSubscriptionAndTenant() |
| 84 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 85 | + public void SelectAzureContextWithSubscriptionAndNoTenant() |
90 | 86 | {
|
91 |
| - var cmdlt = new SelectAzureRMContextCommand(); |
| 87 | + var cmdlt = new SetAzureRMContextCommand(); |
92 | 88 | // Setup
|
93 | 89 | cmdlt.CommandRuntime = commandRuntimeMock;
|
94 |
| - cmdlt.Tenant = "72f988bf-86f1-41af-91ab-2d7cd011db47"; |
| 90 | + cmdlt.SubscriptionId = "db1ab6f0-4769-4b27-930e-01e2ef9c123c"; |
95 | 91 |
|
96 | 92 | // Act
|
97 |
| - Login("2c224e7e-3ef5-431d-a57b-e71f4662e3a6", null); |
98 | 93 | cmdlt.InvokeBeginProcessing();
|
99 | 94 | cmdlt.ExecuteCmdlet();
|
100 | 95 | cmdlt.InvokeEndProcessing();
|
101 | 96 |
|
102 | 97 | // Verify
|
103 |
| - Assert.True(commandRuntimeMock.OutputPipeline.Count == 2); |
104 |
| - var context = (AzureContext)commandRuntimeMock.OutputPipeline[1]; |
105 |
| - Assert.Null(context.Subscription); |
106 |
| - Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", context.Tenant.Id.ToString()); |
| 98 | + Assert.True(commandRuntimeMock.OutputPipeline.Count == 1); |
| 99 | + var context = (AzureContext)commandRuntimeMock.OutputPipeline[0]; |
| 100 | + Assert.Equal("db1ab6f0-4769-4b27-930e-01e2ef9c123c", context.Subscription.Id.ToString()); |
107 | 101 | }
|
108 | 102 |
|
109 | 103 | [Fact]
|
110 |
| - [Trait(Category.AcceptanceType, Category.LiveOnly)] |
111 |
| - public void SelectAzureContextWithNoSubscriptionAndNoTenant() |
| 104 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 105 | + public void SelectAzureContextWithNoSubscriptionAndTenant() |
112 | 106 | {
|
113 |
| - var cmdlt = new SelectAzureRMContextCommand(); |
| 107 | + var cmdlt = new SetAzureRMContextCommand(); |
114 | 108 | // Setup
|
115 | 109 | cmdlt.CommandRuntime = commandRuntimeMock;
|
| 110 | + cmdlt.Tenant = "72f988bf-86f1-41af-91ab-2d7cd011db47"; |
116 | 111 |
|
117 | 112 | // Act
|
118 |
| - Login("2c224e7e-3ef5-431d-a57b-e71f4662e3a6", null); |
119 | 113 | cmdlt.InvokeBeginProcessing();
|
120 |
| - |
121 |
| - // Verify |
122 |
| - Assert.Throws<PSNotSupportedException>(() => cmdlt.ExecuteCmdlet()); |
| 114 | + cmdlt.ExecuteCmdlet(); |
123 | 115 | cmdlt.InvokeEndProcessing();
|
| 116 | + |
| 117 | + // Verify |
| 118 | + Assert.True(commandRuntimeMock.OutputPipeline.Count == 1); |
| 119 | + var context = (AzureContext)commandRuntimeMock.OutputPipeline[0]; |
| 120 | + Assert.Equal("72f988bf-86f1-41af-91ab-2d7cd011db47", context.Tenant.Id.ToString()); |
124 | 121 | }
|
125 | 122 |
|
126 |
| - private void Login(string subscriptionId, string tenantId) |
| 123 | + [Fact] |
| 124 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 125 | + public void SelectAzureContextWithNoSubscriptionAndNoTenant() |
127 | 126 | {
|
128 |
| - var cmdlt = new LoginAzureRMAccountCommand(); |
| 127 | + var cmdlt = new SetAzureRMContextCommand(); |
129 | 128 | // Setup
|
130 | 129 | cmdlt.CommandRuntime = commandRuntimeMock;
|
131 |
| - cmdlt.SubscriptionId = subscriptionId; |
132 |
| - cmdlt.Tenant = tenantId; |
133 | 130 |
|
134 | 131 | // Act
|
135 | 132 | cmdlt.InvokeBeginProcessing();
|
136 | 133 | cmdlt.ExecuteCmdlet();
|
137 | 134 | cmdlt.InvokeEndProcessing();
|
138 | 135 |
|
139 |
| - Assert.NotNull(AzureRMCmdlet.DefaultProfile.Context); |
| 136 | + // Verify |
| 137 | + Assert.True(commandRuntimeMock.OutputPipeline.Count == 1); |
| 138 | + var context = (AzureContext)commandRuntimeMock.OutputPipeline[0]; |
| 139 | + Assert.NotNull(context); |
140 | 140 | }
|
141 | 141 | }
|
142 | 142 | }
|
0 commit comments