public async Task SourceRScriptTest(bool echo, string encoding) { await _workflow.RSessions.TrySwitchBrokerAsync(nameof(RInteractiveWorkflowCommandTest)); await _workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo( cranMirrorName : _settings.CranMirror, codePage : _settings.RCodePage ), null, 50000); var session = _workflow.RSession; await session.ExecuteAsync("sourced <- FALSE"); var tracker = Substitute.For <IActiveWpfTextViewTracker>(); tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns((IWpfTextView)null); var command = new SourceRScriptCommand(_workflow, tracker, echo); command.Should().BeSupported() .And.BeInvisibleAndDisabled(); using (await _workflow.GetOrCreateVisualComponentAsync()) { const string code = "sourced <- TRUE"; var textBuffer = new TextBufferMock(code, RContentTypeDefinition.ContentType); var textView = new WpfTextViewMock(textBuffer); tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns(textView); tracker.LastActiveTextView.Returns(textView); command.Should().BeSupported() .And.BeVisibleAndDisabled(); using (var sf = new SourceFile(code)) { var document = new TextDocumentMock(textBuffer, sf.FilePath) { Encoding = Encoding.GetEncoding(encoding) }; textBuffer.Properties[typeof(ITextDocument)] = document; command.Should().BeSupported() .And.BeVisibleAndEnabled(); var mutatedTask = EventTaskSources.IRSession.Mutated.Create(session); await command.InvokeAsync().Should().BeCompletedAsync(); await mutatedTask.Should().BeCompletedAsync(); (await session.EvaluateAsync <bool>("sourced", REvaluationKind.Normal)).Should().BeTrue(); } } }
public async Task SourceRScriptTest(bool echo, string encoding) { var session = _workflow.RSession; await session.ExecuteAsync("sourced <- FALSE"); var tracker = Substitute.For <IActiveWpfTextViewTracker>(); tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns((IWpfTextView)null); var command = new SourceRScriptCommand(_workflow, tracker, echo); command.Should().BeSupported() .And.BeInvisibleAndDisabled(); using (await _workflow.GetOrCreateVisualComponent(_componentContainerFactory)) { command.Should().BeSupported() .And.BeVisibleAndDisabled(); const string code = "sourced <- TRUE"; var textBuffer = new TextBufferMock(code, RContentTypeDefinition.ContentType); var textView = new WpfTextViewMock(textBuffer); tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns(textView); command.Should().BeSupported() .And.BeVisibleAndDisabled(); using (var sf = new SourceFile(code)) { var document = new TextDocumentMock(textBuffer, sf.FilePath) { Encoding = Encoding.GetEncoding(encoding) }; textBuffer.Properties[typeof(ITextDocument)] = document; command.Should().BeSupported() .And.BeVisibleAndEnabled(); var mutatedTask = EventTaskSources.IRSession.Mutated.Create(session); await command.InvokeAsync(); await mutatedTask; (await session.EvaluateAsync <bool>("sourced", REvaluationKind.Normal)).Should().BeTrue(); } } }