Skip to content

Commit

Permalink
do not support ubuntu in this version and update some tests and contr…
Browse files Browse the repository at this point in the history
…acts
  • Loading branch information
AnakinRaW committed Mar 30, 2024
1 parent c276dd4 commit a9ca8f5
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 47 deletions.
17 changes: 9 additions & 8 deletions sample/SampleApplication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using AET.SteamAbstraction;
using AnakinRaW.CommonUtilities.Registry.Windows;
using Microsoft.Extensions.DependencyInjection;
using PG.StarWarsGame.Infrastructure;
Expand All @@ -11,7 +13,6 @@
using PG.StarWarsGame.Infrastructure.Services;
using PG.StarWarsGame.Infrastructure.Services.Dependencies;
using PG.StarWarsGame.Infrastructure.Services.Detection;
using PG.StarWarsGame.Infrastructure.Services.Name;


var sp = SetupApplication();
Expand Down Expand Up @@ -67,14 +68,14 @@ IServiceProvider SetupApplication()
var sc = new ServiceCollection();

sc.AddSingleton(WindowsRegistry.Default);
sc.AddSingleton<IFileSystem>(_ => new FileSystem());

PetroglyphGameInfrastructure.InitializeServices(sc);
SteamAbstractionLayer.InitializeServices(sc);
PetroglyphGameClients.InitializeServices(sc);

// The game detector to use for this application.
sc.AddTransient<IGameDetector>(sp => new SteamPetroglyphStarWarsGameDetector(sp));
sc.AddTransient<IGameFactory>(sp => new GameFactory(sp));
sc.AddTransient<IModReferenceFinder>(sp => new FileSystemModFinder(sp));
sc.AddTransient<IModFactory>(sp => new ModFactory(sp));
sc.AddTransient<IModReferenceLocationResolver>(sp => new ModReferenceLocationResolver(sp));
sc.AddTransient<IModNameResolver>(sp => new DirectoryModNameResolver(sp));
sc.AddTransient<IDependencyResolver>(sp => new ModDependencyResolver(sp));
sc.AddTransient<IGameClientFactory>(sp => new DefaultGameClientFactory(sp));

return sc.BuildServiceProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Testably.Abstractions.Testing" Version="3.0.0" />
<PackageReference Include="Testably.Abstractions.Testing" Version="3.0.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ namespace AET.SteamAbstraction.Test;

