Skip to content

Commit

Permalink
fix tests windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AnakinRaW committed Mar 30, 2024
1 parent f791206 commit c276dd4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AET.SteamAbstraction.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using PG.TestingUtilities;
using Testably.Abstractions.Testing;
using Xunit;

Expand All @@ -15,7 +16,11 @@ public class SteamWrapperFactoryTest
public void Test_CreateWrapper()
{
var regFactory = new Mock<ISteamRegistryFactory>();
regFactory.Setup(f => f.CreateRegistry()).Returns(new Mock<ISteamRegistry>().Object);

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);

var sc = new ServiceCollection();
sc.AddSingleton(_ => regFactory.Object);
Expand All @@ -36,4 +41,20 @@ public void Test_CreateWrapper()

Assert.IsType(expectedType, wrapper);
}

[PlatformSpecificFact(TestPlatformIdentifier.Windows)]
public void Test_CreateWrapper_ThrowsWrongType_Windows()
{
var regFactory = new Mock<ISteamRegistryFactory>();

regFactory.Setup(f => f.CreateRegistry()).Returns(new Mock<ISteamRegistry>().Object);

var sc = new ServiceCollection();
sc.AddSingleton(_ => regFactory.Object);
sc.AddSingleton(new Mock<IProcessHelper>().Object);
sc.AddSingleton<IFileSystem>(new MockFileSystem());
var factory = new SteamWrapperFactory(sc.BuildServiceProvider());

Assert.Throws<InvalidOperationException>(() => factory.CreateWrapper());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ISteamWrapper CreateWrapper()
var registry = _registryFactory.CreateRegistry();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (registry is not WindowsSteamRegistry windowsRegistry)
if (registry is not IWindowsSteamRegistry windowsRegistry)
throw new InvalidOperationException("Expected Windows Registry on Windows systems.");
return new WindowsSteamWrapper(windowsRegistry, serviceProvider);
}
Expand Down

0 comments on commit c276dd4

Please sign in to comment.