public static void TestTryGetTextFromUriFail() { Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; var webUrl = "https://gist.githubusercontent.com/ig-sinicyn/813e44fa231410892e480c717532bb77/raw/17537a4823e110460b02bf0de4ac11dbd8dcb763/SampleFile.badfile.txt"; var webUrl2 = "https://gist.githubusercontent.baddomain/ig-sinicyn/813e44fa231410892e480c717532bb77/raw/17537a4823e110460b02bf0de4ac11dbd8dcb763/SampleFile.txt"; var relativePath = "BadFile.txt"; var fullPath = Path.GetFullPath(relativePath); var fullPathUri = new Uri(fullPath).ToString(); var timeout = TimeSpan.FromSeconds(0.5); Assert.IsNull(IoHelpers.TryGetTextFromUri(webUrl, timeout)); Assert.IsNull(IoHelpers.TryGetTextFromUri(webUrl2, timeout)); Assert.IsNull(IoHelpers.TryGetTextFromUri(relativePath, timeout)); Assert.IsNull(IoHelpers.TryGetTextFromUri(fullPath, timeout)); Assert.IsNull(IoHelpers.TryGetTextFromUri(fullPathUri, timeout)); }
public static void TestTryGetTextFromUri() { Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; var webUrl = "https://gist.githubusercontent.com/ig-sinicyn/813e44fa231410892e480c717532bb77/raw/17537a4823e110460b02bf0de4ac11dbd8dcb763/SampleFile.txt"; var relativePath = @"Assets\SampleFile.txt"; var fullPath = Path.GetFullPath(relativePath); var fullPathUri = new Uri(fullPath).ToString(); // ReSharper disable StringLiteralTypo var expectedText = @"A sample of text Пример текста テキストのサンプル"; // ReSharper restore StringLiteralTypo Assert.AreEqual(IoHelpers.TryGetTextFromUri(webUrl).ReadToEnd().Replace("\n", "\r\n"), expectedText); Assert.AreEqual(IoHelpers.TryGetTextFromUri(relativePath).ReadToEnd(), expectedText); Assert.AreEqual(IoHelpers.TryGetTextFromUri(fullPath).ReadToEnd(), expectedText); Assert.AreEqual(IoHelpers.TryGetTextFromUri(fullPathUri).ReadToEnd(), expectedText); }
public static XDocument[] TryParseXmlAnnotationDocsFromLog( [NotNull] string logUri, [NotNull] IMessageLogger messageLogger) { Code.NotNullNorEmpty(logUri, nameof(logUri)); Code.NotNull(messageLogger, nameof(messageLogger)); messageLogger.Logger.WriteVerbose($"Downloading '{logUri}'."); using (var reader = IoHelpers.TryGetTextFromUri(logUri, TimeSpan.FromSeconds(15))) { if (reader == null) { messageLogger.WriteSetupErrorMessage($"Could not load log content from '{logUri}'."); return(null); } messageLogger.Logger.WriteVerbose($"Parsing '{logUri}' content."); return(ParseLogContent(logUri, reader, messageLogger)); } }