diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ee68c3d..e5c95d6 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -21,3 +21,5 @@ jobs: run: dotnet restore - name: Build run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal diff --git a/SdarotAPI/SdarotDriver.cs b/SdarotAPI/SdarotDriver.cs index 140fefc..acc1ce9 100644 --- a/SdarotAPI/SdarotDriver.cs +++ b/SdarotAPI/SdarotDriver.cs @@ -8,21 +8,25 @@ public class SdarotDriver public bool IsDriverInitialized => _webDriver is not null; - public SdarotDriver(bool headless = true) + public SdarotDriver(bool headless = true, bool ignoreChecks = false) { _headless = headless; - ChromeDriverHelper.GetChromeVersion().Wait(); // May throw ChromeIsNotInstalledException + if (!ignoreChecks) + ChromeDriverHelper.GetChromeVersion().Wait(); // May throw ChromeIsNotInstalledException Constants.SdarotUrls.BaseDomain = SdarotHelper.RetrieveSdarotDomain().Result; _httpClient.DefaultRequestHeaders.Referrer = new Uri(Constants.SdarotUrls.HomeUrl); - try + if (!ignoreChecks) { - _httpClient.GetAsync(Constants.SdarotUrls.TestUrl).Wait(); - } - catch - { - throw new SdarotBlockedException(); + try + { + _httpClient.GetAsync(Constants.SdarotUrls.TestUrl).Wait(); + } + catch + { + throw new SdarotBlockedException(); + } } } diff --git a/SdarotAPITest/ApiUnitTest.cs b/SdarotAPITest/ApiUnitTest.cs index 05c05f2..1149cb9 100644 --- a/SdarotAPITest/ApiUnitTest.cs +++ b/SdarotAPITest/ApiUnitTest.cs @@ -1,5 +1,4 @@ -using OpenQA.Selenium.Remote; -using System.Diagnostics; +using System.Diagnostics; namespace SdarotAPITest; @@ -7,47 +6,33 @@ namespace SdarotAPITest; public class ApiUnitTest { [TestMethod] - public async Task DriverTest() + public async Task DriverInitTest() { - SdarotDriver driver = new(); - try - { - await driver.InitializeWebDriver(); - - var series = (await driver.SearchSeries("hahamama")).ToList(); - var hamhamama = series[0]; - var seasons = (await driver.GetSeasonsAsync(hamhamama)).ToList(); - var episodes = (await driver.GetEpisodesAsync(seasons[0])).ToList(); - - Trace.WriteLine("Done."); - } - finally - { - driver.ShutdownWebDriver(); - } + await Task.Delay(500); + Stopwatch sw = new(); + sw.Start(); + + SdarotDriver driver = new(ignoreChecks: true); + + sw.Stop(); + + Trace.WriteLine($"Driver initialization: {sw.Elapsed.TotalSeconds} seconds."); } [TestMethod] public async Task SearchTest() { - SdarotDriver driver = new(); - try - { - await driver.InitializeWebDriver(); - - Trace.WriteLine($"No results: {(await MeasureSearch(driver, "dsakdjaslkfjsalkjfas")).TotalSeconds} seconds."); - Trace.WriteLine($"15 results: {(await MeasureSearch(driver, "שמש")).TotalSeconds} seconds."); - Trace.WriteLine($"74 results: {(await MeasureSearch(driver, "ana")).TotalSeconds} seconds."); - Trace.WriteLine($"One result: {(await MeasureSearch(driver, "shemesh")).TotalSeconds} seconds."); - } - finally - { - driver.ShutdownWebDriver(); - } + SdarotDriver driver = new(ignoreChecks: true); + + Trace.WriteLine($"No results: {(await MeasureSearch(driver, "dsakdjaslkfjsalkjfas")).TotalSeconds} seconds."); + Trace.WriteLine($"15 results: {(await MeasureSearch(driver, "שמש")).TotalSeconds} seconds."); + Trace.WriteLine($"74 results: {(await MeasureSearch(driver, "ana")).TotalSeconds} seconds."); + Trace.WriteLine($"One result: {(await MeasureSearch(driver, "shemesh")).TotalSeconds} seconds."); } public static async Task MeasureSearch(SdarotDriver driver, string query) { + await Task.Delay(500); Stopwatch sw = new(); sw.Start(); @@ -56,4 +41,41 @@ public static async Task MeasureSearch(SdarotDriver driver, string que sw.Stop(); return sw.Elapsed; } + + [TestMethod] + public async Task SeasonsTest() + { + await Task.Delay(500); + SdarotDriver driver = new(ignoreChecks: true); + + var series = (await driver.SearchSeries("family guy")).ToList()[0]; + + Stopwatch sw = new(); + sw.Start(); + + await driver.GetSeasonsAsync(series); + + sw.Stop(); + + Trace.WriteLine($"Seasons retrieving: {sw.Elapsed.TotalSeconds} seconds."); + } + + [TestMethod] + public async Task EpisodesTest() + { + await Task.Delay(500); + SdarotDriver driver = new(ignoreChecks: true); + + var series = (await driver.SearchSeries("family guy")).ToList()[0]; + var season = (await driver.GetSeasonsAsync(series)).ToList()[3]; + + Stopwatch sw = new(); + sw.Start(); + + await driver.GetEpisodesAsync(season); + + sw.Stop(); + + Trace.WriteLine($"Seasons retrieving: {sw.Elapsed.TotalSeconds} seconds."); + } } \ No newline at end of file