Exemple #1
0
        public void ConsoleTextOfLineNoMarker()
        {
            string testString = "Test";

            using (OleServiceProvider provider = new OleServiceProvider())
            {
                BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance();
                textLinesMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText"),
                    new EventHandler <CallbackArgs>(GetLineTextCallbackForConsoleTextOfLine));
                textLinesMock["LineText"]      = testString;
                textLinesMock["ExpectedLine"]  = 1;
                textLinesMock["ExpectedStart"] = 0;
                textLinesMock["ExpectedEnd"]   = 10;

                // Create a new local registry class.
                LocalRegistryMock mockRegistry = new LocalRegistryMock();
                // Add the text buffer to the list of the classes that local registry can create.
                mockRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Add the local registry to the service provider.
                provider.AddService(typeof(SLocalRegistry), mockRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    IConsoleText consoleText = windowPane as IConsoleText;
                    Assert.IsNull(consoleText.TextOfLine(1, -1, true));
                    Assert.IsNull(consoleText.TextOfLine(1, -1, false));
                    string text = consoleText.TextOfLine(1, 10, false);
                    Assert.IsTrue(testString == text);
                }
            }
        }
        public void GetDeclarationsNullText()
        {
            // Create a mock IConsoleText that will return null on TextOfLine.
            IConsoleText consoleText = MockFactories.ConsoleTextFactory.GetInstance() as IConsoleText;

            ConsoleAuthoringScope.PythonConsole = consoleText;

            // Create the authoring scope.
            ParseRequest request = new ParseRequest(false);

            request.Reason = ParseReason.DisplayMemberList;
            AuthoringScope scope = ConsoleAuthoringScope.CreateScope(request);

            Assert.IsNotNull(scope);

            // Create object with not null value for the parameters.
            IVsTextView view      = MockFactories.TextViewFactory.GetInstance() as IVsTextView;
            TokenInfo   tokenInfo = new TokenInfo();

            // Call GetDeclarations.
            Declarations declarations = scope.GetDeclarations(view, 0, 0, tokenInfo, ParseReason.DisplayMemberList);

            Assert.IsTrue(0 == declarations.GetCount());
        }
 public Caller(IConsoleText consoleText)
 {
     this.consoleText = consoleText;
 }
 public Caller(IConsoleText consoleText)
 {
     this.consoleText = consoleText;
 }
Exemple #5
0
        public void ConsoleTextOfLineWithMarker()
        {
            string testString1 = "Test 1";
            string testString2 = "Test 2";

            using (OleServiceProvider provider = new OleServiceProvider())
            {
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();
                textLinesMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText"),
                    new EventHandler <CallbackArgs>(GetLineTextCallbackForConsoleTextOfLine));

                // Create a new local registry class.
                LocalRegistryMock mockRegistry = new LocalRegistryMock();
                // Add the text buffer to the list of the classes that local registry can create.
                mockRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Add the local registry to the service provider.
                provider.AddService(typeof(SLocalRegistry), mockRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // Set the span of the marker.
                    TextSpan span = new TextSpan();
                    span.iStartLine  = 0;
                    span.iStartIndex = 0;
                    span.iEndLine    = 3;
                    span.iEndIndex   = 5;
                    BaseMock markerMock = (BaseMock)textLinesMock["LineMarker"];
                    markerMock["Span"] = span;

                    IConsoleText consoleText = windowPane as IConsoleText;

                    // Verify the case that the requested line is all inside the
                    // read only region.
                    textLinesMock["LineText"]      = testString1;
                    textLinesMock["ExpectedLine"]  = 1;
                    textLinesMock["ExpectedStart"] = 0;
                    textLinesMock["ExpectedEnd"]   = 10;
                    Assert.IsNull(consoleText.TextOfLine(1, 10, true));
                    string text = consoleText.TextOfLine(1, 10, false);
                    Assert.IsTrue(text == testString1);

                    // Now ask for some text inside the read-only region, but on its last line.
                    textLinesMock["LineText"]      = testString2;
                    textLinesMock["ExpectedLine"]  = 3;
                    textLinesMock["ExpectedStart"] = 0;
                    textLinesMock["ExpectedEnd"]   = 4;
                    Assert.IsNull(consoleText.TextOfLine(3, 4, true));
                    text = consoleText.TextOfLine(3, 4, false);
                    Assert.IsTrue(text == testString2);

                    // Now the text is part inside and part outside the read-only region.
                    textLinesMock["LineText"]      = testString1;
                    textLinesMock["ExpectedLine"]  = 3;
                    textLinesMock["ExpectedStart"] = 5;
                    textLinesMock["ExpectedEnd"]   = 10;
                    text = consoleText.TextOfLine(3, 10, true);
                    Assert.IsTrue(testString1 == text);
                    textLinesMock["LineText"]      = testString2;
                    textLinesMock["ExpectedLine"]  = 3;
                    textLinesMock["ExpectedStart"] = 0;
                    textLinesMock["ExpectedEnd"]   = 10;
                    text = consoleText.TextOfLine(3, 10, false);
                    Assert.IsTrue(text == testString2);

                    // Now the line has no intersection with the read-only region.
                    textLinesMock["LineText"]      = testString1;
                    textLinesMock["ExpectedLine"]  = 4;
                    textLinesMock["ExpectedStart"] = 0;
                    textLinesMock["ExpectedEnd"]   = 10;
                    text = consoleText.TextOfLine(4, 10, true);
                    Assert.IsTrue(testString1 == text);
                    textLinesMock["LineText"]      = testString2;
                    textLinesMock["ExpectedLine"]  = 4;
                    textLinesMock["ExpectedStart"] = 0;
                    textLinesMock["ExpectedEnd"]   = 10;
                    text = consoleText.TextOfLine(4, 10, false);
                    Assert.IsTrue(text == testString2);
                }
            }
        }