コード例 #1
0
        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
        }
コード例 #2
0
        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");
        }