public async Task CreateNewFile() {
            var css = new ConfigurationSettingCollection();
            var shell = Substitute.For<ICoreShell>();
            var fs = Substitute.For<IFileSystem>();

            var model = new SettingsPageViewModel(css, shell, fs);
            string file = Path.GetTempFileName();
            await model.SetProjectPathAsync("C:\\", null);
            model.CreateNewSettingsFile();
            model.CurrentFile.Should().Be("~/Settings.R");
        }
Beispiel #2
0
        public async Task SetProjectAsync(UnconfiguredProject project, IRProjectProperties properties) {
            if(_access != null) {
                throw new InvalidOperationException("Project is already set");
            }
            _access = await _settingsProvider.OpenProjectSettingsAccessAsync(project, properties);
            _viewModel = new SettingsPageViewModel(_access.Settings, _appShell, _fs);
            await _viewModel.SetProjectPathAsync(Path.GetDirectoryName(project.FullPath), properties);

            PopulateFilesCombo();
            LoadPropertyGrid();

            _access.Settings.CollectionChanged += OnSettingsCollectionChanged;
        }
        public async Task EmptyViewModel() {
            var css = Substitute.For<IConfigurationSettingCollection>();
            var shell = Substitute.For<ICoreShell>();

            string file = Path.GetTempFileName();
            var fs = Substitute.For<IFileSystem>();
            fs.GetFileSystemEntries(file, Arg.Any<string>(), SearchOption.AllDirectories).Returns(new string[] { file });
            fs.DirectoryExists(file).Returns(false);
            fs.FileExists(file).Returns(true);

            var model = new SettingsPageViewModel(css, shell, fs);
            await model.SetProjectPathAsync(Path.GetDirectoryName(file), null);
            model.CurrentFile.Should().BeNull();
            (await model.SaveAsync()).Should().BeFalse(); // nothing should happen
        }
Beispiel #4
0
        public async Task SetProjectAsync(UnconfiguredProject project, IRProjectProperties properties)
        {
            if (_access != null)
            {
                throw new InvalidOperationException("Project is already set");
            }
            _access = await _settingsProvider.OpenProjectSettingsAccessAsync(project, properties);

            _viewModel = new SettingsPageViewModel(_access.Settings, _shell, _fs);
            await _viewModel.SetProjectPathAsync(Path.GetDirectoryName(project.FullPath), properties);

            PopulateFilesCombo();
            LoadPropertyGrid();

            _access.Settings.CollectionChanged += OnSettingsCollectionChanged;
        }
        public async Task LoadSave() {
            var settings = Substitute.For<IConfigurationSettingCollection>();
            var shell = Substitute.For<ICoreShell>();
            var fs = Substitute.For<IFileSystem>();
            var pp = Substitute.For<IRProjectProperties>();
            fs.GetFileSystemEntries(null, null, SearchOption.AllDirectories).ReturnsForAnyArgs(new string[] { @"C:\Settings22.R" });
            pp.GetSettingsFileAsync().Returns(Task.FromResult("~/Settings22.R"));

            var model = new SettingsPageViewModel(settings, shell, fs);
            await model.SetProjectPathAsync(@"C:\", pp);
            await pp.Received().GetSettingsFileAsync();
            model.CurrentFile.Should().Be("~/Settings22.R");

            (await model.SaveAsync()).Should().BeTrue();
            settings.Received().Save(@"C:\Settings22.R");
        }
        public async Task EnumerateFiles() {
            var css = Substitute.For<IConfigurationSettingCollection>();
            var shell = Substitute.For<ICoreShell>();

            string folder = @"C:\";
            string file1 = @"C:\Settings.R";
            string file2 = @"C:\Debug.Settings.R";
            string file3 = @"C:\foo.bar";
            var fs = Substitute.For<IFileSystem>();
            fs.GetFileSystemEntries(folder, Arg.Any<string>(), SearchOption.AllDirectories).Returns(new string[] { file1, file2, file3 });
            fs.DirectoryExists(Arg.Any<string>()).Returns(false);
            fs.FileExists(file1).Returns(true);
            fs.FileExists(file2).Returns(true);
            fs.FileExists(file3).Returns(true);

            var model = new SettingsPageViewModel(css, shell, fs);
            await model.SetProjectPathAsync(folder, null);
            model.CurrentFile.Should().Be("~/Settings.R");
            model.Files.Should().HaveCount(2);
            model.Files.ToArray()[0].Should().Be("~/Settings.R");
            model.Files.ToArray()[1].Should().Be("~/Debug.Settings.R");
        }