protected override void ProcessRecord() { if (Path != null) { foreach (string filePath in Path) { string absolutePath = this.GetNormalizedAbsolutePath(filePath); WriteObject(_serializer.DeserializeFromFile(absolutePath)); } return; } if (JsonSource != null) { foreach (object jsonSourceItem in JsonSource) { switch (jsonSourceItem) { case string jsonString: WriteObject(_serializer.Deserialize(jsonString)); continue; case FileInfo jsonFile: WriteObject(_serializer.Deserialize(jsonFile)); continue; case TextReader jsonReader: WriteObject(_serializer.Deserialize(jsonReader)); continue; default: this.WriteExceptionAsError( new ArgumentException($"Unsupported type for {nameof(JsonSource)} parameter. Should be a string, FileInfo or TextReader object."), errorId: "InvalidArgument", errorCategory: ErrorCategory.InvalidArgument); continue; } } } }
public void ProfileSaveDoesNotSerializeContext() { var dataStore = new MockDataStore(); var profilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.Instance.ProfileFile); var profile = new AzureSMProfile(profilePath); AzureSession.Instance.DataStore = dataStore; var tenant = Guid.NewGuid().ToString(); var environment = new AzureEnvironment { Name = "testCloud", ActiveDirectory = new Uri("http://contoso.com") }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, }; account.SetTenants(tenant); var sub = new AzureSubscription { Id = new Guid().ToString(), Name = "Contoso Test Subscription", }; sub.SetAccount(account.Id); sub.SetEnvironment(environment.Name); sub.SetTenant(tenant); profile.EnvironmentTable[environment.Name] = environment; profile.AccountTable[account.Id] = account; profile.SubscriptionTable[sub.GetId()] = sub; profile.Save(); var profileFile = profile.ProfilePath; string profileContents = dataStore.ReadFileAsText(profileFile); var readProfile = JsonConvert.DeserializeObject <Dictionary <string, object> >(profileContents); Assert.False(readProfile.ContainsKey("DefaultContext")); AzureSMProfile parsedProfile = new AzureSMProfile(); var serializer = new JsonProfileSerializer(); Assert.True(serializer.Deserialize(profileContents, parsedProfile)); Assert.NotNull(parsedProfile); Assert.NotNull(parsedProfile.Environments); Assert.True(parsedProfile.EnvironmentTable.ContainsKey(environment.Name)); Assert.NotNull(parsedProfile.Accounts); Assert.True(parsedProfile.AccountTable.ContainsKey(account.Id)); Assert.NotNull(parsedProfile.Subscriptions); Assert.True(parsedProfile.SubscriptionTable.ContainsKey(sub.GetId())); }
public void ProfileSaveDoesNotSerializeContext() { var dataStore = new MockDataStore(); var currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); AzureSession.DataStore = dataStore; var client = new ProfileClient(currentProfile); var tenant = Guid.NewGuid().ToString(); var environment = new AzureEnvironment { Name = "testCloud", Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } } }; var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User, Properties = { { AzureAccount.Property.Tenants, tenant } } }; var sub = new AzureSubscription { Account = account.Id, Environment = environment.Name, Id = new Guid(), Name = "Contoso Test Subscription", Properties = { { AzureSubscription.Property.Tenants, tenant } } }; client.AddOrSetEnvironment(environment); client.AddOrSetAccount(account); client.AddOrSetSubscription(sub); currentProfile.Save(); var profileFile = currentProfile.ProfilePath; string profileContents = dataStore.ReadFileAsText(profileFile); var readProfile = JsonConvert.DeserializeObject <Dictionary <string, object> >(profileContents); Assert.False(readProfile.ContainsKey("Context")); AzureProfile parsedProfile = new AzureProfile(); var serializer = new JsonProfileSerializer(); Assert.True(serializer.Deserialize(profileContents, parsedProfile)); Assert.NotNull(parsedProfile); Assert.NotNull(parsedProfile.Environments); Assert.True(parsedProfile.Environments.ContainsKey(environment.Name)); Assert.NotNull(parsedProfile.Accounts); Assert.True(parsedProfile.Accounts.ContainsKey(account.Id)); Assert.NotNull(parsedProfile.Subscriptions); Assert.True(parsedProfile.Subscriptions.ContainsKey(sub.Id)); }