protected override void ProcessRecord() { base.ProcessRecord(); if (ShouldProcess("removing environment", Name)) { if (GraphEnvironment.BuiltInEnvironments.Keys.Any((k) => string.Equals(k, Name, StringComparison.CurrentCultureIgnoreCase))) { throw new InvalidOperationException( ErrorConstants.Message.CannotModifyBuiltInEnvironment.FormatCurrentCulture("remove", Name)); } GraphSettings settings = this.GetContextSettings(); WriteObject(settings.RemoveEnvironment(Name)); } }
public void ShouldRemoveSettingsFromConfiguredDataStore() { GraphSession.Initialize(() => new GraphSession()); // Arrange GraphSession.Instance.DataStore = new MockDataStore(); GraphSettings settings = new GraphSettings(ProtectedFileProvider.CreateFileProvider(Constants.SettingFilePath, FileProtection.SharedRead)); GraphEnvironment myNewCloudEnv = new GraphEnvironment { Name = "MyNewCloud", Type = GraphEnvironmentConstants.EnvironmentType.UserDefined, AzureADEndpoint = "https://login.MyNewCloud.com", GraphEndpoint = "https://graph.MyNewCloud.com" }; GraphEnvironment trialCloudEnv = new GraphEnvironment { Name = "TrialCloud", Type = GraphEnvironmentConstants.EnvironmentType.UserDefined, AzureADEndpoint = "https://login.TrialCloud.com", GraphEndpoint = "https://graph.TrialCloud.com" }; settings.TrySetEnvironment(myNewCloudEnv, out IGraphEnvironment mergedMyNewCloudEnv); settings.TrySetEnvironment(trialCloudEnv, out IGraphEnvironment mergedTrialCloudEnv); // Act settings.RemoveEnvironment(trialCloudEnv.Name); string settingsContent = GraphSession.Instance.DataStore.ReadFileAsText(Constants.SettingFilePath); // Assert Assert.NotEmpty(settingsContent); // 5 built-in + 1 user-defined Assert.Equal(6, settings.Environments.Count()); GraphSession.Reset(); }