Browse Source

Indicate exotic lifetimes are not supported

artyom 6 years ago
parent
commit
6eed518746
1 changed files with 17 additions and 0 deletions
  1. 17 0
      tests/Avalonia.ReactiveUI.UnitTests/AutoSuspendHelperTest.cs

+ 17 - 0
tests/Avalonia.ReactiveUI.UnitTests/AutoSuspendHelperTest.cs

@@ -36,6 +36,11 @@ namespace Avalonia.ReactiveUI.UnitTests
             public string Example { get; set; }
         }
 
+        public class ExoticApplicationLifetimeWithoutLifecycleEvents : IDisposable, IApplicationLifetime
+        {
+            public void Dispose() { }
+        }
+
         [Fact]
         public void AutoSuspendHelper_Should_Immediately_Fire_IsLaunchingNew() 
         {
@@ -77,5 +82,17 @@ namespace Avalonia.ReactiveUI.UnitTests
                 Assert.Equal("Foo", RxApp.SuspensionHost.GetAppState<AppState>().Example);
             }
         }
+
+        [Fact]
+        public void AutoSuspendHelper_Should_Throw_For_Not_Supported_Lifetimes()
+        {
+            using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
+            using (var lifetime = new ExoticApplicationLifetimeWithoutLifecycleEvents()) 
+            {
+                var application = AvaloniaLocator.Current.GetService<Application>();
+                application.ApplicationLifetime = lifetime;
+                Assert.Throws<NotSupportedException>(() => new AutoSuspendHelper(application.ApplicationLifetime));
+            }
+        }
     }
 }