public void DotWaitAndDotResultAreNeverUsed() { //TODO: We should use Roslyn to do this //What this expression means: //(?<!//.*?) -- Make sure that any await we find is not preceeded on the same line by // //(?s: -- means . will match newlines in this sub-expression. //\\.Wait\\(\\) -- matches .Wait() //(?<!this\\.?)\\.Result(\\.|;|\\s|,) -- matches .Result followed by a ., ;, whitespace, or , which is not prefixed immediately by "this." const string pattern = "(?<!//.*?)(?s:(\\.Wait\\(\\)|(?<!this\\.?)\\.Result(\\.|;|\\s|,)))"; SourceParser sourceParser = new SourceParser(this.sourceLocation, SourceFileType, null, pattern); List <SourceParserResult> results = sourceParser.Parse().ToList(); //There should be no .Result or .Wait() calls outside of the two which are expected below //Remove the two we expect results.Remove(results.First(r => r.File.Contains("UtilitiesInternal.cs"))); results.Remove(results.First(r => r.File.Contains("SynchronousMethodExceptionBehavior.cs"))); foreach (SourceParserResult parserResult in results) { this.testOutputHelper.WriteLine("Found .Wait or .Result in {0} at {1} -- {2}", parserResult.File, parserResult.LineNumber, parserResult.Match); } Assert.Equal(0, results.Count); }
public void ExceptionsThrownDirectlyByObjectModelDontChange() { const string exceptionNameCaptureGroup = "ExceptionName"; string pattern = GetExceptionCaptureRegex(exceptionNameCaptureGroup); SourceParser sourceParser = new SourceParser(this.sourceLocation, SourceFileType, GeneratedProtocolFolder, pattern); List <SourceParserResult> results = sourceParser.Parse().ToList(); //Ensure we've scanned at least some files... const int expectedExceptionCount = 50; this.testOutputHelper.WriteLine("Found {0} \"throw new Exception\" strings", results.Count); Assert.True(results.Count > expectedExceptionCount); HashSet <string> exceptionSet = new HashSet <string>(); foreach (SourceParserResult parserResult in results) { string exceptionName = parserResult.Match.Groups[exceptionNameCaptureGroup].Value; exceptionSet.Add(exceptionName); } this.testOutputHelper.WriteLine("Found {0} types of exception thrown by object model", exceptionSet.Count); this.testOutputHelper.WriteLine("Exceptions:"); this.testOutputHelper.WriteLine("------------------------"); foreach (string exceptionType in exceptionSet) { this.testOutputHelper.WriteLine("{0}", exceptionType); } var expectedExceptions = new HashSet <string> { "ArgumentNullException", "AddTaskCollectionTerminatedException", "BatchClientException", "RunOnceException", "TimeoutException", "ArgumentOutOfRangeException", "InvalidOperationException", "ArgumentException", "FileNotFoundException", "ParallelOperationsException", }; Assert.Equal(expectedExceptions.OrderBy(e => e), exceptionSet.OrderBy(e => e)); }
public async Task <List <ISourceVacancy> > Load() { if (SourceParser == null) { throw new Exception("Не определен адаптер для разбора данных с ресурса."); } if (Url == null) { throw new Exception("Не определен адрес ресурса ресурса."); } var htmlText = await GetSourcHtmlText(); var results = SourceParser.Parse(htmlText); return(await Task.FromResult(results)); }
public void ExceptionsThrownDirectlyByRestProxyDontChange() { const string exceptionNameCaptureGroup = "ExceptionName"; string pattern = GetExceptionCaptureRegex(exceptionNameCaptureGroup); SourceParser sourceParser = new SourceParser(this.proxySourceLocation, SourceFileType, null, pattern); List <SourceParserResult> results = sourceParser.Parse().ToList(); //Ensure we've scanned at least some files... const int expectedExceptionCount = 100; this.testOutputHelper.WriteLine("Found {0} \"throw new Exception\" strings", results.Count); Assert.True(results.Count > expectedExceptionCount); HashSet <string> exceptionSet = new HashSet <string>(); foreach (SourceParserResult parserResult in results) { string exceptionName = parserResult.Match.Groups[exceptionNameCaptureGroup].Value; exceptionSet.Add(exceptionName); } this.testOutputHelper.WriteLine("Found {0} types of exception thrown by rest proxy", exceptionSet.Count); this.testOutputHelper.WriteLine("Exceptions:"); this.testOutputHelper.WriteLine("------------------------"); foreach (string exceptionType in exceptionSet) { this.testOutputHelper.WriteLine("{0}", exceptionType); } IEnumerable <string> expectedExceptions = new List <string>() { "ArgumentNullException", "ValidationException", "SerializationException" }; Assert.Equal(expectedExceptions, exceptionSet); }