public class SteamWrapperFactoryTest
{
[Fact]
public void Test_CreateWrapper()
[PlatformSpecificFact(TestPlatformIdentifier.Windows)]
public void Test_CreateWrapper_Windows()
{
var regFactory = new Mock<ISteamRegistryFactory>();

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
regFactory.Setup(f => f.CreateRegistry()).Returns(new Mock<IWindowsSteamRegistry>().Object);
else
regFactory.Setup(f => f.CreateRegistry()).Returns(new Mock<ISteamRegistry>().Object);
regFactory.Setup(f => f.CreateRegistry()).Returns(new Mock<IWindowsSteamRegistry>().Object);

var sc = new ServiceCollection();
sc.AddSingleton(_ => regFactory.Object);
Expand All @@ -30,15 +27,7 @@ public void Test_CreateWrapper()

var wrapper = factory.CreateWrapper();

Type? expectedType = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
expectedType = typeof(WindowsSteamWrapper);
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
expectedType = typeof(LinuxSteamWrapper);

if (expectedType is null)
Assert.Fail("Platform was not supported");

var expectedType = typeof(WindowsSteamWrapper);
Assert.IsType(expectedType, wrapper);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=library/@EntryIndexedValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=linux/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=windows/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=wrappers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
</wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

namespace AET.SteamAbstraction;

internal class SteamAbstractionLayer
/// <summary>
///
/// </summary>
public class SteamAbstractionLayer
{
/// <summary>
///
/// </summary>
/// <param name="serviceCollection"></param>
public static void InitializeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<ISteamWrapperFactory>(sp => new SteamWrapperFactory(sp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public ISteamWrapper CreateWrapper()
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return new LinuxSteamWrapper(registry, serviceProvider);
{
throw new NotImplementedException("Steam wrapper for Linux is not yet implemented.");
}

throw new PlatformNotSupportedException($"The current platform is not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DefaultGameClientFactory(IServiceProvider serviceProvider)
/// Gets or creates an <see cref="IGameClient"/> for the given <paramref name="gamePlatform"/>.
/// </summary>
/// <param name="gamePlatform">The requested game platform.</param>
/// <param name="serviceProvider">The service provider used to created the <see cref="IGameClient"/>.</param>
/// <param name="serviceProvider">The service provider used to create the <see cref="IGameClient"/>.</param>
/// <returns></returns>
public IGameClient CreateClient(GamePlatform gamePlatform, IServiceProvider serviceProvider)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using PG.StarWarsGame.Infrastructure.Clients.Arguments;
using PG.StarWarsGame.Infrastructure.Clients.Processes;

namespace PG.StarWarsGame.Infrastructure.Clients;

Expand All @@ -15,9 +16,13 @@ public class PetroglyphGameClients
/// <param name="serviceCollection">The service collection to be filled.</param>
public static void InitializeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<IGameProcessLauncher>(sp => new DefaultGameProcessLauncher(sp));
serviceCollection.AddTransient<IGameExecutableFileService>(sp => new GameExecutableFileService(sp));
serviceCollection.AddTransient<IGameExecutableNameBuilder>(_ => new GameExecutableNameBuilder());


serviceCollection.AddTransient<IGameClientFactory>(sp => new DefaultGameClientFactory(sp));
serviceCollection.AddTransient<IModArgumentListFactory>(sp => new ModArgumentListFactory(sp));
serviceCollection.AddTransient<IArgumentCollectionBuilder>(sp => new KeyBasedArgumentCollectionBuilder());
serviceCollection.AddTransient<IArgumentValidator>(_ => new ArgumentValidator());
serviceCollection.AddTransient<IArgumentCommandLineBuilder>(sp => new ArgumentCommandLineBuilder(sp));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SteamGameLauncher(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
throw new ArgumentNullException(nameof(serviceProvider));
_steamWrapper = serviceProvider.GetRequiredService<ISteamWrapper>();
_steamWrapper = serviceProvider.GetRequiredService<ISteamWrapperFactory>().CreateWrapper();
_internalLauncher = serviceProvider.GetRequiredService<IGameProcessLauncher>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class SteamPetroglyphStarWarsGameDetector : GameDetector
private const uint EaWGameId = 32470;
private const uint FocDepotId = 32472;

private readonly ISteamWrapper _steamWrapper;
private readonly ISteamWrapperFactory _steamWrapperFactory;
private readonly IGameRegistryFactory _registryFactory;

/// <summary>
Expand All @@ -31,16 +31,18 @@ public sealed class SteamPetroglyphStarWarsGameDetector : GameDetector
public SteamPetroglyphStarWarsGameDetector(IServiceProvider serviceProvider) : base(serviceProvider, true)
{
_registryFactory = ServiceProvider.GetRequiredService<IGameRegistryFactory>();
_steamWrapper = ServiceProvider.GetRequiredService<ISteamWrapper>();
_steamWrapperFactory = ServiceProvider.GetRequiredService<ISteamWrapperFactory>();
}

/// <inheritdoc/>
protected override GameLocationData FindGameLocation(GameDetectorOptions options)
{
if (!_steamWrapper.Installed)
using var steam = _steamWrapperFactory.CreateWrapper();

if (!steam.Installed)
return default;

if (!_steamWrapper.IsGameInstalled(EaWGameId, out var game))
if (!steam.IsGameInstalled(EaWGameId, out var game))
return default;

if (!game!.State.HasFlag(SteamAppState.StateFullyInstalled))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Testably.Abstractions.Testing" Version="3.0.0" />
<PackageReference Include="Testably.Abstractions.Testing" Version="3.0.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace PG.StarWarsGame.Infrastructure.Clients.Test.Steam;
public class SteamGameClientTest
{
private readonly SteamGameClient _service;
private readonly Mock<ISteamWrapper> _steam;
private readonly Mock<ISteamWrapperFactory> _steamFactory;
private readonly Mock<IGame> _game;
private readonly Mock<IGameProcessLauncher> _launcher;

Expand All @@ -23,8 +23,8 @@ public SteamGameClientTest()
var fs = new MockFileSystem();
fs.Initialize().WithFile("test.exe");
var sc = new ServiceCollection();
_steam = new Mock<ISteamWrapper>();
sc.AddTransient(_ => _steam.Object);
_steamFactory = new Mock<ISteamWrapperFactory>();
sc.AddTransient(_ => _steamFactory.Object);
var fileService = new Mock<IGameExecutableFileService>();
fileService.Setup(s => s.GetExecutableForGame(It.IsAny<IGame>(), It.IsAny<GameBuildType>()))
.Returns(fs.FileInfo.New("test.exe"));
Expand All @@ -49,6 +49,10 @@ public void TestNotCompatiblePlatform_Throws()
[Fact]
public void TestSteamNotRunning_Throws()
{
var steam = new Mock<ISteamWrapper>();
steam.SetupGet(s => s.IsRunning).Returns(false);
_steamFactory.Setup(s => s.CreateWrapper()).Returns(steam.Object);

_game.Setup(g => g.Platform).Returns(GamePlatform.SteamGold);
_game.Setup(g => g.Game).Returns(_game.Object);
Assert.Throws<GameStartException>(() => _service.Play(_game.Object));
Expand All @@ -57,9 +61,12 @@ public void TestSteamNotRunning_Throws()
[Fact]
public void TestProcessCreated()
{
var steam = new Mock<ISteamWrapper>();
steam.SetupGet(s => s.IsRunning).Returns(true);
_steamFactory.Setup(s => s.CreateWrapper()).Returns(steam.Object);

_game.Setup(g => g.Platform).Returns(GamePlatform.SteamGold);
_game.Setup(g => g.Game).Returns(_game.Object);
_steam.Setup(s => s.IsRunning).Returns(true);

var process = new Mock<IGameProcess>();
process.Setup(p => p.State).Returns(GameProcessState.Closed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public SteamPetroglyphStarWarsGameDetectorTest()
var sc = new ServiceCollection();
_fileSystem = new MockFileSystem();
_steamWrapper = new Mock<ISteamWrapper>();

var steamFactory = new Mock<ISteamWrapperFactory>();
steamFactory.Setup(f => f.CreateWrapper()).Returns(_steamWrapper.Object);
sc.AddSingleton(steamFactory.Object);

_gameRegistryFactory = new Mock<IGameRegistryFactory>();
_gameRegistry = new Mock<IGameRegistry>();
sc.AddTransient<IFileSystem>(_ => _fileSystem);
Expand Down

This file was deleted.

14 changes: 14 additions & 0 deletions src/PetroGlyph.Games.EawFoc/src/PetroglyphGameInfrastructure.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using PG.StarWarsGame.Infrastructure.Games.Registry;
using PG.StarWarsGame.Infrastructure.Services;
using PG.StarWarsGame.Infrastructure.Services.Dependencies;
using PG.StarWarsGame.Infrastructure.Services.Detection;
using PG.StarWarsGame.Infrastructure.Services.Name;
using PG.StarWarsGame.Infrastructure.Services.Steam;

namespace PG.StarWarsGame.Infrastructure;
Expand All @@ -20,5 +23,16 @@ public static void InitializeServices(IServiceCollection serviceCollection)
serviceCollection.AddTransient<IGameRegistryFactory>(_ => new GameRegistryFactory());
serviceCollection.AddTransient<IModIdentifierBuilder>(sp => new ModIdentifierBuilder(sp));
serviceCollection.AddTransient<ISteamGameHelpers>(sp => new SteamGameHelpers(sp));

serviceCollection.AddTransient<IGameFactory>(sp => new GameFactory(sp));
serviceCollection.AddTransient<IGameRegistryFactory>(sp => new GameRegistryFactory());
serviceCollection.AddTransient<IModReferenceFinder>(sp => new FileSystemModFinder(sp));
serviceCollection.AddTransient<IModFactory>(sp => new ModFactory(sp));
serviceCollection.AddTransient<IModReferenceLocationResolver>(sp => new ModReferenceLocationResolver(sp));
serviceCollection.AddTransient<IModNameResolver>(sp => new DirectoryModNameResolver(sp));

serviceCollection.AddTransient<IDependencyResolver>(sp => new ModDependencyResolver(sp));
serviceCollection.AddTransient<IModDependencyGraphBuilder>(sp => new ModDependencyGraphBuilder());
serviceCollection.AddTransient<IModDependencyTraverser>(sp => new ModDependencyTraverser(sp));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
<PackageReference Include="Testably.Abstractions.Testing" Version="3.0.0" />
<PackageReference Include="Testably.Abstractions.Testing" Version="3.0.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.0",
"version": "3.0",
"publicReleaseRefSpec": [
"^refs/heads/main"
],
Expand Down

0 comments on commit a9ca8f5

Please sign in to comment.