コード例 #1
0
        private void ConfigureSettingAccessMock(IEnumerable <IConfigurationSetting> settings)
        {
            var confProj = Substitute.For <ConfiguredProject>();
            var unconf   = Substitute.For <UnconfiguredProject>();

            unconf.LoadedConfiguredProjects.Returns((IEnumerable <ConfiguredProject>) new ConfiguredProject[] { confProj });
            var browseContext = Substitute.For <IVsBrowseObjectContext>();

            browseContext.UnconfiguredProject.Returns(unconf);

            var dteProj = Substitute.For <EnvDTE.Project>();

            dteProj.Object.Returns(browseContext);

            var access = Substitute.For <IProjectConfigurationSettingsAccess>();
            var coll   = new ConfigurationSettingCollection();

            foreach (var s in settings)
            {
                coll.Add(s);
            }
            access.Settings.Returns(coll);
            _pcsp.OpenProjectSettingsAccessAsync(confProj).Returns(Task.FromResult(access));

            object ext;
            var    hier = Substitute.For <IVsHierarchy>();

            hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out ext).Returns((c) => {
                c[2] = dteProj;
                return(VSConstants.S_OK);
            });
            _pss.GetSelectedProject <IVsHierarchy>().Returns(hier);
        }
コード例 #2
0
        public void Test01() {
            string file = Path.GetTempFileName();
            var content = "x <- 1";

            var coll = new ConfigurationSettingCollection();
            coll.Save(file);

            var fi = new FileInfo(file);
            fi.Length.Should().Be(0);

            try {
                using (var sw = new StreamWriter(file)) {
                    sw.Write(content);
                }

                coll.Load(file);
                coll.GetSetting("foo").Should().BeNull();

                var setting = coll.GetSetting("x");
                setting.Should().NotBeNull();
                setting.Name.Should().Be("x");
                setting.Value.Should().Be("1");
                setting.ValueType.Should().Be(ConfigurationSettingValueType.Expression);

            } finally {
                if (File.Exists(file)) {
                    File.Delete(file);
                }
            }
        }
