Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO.Compression;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Nikse.SubtitleEdit;
- namespace Test.Dictionaries
- {
- [TestClass]
- public class HunspellDictionaryTest
- {
- [TestMethod]
- public async Task DictionaryStatusTest()
- {
- var assembly = typeof(Program).Assembly;
- using (var gzipStream = assembly.GetManifestResourceStream("Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz"))
- using (var gzip = new GZipStream(gzipStream, CompressionMode.Decompress))
- using (var httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(3) })
- {
- // todo: add httpclient header, some sites might drop the request if some header is not provided
- var doc = XDocument.Load(gzip);
- foreach (var dictionaryEl in doc.Root.Elements("Dictionary"))
- {
- string name = dictionaryEl.Element("EnglishName").Value;
- Debug.WriteLine($"Processing document: {name}");
- var url = dictionaryEl.Element("DownloadLink").Value;
- try
- {
- var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url),
- HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, $"{name} is not available!");
- }
- catch (Exception e)
- {
- Debug.WriteLine($"Failed to get response: {name}: {e.Message}");
- }
- await Task.Delay(500).ConfigureAwait(false);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement