public async void AddMessageAsync_ReturnsHandledAndStopProcessing()
        {
            var reporter = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) => { });
            var project  = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);
            var provider = CreateInstance(project);
            var task     = CreateDefaultTask();

            var result = await provider.AddMessageAsync(task);

            Assert.Equal(result, AddMessageResult.HandledAndStopProcessing);
        }
        public async void AddMessageAsync_CriticalBuildMessageTaskAsTask_PassesTP_LOWAsPriority()
        {
            VSTASKPRIORITY?result   = null;
            var            reporter = IVsLanguageServiceBuildErrorReporter2Factory.ImplementReportError((string bstrErrorMessage, string bstrErrorId, VSTASKPRIORITY nPriority, int iLine, int iColumn, int iEndLine, int iEndColumn, string bstrFileName) => {
                result = nPriority;
            });
            var project  = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);
            var provider = CreateInstance(project);

            await provider.AddMessageAsync(new TargetGeneratedError("Test", new CriticalBuildMessageEventArgs(null, "Code", "File", 1, 1, 1, 1, "Message", "HelpKeyword", "Sender")));

            Assert.Equal(result, VSTASKPRIORITY.TP_LOW);
        }
        public async void ClearAllAsync_WhenProjectWithIntellisense_CallsClearErrors()
        {
            int callCount = 0;
            var reporter  = IVsLanguageServiceBuildErrorReporter2Factory.ImplementClearErrors(() => { callCount++; return(0); });
            var project   = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);
            var task      = CreateDefaultTask();
            var provider  = CreateInstance(project);

            await provider.AddMessageAsync(task);   // Force initialization

            await provider.ClearAllAsync();

            Assert.Equal(1, callCount);
        }
        public async void AddMessageAsync_WhenReporterThrows_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 project  = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);
            var provider = CreateInstance(project);
            var task     = CreateDefaultTask();

            await Assert.ThrowsAsync <Exception>(() => {
                return(provider.AddMessageAsync(task));
            });
        }
        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 project = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);

            var provider = CreateInstance(project);

            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);
        }
        [InlineData(100, 101, 1, 1, 99, 100)]                                                                                  //  Roslyn's ProjectExternalErrorReporter throws if end is less than start
        public async void 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 project = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);

            var provider = CreateInstance(project);
            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 void 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 project = IProjectWithIntellisenseFactory.ImplementGetExternalErrorReporter(reporter);

            var provider = CreateInstance(project);
            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);
        }