Skip to content

Commit

Permalink
Merge pull request #97 from yairp03/dev
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
yairp03 authored Sep 18, 2022
2 parents 682ec25 + 8b22ac9 commit ac9126a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
20 changes: 12 additions & 8 deletions SdarotAPI/SdarotDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down
88 changes: 55 additions & 33 deletions SdarotAPITest/ApiUnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
using OpenQA.Selenium.Remote;
using System.Diagnostics;
using System.Diagnostics;

namespace SdarotAPITest;

[TestClass]
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<TimeSpan> MeasureSearch(SdarotDriver driver, string query)
{
await Task.Delay(500);
Stopwatch sw = new();
sw.Start();

Expand All @@ -56,4 +41,41 @@ public static async Task<TimeSpan> 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.");
}
}

0 comments on commit ac9126a

Please sign in to comment.