diff --git a/src/NewsReader/NewsReader.Applications.Test/Controllers/AppControllerTest.cs b/src/NewsReader/NewsReader.Applications.Test/Controllers/AppControllerTest.cs index f47b8998..2c353e6d 100644 --- a/src/NewsReader/NewsReader.Applications.Test/Controllers/AppControllerTest.cs +++ b/src/NewsReader/NewsReader.Applications.Test/Controllers/AppControllerTest.cs @@ -7,10 +7,10 @@ namespace Test.NewsReader.Applications.Controllers; public class AppControllerTest : TestBase { [Fact] - public void OpenSettingsView() + public void OpenSettingsView() => Run(context => { StartApp(); - var feed = Context.WaitForNotNull(Shell.View.GetCurrentViewOrNull); + var feed = context.WaitForNotNull(Shell.View.GetCurrentViewOrNull); var feed1 = FeedsController.FeedManager.Feeds.Single(); Assert.Equal(feed1, feed.ViewModel.Feed); Assert.Equal(feed1, Shell.ViewModel.SelectedFeed); @@ -20,5 +20,5 @@ public void OpenSettingsView() var settings = Shell.View.GetCurrentView(); Assert.NotNull(settings.View); Assert.Null(Shell.ViewModel.SelectedFeed); - } + }); } diff --git a/src/NewsReader/NewsReader.Applications.Test/TestBase.cs b/src/NewsReader/NewsReader.Applications.Test/TestBase.cs index 3c976649..e4dc319e 100644 --- a/src/NewsReader/NewsReader.Applications.Test/TestBase.cs +++ b/src/NewsReader/NewsReader.Applications.Test/TestBase.cs @@ -17,15 +17,12 @@ public abstract class TestBase : IDisposable { protected TestBase() { - Context = UnitTestSynchronizationContext.Create(); var builder = new ContainerBuilder(); builder.RegisterModule(new ApplicationsModule()); builder.RegisterModule(new MockPresentationModule()); Container = builder.Build(); } - public UnitTestSynchronizationContext Context { get; } - public Autofac.IContainer Container { get; } internal AppController AppController { get; private set; } = null!; @@ -33,6 +30,12 @@ protected TestBase() internal SettingsController SettingsController { get; private set; } = null!; public ViewPair Shell { get; private set; } = null!; + public void Run(Action action) + { + using var context = UnitTestSynchronizationContext.Create(); + action(context); + } + public T Resolve() where T : notnull => Container.Resolve(); public void StartApp() @@ -47,7 +50,6 @@ public void StartApp() public void Dispose() { OnDispose(); - Context.Dispose(); } protected virtual void OnDispose() { }