Exemplo n.º 1
0
        public void TestCheckBox()
        {
            using (var workspace = TestWorkspace.CreateCSharp(""))
            {
                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                var optionStore     = new OptionStore(workspace.Options, Enumerable.Empty <IOption>());
                using (var viewModel = new SpacingViewModel(optionStore, serviceProvider))
                {
                    // Use the first item's preview.
                    var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().First();
                    viewModel.SetOptionAndUpdatePreview(checkbox.IsChecked, checkbox.Option, checkbox.GetPreview());

                    // Get a checkbox and toggle it
                    var originalPreview = GetText(viewModel);

                    checkbox.IsChecked = !checkbox.IsChecked;
                    var modifiedPreview = GetText(viewModel);
                    Assert.NotEqual(modifiedPreview, originalPreview);

                    // Switch it back
                    checkbox.IsChecked = !checkbox.IsChecked;
                    Assert.Equal(originalPreview, viewModel.TextViewHost.TextView.TextBuffer.CurrentSnapshot.GetText().ToString());
                }
            }
        }
Exemplo n.º 2
0
        public void TestOptionLoading()
        {
            using var workspace = TestWorkspace.CreateCSharp("");
            var optionSet   = workspace.Options.WithChangedOption(CSharpFormattingOptions.SpacingAfterMethodDeclarationName, true);
            var optionStore = new OptionStore(optionSet, Enumerable.Empty <IOption>());

            var serviceProvider = new MockServiceProvider(workspace.ExportProvider);

            using var viewModel = new SpacingViewModel(optionStore, serviceProvider);
            // Use the first item's preview.
            var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().Where(c => c.Option == CSharpFormattingOptions.SpacingAfterMethodDeclarationName).First();

            Assert.True(checkbox.IsChecked);
        }
Exemplo n.º 3
0
        public void TestOptionSaving()
        {
            using var workspace = TestWorkspace.CreateCSharp("");
            var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
            var optionStore     = new OptionStore(workspace.Options, Enumerable.Empty <IOption>());

            using var viewModel = new SpacingViewModel(optionStore, serviceProvider);
            // Use the first item's preview.
            var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().Where(c => c.Option == CSharpFormattingOptions.SpacingAfterMethodDeclarationName).First();
            var initial  = checkbox.IsChecked;

            checkbox.IsChecked = !checkbox.IsChecked;

            Assert.NotEqual(optionStore.GetOption(CSharpFormattingOptions.SpacingAfterMethodDeclarationName), initial);
        }
Exemplo n.º 4
0
        public async Task TestOptionLoading()
        {
            using (var workspace = await TestWorkspace.CreateCSharpAsync(""))
            {
                var optionSet = workspace.Options.WithChangedOption(CSharpFormattingOptions.SpacingAfterMethodDeclarationName, true);

                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                using (var viewModel = new SpacingViewModel(optionSet, serviceProvider))
                {
                    // Use the first item's preview.
                    var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().Where(c => c.Option == CSharpFormattingOptions.SpacingAfterMethodDeclarationName).First();
                    Assert.True(checkbox.IsChecked);
                }
            }
        }
Exemplo n.º 5
0
        public void TestOptionLoading()
        {
            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromFile(""))
            {
                var optionService = workspace.GetService <IOptionService>();
                var optionSet     = optionService.GetOptions();
                optionSet = optionSet.WithChangedOption(CSharpFormattingOptions.SpacingAfterMethodDeclarationName, true);

                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                using (var viewModel = new SpacingViewModel(optionSet, serviceProvider))
                {
                    // Use the first item's preview.
                    var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().Where(c => c.Option == CSharpFormattingOptions.SpacingAfterMethodDeclarationName).First();
                    Assert.True(checkbox.IsChecked);
                }
            }
        }
Exemplo n.º 6
0
        public void TestOptionSaving()
        {
            using (var workspace = TestWorkspace.CreateCSharp(""))
            {
                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                using (var viewModel = new SpacingViewModel(workspace.Options, serviceProvider))
                {
                    // Use the first item's preview.
                    var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().Where(c => c.Option == CSharpFormattingOptions.SpacingAfterMethodDeclarationName).First();
                    var initial  = checkbox.IsChecked;
                    checkbox.IsChecked = !checkbox.IsChecked;

                    var changedOptions = viewModel.ApplyChangedOptions(workspace.Options);
                    Assert.NotEqual(changedOptions.GetOption(CSharpFormattingOptions.SpacingAfterMethodDeclarationName), initial);
                }
            }
        }
Exemplo n.º 7
0
        public async Task TestFeatureBasedSaving()
        {
            using (var workspace = await TestWorkspace.CreateCSharpAsync(""))
            {
                // Set an option for an unrelated feature
                var optionService = workspace.GetService <IOptionService>();
                var optionSet     = optionService.GetOptions();
                var expectedValue = !CSharpFormattingOptions.NewLineForCatch.DefaultValue;
                optionSet = optionSet.WithChangedOption(CSharpFormattingOptions.NewLineForCatch, expectedValue);
                optionService.SetOptions(optionSet);

                // Save the options
                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                using (var viewModel = new SpacingViewModel(workspace.Options, serviceProvider))
                {
                    var changedOptions = optionService.GetOptions();
                    Assert.Equal(changedOptions.GetOption(CSharpFormattingOptions.NewLineForCatch), expectedValue);
                }
            }
        }
Exemplo n.º 8
0
        public async Task TestOptionSaving()
        {
            using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(""))
            {
                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                using (var viewModel = new SpacingViewModel(workspace.Options, serviceProvider))
                {
                    // Use the first item's preview.
                    var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().Where(c => c.Option == CSharpFormattingOptions.SpacingAfterMethodDeclarationName).First();
                    var initial  = checkbox.IsChecked;
                    checkbox.IsChecked = !checkbox.IsChecked;

                    var optionService = workspace.GetService <IOptionService>();
                    var optionSet     = optionService.GetOptions();

                    var changedOptions = viewModel.ApplyChangedOptions(optionSet);
                    Assert.NotEqual(changedOptions.GetOption(CSharpFormattingOptions.SpacingAfterMethodDeclarationName), initial);
                }
            }
        }
Exemplo n.º 9
0
        public async Task TestCheckBox()
        {
            using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(""))
            {
                var serviceProvider = new MockServiceProvider(workspace.ExportProvider);
                using (var viewModel = new SpacingViewModel(workspace.Options, serviceProvider))
                {
                    // Use the first item's preview.
                    var checkbox = viewModel.Items.OfType <CheckBoxOptionViewModel>().First();
                    viewModel.SetOptionAndUpdatePreview(checkbox.IsChecked, checkbox.Option, checkbox.GetPreview());

                    // Get a checkbox and toggle it
                    var originalPreview = GetText(viewModel);

                    checkbox.IsChecked = !checkbox.IsChecked;
                    var modifiedPreview = GetText(viewModel);
                    Assert.NotEqual(modifiedPreview, originalPreview);

                    // Switch it back
                    checkbox.IsChecked = !checkbox.IsChecked;
                    Assert.Equal(originalPreview, viewModel.TextViewHost.TextView.TextBuffer.CurrentSnapshot.GetText().ToString());
                }
            }
        }