public async Task <bool> SaveSettingsAsync() { bool result = true; if (string.IsNullOrEmpty(_viewModel.CurrentFile)) { _viewModel.CreateNewSettingsFile(); PopulateFilesCombo(); } result = await _viewModel.SaveAsync(); if (result) { IsDirty = false; } return(result); }
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 }
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"); }