Skip to content

Commit 26cab82

Browse files
committed
Embed Steam Workshop fixtures for tests and replace skipped Steam live tests with local resources
1 parent 6c0bfad commit 26cab82

7 files changed

Lines changed: 4827 additions & 9 deletions

test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using AET.Modinfo.Model;
44
using AET.Modinfo.Spec;
55
using AET.Modinfo.Utilities;
6+
using Microsoft.Extensions.DependencyInjection;
67
using PG.StarWarsGame.Infrastructure.Services.Name;
8+
using PG.StarWarsGame.Infrastructure.Services.Steam;
79
using PG.StarWarsGame.Infrastructure.Testing.TestBases;
810
using Xunit;
911

@@ -25,6 +27,12 @@ public void Ctor_NullArgs_Throws()
2527

2628
public class OnlineModNameResolverTest : ModNameResolverTestBase
2729
{
30+
protected override void SetupServices(IServiceCollection serviceCollection)
31+
{
32+
base.SetupServices(serviceCollection);
33+
serviceCollection.AddSingleton<ISteamWorkshopWebpageDownloader>(new FakeSteamWorkshopWebpageDownloader());
34+
}
35+
2836
public override ModNameResolverBase CreateResolver()
2937
{
3038
return new OnlineModNameResolver(ServiceProvider);
@@ -36,10 +44,7 @@ public void Ctor_NullArgs_Throws()
3644
Assert.Throws<ArgumentNullException>(() => new OnlineModNameResolver(null!));
3745
}
3846

39-
[Theory(
40-
Skip = TestEnvironment.SteamLiveTestsSkipReason,
41-
SkipUnless = nameof(TestEnvironment.SteamLiveTestsEnabled),
42-
SkipType = typeof(TestEnvironment))]
47+
[Theory]
4348
[InlineData("path/1125718579", "z3r0x's mod version 3.5")]
4449
[InlineData("path/2978074984", "EAWFOC Mod Template")]
4550
public void ResolveName_Steam_WithoutModinfo_FindNameOnline(string path, string containsExpected)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Threading.Tasks;
4+
using HtmlAgilityPack;
5+
using PG.StarWarsGame.Infrastructure.Services.Steam;
6+
7+
namespace PG.StarWarsGame.Infrastructure.Test.ModServices;
8+
9+
internal sealed class FakeSteamWorkshopWebpageDownloader : ISteamWorkshopWebpageDownloader
10+
{
11+
private const string FixtureNamespace = "PG.StarWarsGame.Infrastructure.Test.ModServices.Fixtures";
12+
13+
public Task<HtmlDocument> GetSteamWorkshopsPageHtmlAsync(ulong workshopId, CultureInfo? culture)
14+
{
15+
var doc = new HtmlDocument();
16+
var resourceName = $"{FixtureNamespace}.workshop_{workshopId}.html";
17+
var assembly = typeof(FakeSteamWorkshopWebpageDownloader).Assembly;
18+
using var stream = assembly.GetManifestResourceStream(resourceName);
19+
if (stream is null)
20+
return Task.FromResult(doc);
21+
doc.Load(stream);
22+
return Task.FromResult(doc);
23+
}
24+
}

test/PG.StarWarsGame.Infrastructure.Test/ModServices/Fixtures/workshop_1125718579.html

Lines changed: 1697 additions & 0 deletions
Large diffs are not rendered by default.

test/PG.StarWarsGame.Infrastructure.Test/ModServices/Fixtures/workshop_2508288191.html

Lines changed: 1546 additions & 0 deletions
Large diffs are not rendered by default.

test/PG.StarWarsGame.Infrastructure.Test/ModServices/Fixtures/workshop_2978074984.html

Lines changed: 1539 additions & 0 deletions
Large diffs are not rendered by default.

test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices;
1212

1313
public class OnlineModGameTypeResolverTest : ModGameTypeResolverTestBase
1414
{
15+
protected override void SetupServices(IServiceCollection serviceCollection)
16+
{
17+
base.SetupServices(serviceCollection);
18+
serviceCollection.AddSingleton<ISteamWorkshopWebpageDownloader>(new FakeSteamWorkshopWebpageDownloader());
19+
}
20+
1521
public override ModGameTypeResolver CreateResolver()
1622
{
1723
return new OnlineModGameTypeResolver(ServiceProvider);
@@ -20,13 +26,10 @@ public override ModGameTypeResolver CreateResolver()
2026
public static IEnumerable<object[]> GetOnlineModsData()
2127
{
2228
yield return ["1125718579", new[] {GameType.Foc}, GameType.Eaw]; //z3r0x's Mod (3.5)
23-
yield return ["2508288191", new[] {GameType.Foc, GameType.Eaw}, null!]; //Mod Template
29+
yield return ["2508288191", new[] {GameType.Foc, GameType.Eaw}, null!]; //Deep Core
2430
}
2531

26-
[Theory(
27-
Skip = TestEnvironment.SteamLiveTestsSkipReason,
28-
SkipUnless = nameof(TestEnvironment.SteamLiveTestsEnabled),
29-
SkipType = typeof(TestEnvironment))]
32+
[Theory]
3033
[MemberData(nameof(GetOnlineModsData))]
3134
public void Online_GetTagsFromSteamOnline(string knownId, ICollection<GameType> expectedTypes, GameType? incompatibleWith)
3235
{

test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
3434
<ProjectReference Include="..\..\src\PG.StarWarsGame.Infrastructure\PG.StarWarsGame.Infrastructure.csproj" />
3535
<ProjectReference Include="..\PG.StarWarsGame.Infrastructure.Testing\PG.StarWarsGame.Infrastructure.Testing.csproj" />
3636
</ItemGroup>
37+
38+
<ItemGroup>
39+
<EmbeddedResource Include="ModServices\Fixtures\*.html" />
40+
</ItemGroup>
3741
</Project>

0 commit comments

Comments
 (0)