Пример #1
0
        public async Task AddMessageAsync_WhenHostSpecificErrorReporterThrowsNotImplemented_ReturnsNotHandled()
        {
            var reporter = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) =>
            {
                throw new NotImplementedException();
            });

            var host     = ILanguageServiceHostFactory.ImplementHostSpecificErrorReporter(() => reporter);
            var provider = CreateInstance(host);
            var task     = CreateDefaultTask();

            var result = await provider.AddMessageAsync(task);

            Assert.Equal(AddMessageResult.NotHandled, result);
        }
        public async void AddMessageAsync_WhenHostSpecificErrorReporterThrows_Throws()
        {
            var reporter = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) =>
            {
                throw new Exception();
            });

            var host     = ILanguageServiceHostFactory.ImplementHostSpecificErrorReporter(() => reporter);
            var provider = CreateInstance(host);
            var task     = CreateDefaultTask();

            await Assert.ThrowsAsync <Exception>(() => {
                return(provider.AddMessageAsync(task));
            });
        }
        [InlineData(100, 101, 1, 1, 99, 100)]                                                                                  //  Roslyn's ProjectExternalErrorReporter throws if end is less than start
        public async Task AddMessageAsync_BuildErrorAsTask_CallsReportErrorSettingEndLineAndColumn(int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber, int expectedEndLineNumber, int expectedEndColumnNumber)
        {
            int?endLineResult   = null;
            int?endColumnResult = null;
            var reporter        = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) =>
            {
                endLineResult   = iEndLine;
                endColumnResult = iEndColumn;
            });

            var host = ILanguageServiceHostFactory.ImplementHostSpecificErrorReporter(() => reporter);

            var provider = CreateInstance(host);
            await provider.AddMessageAsync(new TargetGeneratedError("Test", new BuildErrorEventArgs(null, "Code", "File", lineNumber, columnNumber, endLineNumber, endColumnNumber, "ErrorMessage", "HelpKeyword", "Sender")));


            Assert.Equal(expectedEndLineNumber, endLineResult);
            Assert.Equal(expectedEndColumnNumber, endColumnResult);
        }
        public async Task AddMessageAsync_BuildErrorAsTask_CallsReportErrorSettingErrorMessageAndCode(string errorMessage, string code)
        {
            string errorMessageResult = "NotSet";
            string errorIdResult      = "NotSet";
            var    reporter           = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) =>
            {
                errorMessageResult = bstrErrorMessage;
                errorIdResult      = bstrErrorId;
            });

            var host = ILanguageServiceHostFactory.ImplementHostSpecificErrorReporter(() => reporter);

            var provider = CreateInstance(host);
            await provider.AddMessageAsync(new TargetGeneratedError("Test", new BuildErrorEventArgs(null, code, "File", 0, 0, 0, 0, errorMessage, "HelpKeyword", "Sender")));


            Assert.Equal(errorMessage, errorMessageResult);
            Assert.Equal(code, errorIdResult);
        }
Пример #5
0
        public async void AddMessageAsync_BuildErrorAsTask_CallsReportErrorSettingFileName(string file, string projectFile, string expectedFileName)
        {
            string fileNameResult = "NotSet";
            var    reporter       = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) =>
            {
                fileNameResult = bstrFileName;
            });

            var host = ILanguageServiceHostFactory.ImplementHostSpecificErrorReporter(() => reporter);

            var provider = CreateInstance(host);

            var args = new BuildErrorEventArgs(null, "Code", file, 0, 0, 0, 0, "ErrorMessage", "HelpKeyword", "Sender");

            args.ProjectFile = projectFile;
            await provider.AddMessageAsync(new TargetGeneratedError("Test", args));

            Assert.Equal(expectedFileName, fileNameResult);
        }