Skip to content

Commit

Permalink
fixing Shiny tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Feb 24, 2021
1 parent b77c08c commit b7ad9ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
2 changes: 0 additions & 2 deletions tests/Shiny.Prism.Tests/Mocks/MockStartup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down
30 changes: 5 additions & 25 deletions tests/Shiny.Prism.Tests/Mocks/ShinyPrismTestHost.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reactive.Subjects;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Shiny.Infrastructure;
using Shiny.Jobs;
using Shiny.Net;
using Shiny.Power;
Expand All @@ -17,49 +15,31 @@

namespace Shiny.Prism.Mocks
{
class ShinyPrismTestHost : IPlatform
class ShinyPrismTestHost : TestPlatform
{
private readonly Subject<PlatformState> _stateChanged = new Subject<PlatformState>();
private readonly Action<IServiceCollection> _platformBuild;

private ShinyPrismTestHost(Action<IServiceCollection> platformBuild)
{
_platformBuild = platformBuild;
}

public DirectoryInfo AppData { get; }
public DirectoryInfo Cache { get; }
public DirectoryInfo Public { get; }
public string AppIdentifier { get; }
public string AppVersion { get; }
public string AppBuild { get; }
public string MachineName { get; }
public string OperatingSystem { get; }
public string OperatingSystemVersion { get; }
public string Manufacturer { get; }
public string Model { get; }

public static void Init(ITestOutputHelper testOutputHelper) => Init(new MockStartup(testOutputHelper));

public static void Init(IShinyStartup startup = null, Action<IServiceCollection> platformBuild = null)
{
ShinyHost.Init(new ShinyPrismTestHost(platformBuild), startup);
}

public void Register(IServiceCollection services)
public override void Register(IServiceCollection services)
{
base.Register(services);
services.AddSingleton<IJobManager, TestJobManager>();
services.AddSingleton<IConnectivity, TestConnectivity>();
services.AddSingleton<IPowerManager, TestPowerManager>();
//services.AddSingleton<IFileSystem, FileSystemImpl>();
services.AddSingleton<ISettings, TestSettings>();
//services.AddSingleton<IEnvironment, TestEnvironment>();
services.AddSingleton<ISerializer, ShinySerializer>();
_platformBuild?.Invoke(services);
}

public IObservable<PlatformState> WhenStateChanged()
{
return _stateChanged;
}
}
}
11 changes: 10 additions & 1 deletion tests/Shiny.Prism.Tests/Tests/PrismStartupTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Prism.DryIoc;
using Prism.Ioc;
using Shiny.Jobs;
Expand Down Expand Up @@ -34,13 +35,21 @@ public void DoesNotThrowExceptionOnStartup()
}

[Theory]
[InlineData(typeof(IPlatform), typeof(ShinyPrismTestHost))]
[InlineData(typeof(IJobManager), typeof(TestJobManager))]
[InlineData(typeof(IConnectivity), typeof(TestConnectivity))]
[InlineData(typeof(IPowerManager), typeof(TestPowerManager))]
[InlineData(typeof(ISettings), typeof(TestSettings))]
public void ExpectedTypesAreRegisteredAndResolve(Type serviceType, Type implementingType)
{
ShinyPrismTestHost.Init(_testOutputHelper);
var types = ContainerLocator.Container
.GetContainer()
.GetServiceRegistrations()
.Where(x => x.ServiceType.Assembly.GetName().Name == "Shiny.Core");
foreach (var type in types)
_testOutputHelper.WriteLine($"Found: {type.ServiceType.FullName} - {type.ImplementationType?.FullName}");

Assert.True(PrismContainerExtension.Current.IsRegistered(serviceType));

var fromShiny = ShinyHost.Container.GetService(serviceType);
Expand All @@ -54,7 +63,7 @@ public void PrismStartupLocatesContainerExtension()
var ex = Record.Exception(() => ShinyPrismTestHost.Init(new MockStartup(_testOutputHelper, false)));

Assert.Null(ex);
Assert.NotNull(PrismContainerExtension.Current.Resolve<IConnectivity>());
Assert.NotNull(PrismContainerExtension.Current.Resolve<IJobManager>());
}
}
}

0 comments on commit b7ad9ef

Please sign in to comment.