|
| 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.Azure.Commands.Common.Authentication.Abstractions; |
| 16 | +using Xunit; |
| 17 | + |
| 18 | +namespace Authentication.Abstractions.Test |
| 19 | +{ |
| 20 | + public class ContextUnitTests |
| 21 | + { |
| 22 | + [Fact] |
| 23 | + public void TestDeepCopy() |
| 24 | + { |
| 25 | + IAzureSubscription subscription = new AzureSubscription() |
| 26 | + { |
| 27 | + Id = "DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD", |
| 28 | + Name = "my sub", |
| 29 | + State = "my state", |
| 30 | + }; |
| 31 | + const string SubHomeTenant = "my home tenant"; |
| 32 | + subscription.SetHomeTenant(SubHomeTenant); |
| 33 | + |
| 34 | + IAzureAccount account = new AzureAccount() |
| 35 | + { |
| 36 | + |
| 37 | + Type = "User" |
| 38 | + }; |
| 39 | + |
| 40 | + IAzureEnvironment environment = new AzureEnvironment() |
| 41 | + { |
| 42 | + Name = "my environment" |
| 43 | + }; |
| 44 | + IAzureTenant tenant = new AzureTenant() |
| 45 | + { |
| 46 | + Id = "DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD" |
| 47 | + }; |
| 48 | + IAzureContext original = new AzureContext(subscription, account, environment, tenant); |
| 49 | + const string PropertyKey = "customPropertyKey"; |
| 50 | + const string PropertyValue = "customPropertyValue"; |
| 51 | + original.SetProperty(PropertyKey, PropertyValue); |
| 52 | + |
| 53 | + IAzureContext clone = original.DeepCopy(); |
| 54 | + |
| 55 | + // references are not equal |
| 56 | + Assert.NotSame(original, clone); |
| 57 | + Assert.NotSame(original.Subscription, clone.Subscription); |
| 58 | + Assert.NotSame(original.Account, clone.Account); |
| 59 | + Assert.NotSame(original.Environment, clone.Environment); |
| 60 | + Assert.NotSame(original.Tenant, clone.Tenant); |
| 61 | + |
| 62 | + // values are equal |
| 63 | + Assert.Equal(original.Subscription.Id, clone.Subscription.Id); |
| 64 | + Assert.Equal(original.Account.Id, clone.Account.Id); |
| 65 | + Assert.Equal(original.Environment.Name, clone.Environment.Name); |
| 66 | + Assert.Equal(original.Tenant.Id, clone.Tenant.Id); |
| 67 | + |
| 68 | + // custom property |
| 69 | + Assert.Equal(SubHomeTenant, clone.Subscription.GetHomeTenant()); |
| 70 | + Assert.Equal(PropertyValue, clone.GetProperty(PropertyKey)); |
| 71 | + } |
| 72 | + |
| 73 | + [Fact] |
| 74 | + public void TestDeepCopyNull() |
| 75 | + { |
| 76 | + IAzureContext original = null; |
| 77 | + Assert.Null(original.DeepCopy()); |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments