public IRSession GetOrCreate(Guid guid, IRHostClientApp hostClientApp) {
     IRSession session;
     if (!_sessions.TryGetValue(guid, out session)) {
         session = new RSessionMock();
         _sessions[guid] = session;
     }
     return session;
 }
Пример #2
0
        public void SetDirectoryToProjectTest() {
            var session = new RSessionMock();
            session.IsHostRunning = true;

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

            var pss = Substitute.For<IProjectSystemServices>();
            pss.GetSelectedProject<IVsProject>().Returns((IVsProject)null);
            pss.GetActiveProject().Returns((EnvDTE.Project)null);

            var cmd = new SetDirectoryToProjectCommand(workflow, pss);
            var status = cmd.OleStatus;
            cmd.Enabled.Should().BeFalse();
            cmd.Supported.Should().BeTrue();

            var proj = Substitute.For<IVsProject>();
            string value;
            proj
                .GetMkDocument((uint)VSConstants.VSITEMID.Root, out value)
                .Returns(x => {
                    x[1] = @"c:\dir1\dir2\file.rproj";
                    return VSConstants.S_OK;
                });

            pss = Substitute.For<IProjectSystemServices>();
            pss.GetSelectedProject<IVsProject>().Returns(proj);

            var proj2 = Substitute.For<EnvDTE.Project>();
            pss.GetActiveProject().Returns(proj2);

            cmd = new SetDirectoryToProjectCommand(workflow, pss);
            status = cmd.OleStatus;
            cmd.Enabled.Should().BeTrue();
            cmd.Supported.Should().BeTrue();
            cmd.Invoke();

            session.LastExpression.Should().Be("setwd('c:/dir1/dir2')\n");
        }
Пример #3
0
        public void SetDirectoryToSourceTest() {
            var session = new RSessionMock();
            var workflow = Substitute.For<IRInteractiveWorkflow>();
            workflow.RSession.Returns(session);

            var document = Substitute.For<ITextDocument>();
            document.FilePath.Returns(@"c:\dir1\dir2\file.r");

            var tb = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
            tb.Properties.AddProperty(typeof(ITextDocument), document);

            var tracker = Substitute.For<IActiveWpfTextViewTracker>();
            tracker.LastActiveTextView.Returns((IWpfTextView)null);

            var cmd = new SetDirectoryToSourceCommand(workflow, tracker);
            var status = cmd.OleStatus;
            cmd.Enabled.Should().BeFalse();
            cmd.Supported.Should().BeTrue();

            tracker = Substitute.For<IActiveWpfTextViewTracker>();
            tracker.LastActiveTextView.Returns(new WpfTextViewMock(tb));

            cmd = new SetDirectoryToSourceCommand(workflow, tracker);
            status = cmd.OleStatus;
            cmd.Enabled.Should().BeFalse();

            session.IsHostRunning = true;
            status = cmd.OleStatus;
            cmd.Enabled.Should().BeTrue();

            cmd.Invoke();
            session.LastExpression.Should().Be("setwd('c:/dir1/dir2')\n");

            session.IsRemote = true;
            status = cmd.OleStatus;
            cmd.Enabled.Should().BeFalse();
        }