コード例 #3
0
        public void Test01()
        {
            string file    = Path.GetTempFileName();
            var    content = "x <- 1";

            var coll = new ConfigurationSettingCollection();

            coll.Save(file);

            var fi = new FileInfo(file);

            fi.Length.Should().Be(0);

            try {
                using (var sw = new StreamWriter(file)) {
                    sw.Write(content);
                }

                coll.Load(file);
                coll.GetSetting("foo").Should().BeNull();

                var setting = coll.GetSetting("x");
                setting.Should().NotBeNull();
                setting.Name.Should().Be("x");
                setting.Value.Should().Be("1");
                setting.ValueType.Should().Be(ConfigurationSettingValueType.Expression);
            } finally {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
コード例 #4
0
ファイル: CommandTest.cs プロジェクト: Microsoft/RTVS
        public void AddDbConnectionCommand() {
            var coll = new ConfigurationSettingCollection();
            coll.Add(new ConfigurationSetting("dbConnection1", "1", ConfigurationSettingValueType.String));
            coll.Add(new ConfigurationSetting("dbConnection2", "1", ConfigurationSettingValueType.String));
            coll.Add(new ConfigurationSetting("dbConnection4", "1", ConfigurationSettingValueType.String));

            var configuredProject = Substitute.For<ConfiguredProject>();
            var ac = Substitute.For<IProjectConfigurationSettingsAccess>();
            ac.Settings.Returns(coll);
            var csp = Substitute.For<IProjectConfigurationSettingsProvider>();
            csp.OpenProjectSettingsAccessAsync(configuredProject).Returns(ac);

            var properties = new ProjectProperties(Substitute.For<ConfiguredProject>());
            var dbcs = Substitute.For<IDbConnectionService>();
            dbcs.EditConnectionString(null).Returns("DSN");

            var session = Substitute.For<IRSession>();
            session.EvaluateAsync(null, REvaluationKind.NoResult).ReturnsForAnyArgs(Task.FromResult(new REvaluationResult()));
            session.IsHostRunning.Returns(true);
            var operations = Substitute.For<IRInteractiveWorkflowOperations>();

            var workflow = Substitute.For<IRInteractiveWorkflow>();
            workflow.RSession.Returns(session);
            workflow.Operations.Returns(operations);

            var ucp = Substitute.For<UnconfiguredProject>();
            ucp.LoadedConfiguredProjects.Returns(new ConfiguredProject[] { configuredProject });
            var vsbc = Substitute.For<IVsBrowseObjectContext>();
            vsbc.UnconfiguredProject.Returns(ucp); // IVsBrowseObjectContext.ConfiguredProject

            var dteProj = Substitute.For<EnvDTE.Project>();
            dteProj.Object.Returns(vsbc); // dteProject?.Object as IVsBrowseObjectContext

            object extObject;
            var hier = Substitute.For<IVsHierarchy>();
            hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject)
                .Returns(x => {
                    x[2] = dteProj;
                    return VSConstants.S_OK;
                });

            var pss = Substitute.For<IProjectSystemServices>();
            pss.GetSelectedProject<IVsHierarchy>().Returns(hier);

            var cmd = new AddDbConnectionCommand(dbcs, pss, csp, workflow);
            cmd.Enabled.Should().BeTrue();
            cmd.Invoke(null, IntPtr.Zero, OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT);

            coll.Should().HaveCount(4);
            var s = coll.GetSetting("dbConnection3");
            s.Value.Should().Be("DSN");
            s.ValueType.Should().Be(ConfigurationSettingValueType.String);
            s.Category.Should().Be(ConnectionStringEditor.ConnectionStringEditorCategory);
            s.EditorType.Should().Be(ConnectionStringEditor.ConnectionStringEditorName);
            s.Description.Should().Be(Resources.ConnectionStringDescription);

            var expected = "if (!exists('settings')) { settings <- as.environment(list()); }; if (is.environment(settings)) { settings$dbConnection3 = \"DSN\"; }";
            operations.Received(1).EnqueueExpression(expected, true);
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        private async Task <ConfigurationSettingCollection> OpenCollectionAsync(string projectFolder, IRProjectProperties properties)
        {
            var settings         = new ConfigurationSettingCollection();
            var settingsFilePath = await GetSettingsFilePathAsync(projectFolder, properties);

            if (!string.IsNullOrEmpty(settingsFilePath))
            {
                settings.Load(settingsFilePath.MakeAbsolutePathFromRRelative(projectFolder));
            }
            return(settings);
        }
コード例 #7
0
        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");
        }
コード例 #8
0
            public SettingsAccess(ProjectConfigurationSettingsProvider provider, IThreadHandling threadHandling,
                                  string projectPath, IRProjectProperties propertes, ConfigurationSettingCollection settings)
            {
                _provider       = provider;
                _threadHandling = threadHandling;
                _projectPath    = projectPath;
                _properties     = propertes;

                _counter = new CountdownDisposable(Release);

                Settings = settings;
                Settings.CollectionChanged += OnCollectionChanged;
            }
コード例 #9
0
 public ActionResult Save(Bam.Net.CoreServices.ApplicationRegistration.Data.Dao.ConfigurationSetting[] values)
 {
     try
     {
         ConfigurationSettingCollection saver = new ConfigurationSettingCollection();
         saver.AddRange(values);
         saver.Save();
         return(Json(new { Success = true, Message = "", Dao = "" }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
コード例 #10
0
        public async Task ConcurrentAccess()
        {
            string folder = Path.Combine(_files.DestinationPath, "ConcurrentAccess");

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            string projFile = Path.Combine(folder, "file.rproj");
            var    up       = Substitute.For <UnconfiguredProject>();

            up.FullPath.Returns(projFile);

            var props = Substitute.For <IRProjectProperties>();
            var p     = new ProjectConfigurationSettingsProvider();

            var s1 = new ConfigurationSetting("s1", "1", ConfigurationSettingValueType.String);
            var s2 = new ConfigurationSetting("s2", "2", ConfigurationSettingValueType.String);

            using (var access1 = await p.OpenProjectSettingsAccessAsync(up, props)) {
                access1.Settings.Should().NotBeNull();
                access1.Settings.Should().BeEmpty();

                using (var access2 = await p.OpenProjectSettingsAccessAsync(up, props)) {
                    access2.Settings.Should().NotBeNull();
                    access2.Settings.Add(s1);
                    access1.Settings.Count.Should().Be(1);
                }

                access1.Settings.Add(s2);
                access1.Settings.Count.Should().Be(2);
            }

            var settingsFile = Path.Combine(folder, "Settings.R");

            File.Exists(settingsFile).Should().BeTrue();

            var c = new ConfigurationSettingCollection();

            c.Load(settingsFile);

            c.Count.Should().Be(2);
            c.GetSetting("s1").Value.Should().Be("1");
            c.GetSetting("s2").Value.Should().Be("2");

            File.Delete(settingsFile);
        }
コード例 #11
0
ファイル: SettingsTest.cs プロジェクト: Microsoft/RTVS
        public async Task ConcurrentAccess() {
            string folder = Path.Combine(_files.DestinationPath, "ConcurrentAccess");
            if(!Directory.Exists(folder)) {
                Directory.CreateDirectory(folder);
            }
            string projFile = Path.Combine(folder, "file.rproj");
            var up = Substitute.For<UnconfiguredProject>();
            up.FullPath.Returns(projFile);

            var props = Substitute.For<IRProjectProperties>();
            var p = new ProjectConfigurationSettingsProvider();

            var s1 = new ConfigurationSetting("s1", "1", ConfigurationSettingValueType.String);
            var s2 = new ConfigurationSetting("s2", "2", ConfigurationSettingValueType.String);

            using (var access1 = await p.OpenProjectSettingsAccessAsync(up, props)) {
                access1.Settings.Should().NotBeNull();
                access1.Settings.Should().BeEmpty();

                using (var access2 = await p.OpenProjectSettingsAccessAsync(up, props)) {
                    access2.Settings.Should().NotBeNull();
                    access2.Settings.Add(s1);
                    access1.Settings.Count.Should().Be(1);
                }

                access1.Settings.Add(s2);
                access1.Settings.Count.Should().Be(2);
            }

            var settingsFile = Path.Combine(folder, "Settings.R");
            File.Exists(settingsFile).Should().BeTrue();

            var c = new ConfigurationSettingCollection();
            c.Load(settingsFile);

            c.Count.Should().Be(2);
            c.GetSetting("s1").Value.Should().Be("1");
            c.GetSetting("s2").Value.Should().Be("2");

            File.Delete(settingsFile);
        }
コード例 #12
0
        private void ConfigureSettingAccessMock(IEnumerable<IConfigurationSetting> settings) {

            var confProj = Substitute.For<ConfiguredProject>();
            var unconf = Substitute.For<UnconfiguredProject>();
            unconf.LoadedConfiguredProjects.Returns((IEnumerable<ConfiguredProject>)new ConfiguredProject[] { confProj });
            var browseContext = Substitute.For<IVsBrowseObjectContext>();
            browseContext.UnconfiguredProject.Returns(unconf);

            var dteProj = Substitute.For<EnvDTE.Project>();
            dteProj.Object.Returns(browseContext);

            var access = Substitute.For<IProjectConfigurationSettingsAccess>();
            var coll = new ConfigurationSettingCollection();
            foreach (var s in settings) {
                coll.Add(s);
            }
            access.Settings.Returns(coll);
            _pcsp.OpenProjectSettingsAccessAsync(confProj).Returns(Task.FromResult(access));

            object ext;
            var hier = Substitute.For<IVsHierarchy>();
            hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out ext).Returns((c) => {
                c[2] = dteProj;
                return VSConstants.S_OK;
            });
            _pss.GetSelectedProject<IVsHierarchy>().Returns(hier);

            _coreShell.When(cs => cs.DispatchOnUIThread(Arg.Any<Action>())).Do(c => {
                var action = (Action)c.Args()[0];
                action();
            });
        }
コード例 #13
0
ファイル: CommandTest.cs プロジェクト: ktaranov/RTVS
        public void AddDbConnectionCommand()
        {
            var coll = new ConfigurationSettingCollection();

            coll.Add(new ConfigurationSetting("dbConnection1", "1", ConfigurationSettingValueType.String));
            coll.Add(new ConfigurationSetting("dbConnection2", "1", ConfigurationSettingValueType.String));
            coll.Add(new ConfigurationSetting("dbConnection4", "1", ConfigurationSettingValueType.String));

            var configuredProject = Substitute.For <ConfiguredProject>();
            var ac = Substitute.For <IProjectConfigurationSettingsAccess>();

            ac.Settings.Returns(coll);
            var csp = Substitute.For <IProjectConfigurationSettingsProvider>();

            csp.OpenProjectSettingsAccessAsync(configuredProject).Returns(ac);

            var properties = new ProjectProperties(Substitute.For <ConfiguredProject>());
            var dbcs       = Substitute.For <IDbConnectionService>();

            dbcs.EditConnectionString(null).Returns("DSN");

            var session = Substitute.For <IRSession>();

            session.EvaluateAsync(null, REvaluationKind.NoResult).ReturnsForAnyArgs(Task.FromResult(new REvaluationResult()));
            session.IsHostRunning.Returns(true);
            var operations = Substitute.For <IRInteractiveWorkflowOperations>();

            var workflow = Substitute.For <IRInteractiveWorkflow>();

            workflow.RSession.Returns(session);
            workflow.Operations.Returns(operations);

            var ucp = Substitute.For <UnconfiguredProject>();

            ucp.LoadedConfiguredProjects.Returns(new ConfiguredProject[] { configuredProject });
            var vsbc = Substitute.For <IVsBrowseObjectContext>();

            vsbc.UnconfiguredProject.Returns(ucp); // IVsBrowseObjectContext.ConfiguredProject

            var dteProj = Substitute.For <EnvDTE.Project>();

            dteProj.Object.Returns(vsbc); // dteProject?.Object as IVsBrowseObjectContext

            object extObject;
            var    hier = Substitute.For <IVsHierarchy>();

            hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject)
            .Returns(x => {
                x[2] = dteProj;
                return(VSConstants.S_OK);
            });

            var pss = Substitute.For <IProjectSystemServices>();

            pss.GetSelectedProject <IVsHierarchy>().Returns(hier);

            var cmd = new AddDbConnectionCommand(dbcs, pss, csp, workflow);

            cmd.Enabled.Should().BeTrue();
            cmd.Invoke(null, IntPtr.Zero, OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT);

            coll.Should().HaveCount(4);
            var s = coll.GetSetting("dbConnection3");

            s.Value.Should().Be("DSN");
            s.ValueType.Should().Be(ConfigurationSettingValueType.String);
            s.Category.Should().Be(ConnectionStringEditor.ConnectionStringEditorCategory);
            s.EditorType.Should().Be(ConnectionStringEditor.ConnectionStringEditorName);
            s.Description.Should().Be(Resources.ConnectionStringDescription);

            operations.Received(1).EnqueueExpression(Invariant($"dbConnection3 <- 'DSN'"), true);
        }