public void ConfigureCurrentThreadAsMainGuiThread()
        {
            Exception?occurredException = null;

            var dummyThread = new Thread(() =>
            {
                // Delegate this test to an own thread because change of Thread.Name can not be reversed

                try
                {
                    using (_ = FirLibApplication.GetLoader()
                               .ConfigureCurrentThreadAsMainGuiThread()
                               .Load())
                    {
                        Assert.AreEqual(FirLibConstants.MESSENGER_NAME_GUI, Thread.CurrentThread.Name);
                    }
                    Assert.AreEqual(FirLibConstants.MESSENGER_NAME_GUI, Thread.CurrentThread.Name);
                }
                catch (Exception e)
                {
                    occurredException = e;
                }
            });

            dummyThread.Start();
            dummyThread.Join();

            Assert.IsNull(occurredException, occurredException?.ToString() ?? string.Empty);
        }
        public void LoadAndUnload_Multiple()
        {
            FirLibApplication?firstAppObject = null;

            using (_ = FirLibApplication.GetLoader().Load())
            {
                Assert.IsTrue(FirLibApplication.IsLoaded);
                Assert.IsNotNull(FirLibApplication.Current);

                firstAppObject = FirLibApplication.Current;
            }
            Assert.IsFalse(FirLibApplication.IsLoaded);

            FirLibApplication?secondAppObject = null;

            using (_ = FirLibApplication.GetLoader().Load())
            {
                Assert.IsTrue(FirLibApplication.IsLoaded);
                Assert.IsNotNull(FirLibApplication.Current);

                secondAppObject = FirLibApplication.Current;
            }
            Assert.IsFalse(FirLibApplication.IsLoaded);

            Assert.AreNotEqual(firstAppObject, secondAppObject, "First and second application object");
        }
 public void LoadAndUnload()
 {
     using (_ = FirLibApplication.GetLoader().Load())
     {
         Assert.IsTrue(FirLibApplication.IsLoaded);
         Assert.IsNotNull(FirLibApplication.Current);
     }
     Assert.IsFalse(FirLibApplication.IsLoaded);
 }
Exemplo n.º 4
0
        /// <inheritdoc />
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Initialize base application logic
            FirLibApplication.GetLoader()
            .AttachToWpfEnvironment()
            .Load();
        }
        public void DisposeServiceOnUnload()
        {
            var disposeOnServiceCalled = false;
            var dummyDisposable        = new DummyDisposable(
                () => disposeOnServiceCalled = true);

            using (_ = FirLibApplication.GetLoader()
                       .AddService(typeof(IDisposable), dummyDisposable)
                       .Load())
            {
                Assert.IsFalse(disposeOnServiceCalled, nameof(disposeOnServiceCalled));
            }
            Assert.IsTrue(disposeOnServiceCalled, nameof(disposeOnServiceCalled));
        }
        public void LoadAndUnloadMethods()
        {
            var loadActionCalled   = false;
            var unloadActionCalled = false;

            using (_ = FirLibApplication.GetLoader()
                       .AddLoadAction(() => loadActionCalled = true)
                       .AddUnloadAction(() => unloadActionCalled = true)
                       .Load())
            {
                Assert.IsTrue(loadActionCalled, nameof(loadActionCalled));
                Assert.IsFalse(unloadActionCalled, nameof(unloadActionCalled));
            }
            Assert.IsTrue(loadActionCalled, nameof(loadActionCalled));
            Assert.IsTrue(unloadActionCalled, nameof(unloadActionCalled));
        }