public async Task PropertyGridSingle() { var fs = Substitute.For <IFileSystem>(); var up = Substitute.For <UnconfiguredProject>(); up.FullPath.Returns(Path.Combine(_files.DestinationPath, "file.rproj")); var control = new SettingsPageControl(_csp, _shell, fs); var fileName = "PropertyGridSingle.settings.r"; var file = Path.Combine(_files.DestinationPath, fileName); fs.GetFileSystemEntries(Arg.Any <string>(), Arg.Any <string>(), SearchOption.AllDirectories).Returns(new string[] { file }); await control.SetProjectAsync(up, _properties); control.CreateControl(); control.FileListCombo.Items.Count.Should().BeGreaterThan(0); control.FileListCombo.Items.Should().Contain("~/" + fileName); control.PropertyGrid.SelectedObject.Should().NotBeNull(); var desc = control.PropertyGrid.SelectedObject as SettingsTypeDescriptor; desc.Should().NotBeNull(); desc.GetProperties().Should().HaveCount(1); var prop = desc.GetProperties()[0] as SettingPropertyDescriptor; prop.Should().NotBeNull(); prop.Setting.Name.Should().Be("x"); prop.Setting.Value.Should().Be("1"); prop.Setting.ValueType.Should().Be(ConfigurationSettingValueType.Expression); }
public async Task PropertyGridMultiple02() { var shell = Substitute.For <ICoreShell>(); var fs = Substitute.For <IFileSystem>(); var up = Substitute.For <UnconfiguredProject>(); up.FullPath.Returns(Path.Combine(_files.DestinationPath, "file.rproj")); var control = new SettingsPageControl(_csp, shell, fs); var fileName1 = "PropertyGridMultiple02-1.Settings.R"; var file1 = Path.Combine(_files.DestinationPath, fileName1); var fileName2 = "PropertyGridMultiple02-2.Settings.R"; var file2 = Path.Combine(_files.DestinationPath, fileName2); fs.GetFileSystemEntries(Arg.Any <string>(), Arg.Any <string>(), SearchOption.AllDirectories).Returns(new string[] { file1, file2 }); await control.SetProjectAsync(up, _properties); control.CreateControl(); control.FileListCombo.Items.Count.Should().BeGreaterThan(0); control.FileListCombo.Items.Should().Contain("~/" + fileName1); control.FileListCombo.Items.Should().Contain("~/" + fileName2); control.PropertyGrid.SelectedObject.Should().NotBeNull(); var desc = control.PropertyGrid.SelectedObject as SettingsTypeDescriptor; desc.Should().NotBeNull(); desc.GetProperties().Should().HaveCount(1); var prop = desc.GetProperties()[0] as SettingPropertyDescriptor; prop.Should().NotBeNull(); prop.SetValue(null, "42"); prop.Setting.Value.Should().Be("42"); var pg = control.PropertyGrid; var mi = pg.GetType().GetMethod("OnPropertyValueChanged", BindingFlags.Instance | BindingFlags.NonPublic); mi.Invoke(pg, new object[] { new PropertyValueChangedEventArgs(pg.SelectedGridItem, "1") }); control.IsDirty.Should().BeTrue(); var uis = shell.UI(); uis.ShowMessage(Resources.SettingsPage_SavePrompt, MessageButtons.YesNoCancel).Returns(MessageButtons.Yes); control.FileListCombo.SelectedIndex = 1; uis.Received().ShowMessage(Resources.SettingsPage_SavePrompt, MessageButtons.YesNoCancel); control.IsDirty.Should().BeTrue(); // Changing between setting files makes page dirty control.FileListCombo.SelectedIndex.Should().Be(1); }
public async Task DirtyState() { var control = new SettingsPageControl(_csp, _shell, _fs); int count = 0; control.DirtyStateChanged += (s, e) => { count++; }; control.IsDirty = true; control.IsDirty.Should().BeTrue(); count.Should().Be(1); await control.SetProjectAsync(_unconfiguredProject, _properties); (await control.SaveSettingsAsync()).Should().BeTrue(); control.IsDirty.Should().BeFalse(); }
public async Task AddVariable() { var control = new SettingsPageControl(_csp, _shell, _fs); await control.SetProjectAsync(_unconfiguredProject, _properties); control.CreateControl(); control.PropertyGrid.SelectedObject.Should().BeNull(); control.AddButton.Enabled.Should().BeFalse(); control.VariableName.Text = "x"; control.AddButton.Enabled.Should().BeFalse(); control.VariableValue.Text = " "; control.AddButton.Enabled.Should().BeFalse(); control.VariableValue.Text = "1"; control.AddButton.Enabled.Should().BeTrue(); control.VariableName.Text = " "; control.AddButton.Enabled.Should().BeFalse(); control.VariableName.Text = "x"; control.AddButton.Enabled.Should().BeTrue(); control.AddButton.PerformClick(); var desc = control.PropertyGrid.SelectedObject as SettingsTypeDescriptor; desc.Should().NotBeNull(); desc.GetProperties().Should().HaveCount(1); var prop = desc.GetProperties()[0] as SettingPropertyDescriptor; prop.Should().NotBeNull(); prop.Setting.Name.Should().Be("x"); prop.Setting.Value.Should().Be("1"); prop.Setting.ValueType.Should().Be(ConfigurationSettingValueType.String); }