Xunit.StaFact | based tests on an STA thread

 by   AArnott C# Version: v1.1.11 License: Non-SPDX

kandi X-RAY | Xunit.StaFact Summary

Xunit.StaFact is a C# library. Xunit.StaFact has no bugs, it has no vulnerabilities and it has low support. However Xunit.StaFact has a Non-SPDX License. You can download it from GitHub.
Run your xunit-based tests on an STA thread with the WPF Dispatcher, a WinForms SynchronizationContext, or even a cross-platform generic UI thread emulation with a SynchronizationContext that keeps code running on a "main thread" for that test. Simply use [WpfFact], [WinFormsFact], [StaFact] or the cross-platform [UIFact] on your test method to run your test under conditions that most closely match the main thread in your application. Theory variants of these attributes allow for parameterized testing. Check out the xunit.combinatorial nuget package for pairwise or combinatorial testing with theories.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        Xunit.StaFact has a low active ecosystem.
                        summary
                        It has 67 star(s) with 27 fork(s). There are 8 watchers for this library.
                        summary
                        It had no major release in the last 12 months.
                        summary
                        There are 4 open issues and 24 have been closed. On average issues are closed in 89 days. There are 3 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of Xunit.StaFact is v1.1.11
                        Xunit.StaFact Support
                          Best in #C#
                            Average in #C#
                            Xunit.StaFact Support
                              Best in #C#
                                Average in #C#

                                  kandi-Quality Quality

                                    summary
                                    Xunit.StaFact has 0 bugs and 0 code smells.
                                    Xunit.StaFact Quality
                                      Best in #C#
                                        Average in #C#
                                        Xunit.StaFact Quality
                                          Best in #C#
                                            Average in #C#

                                              kandi-Security Security

                                                summary
                                                Xunit.StaFact has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                Xunit.StaFact code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                Xunit.StaFact Security
                                                  Best in #C#
                                                    Average in #C#
                                                    Xunit.StaFact Security
                                                      Best in #C#
                                                        Average in #C#

                                                          kandi-License License

                                                            summary
                                                            Xunit.StaFact has a Non-SPDX License.
                                                            summary
                                                            Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
                                                            Xunit.StaFact License
                                                              Best in #C#
                                                                Average in #C#
                                                                Xunit.StaFact License
                                                                  Best in #C#
                                                                    Average in #C#

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        Xunit.StaFact releases are available to install and integrate.
                                                                        summary
                                                                        Installation instructions are not available. Examples and code snippets are available.
                                                                        Xunit.StaFact Reuse
                                                                          Best in #C#
                                                                            Average in #C#
                                                                            Xunit.StaFact Reuse
                                                                              Best in #C#
                                                                                Average in #C#
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
                                                                                  Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  Xunit.StaFact Key Features

                                                                                  The following attributes are supported:. ¹ This is a private SynchronizationContext that works cross-platform and effectively keeps code running on the test's starting thread the way a GUI application's main thread would do. ² STA thread only applies on Windows. On other operating systems, an MTA thread is used. ³ Windows-only attributes result in the test to result in "Skipped" on other operating systems.

                                                                                  Xunit.StaFact Examples and Code Snippets

                                                                                  Xunit.StaFact,Samples
                                                                                  C#dot imgLines of Code : 8dot imgLicense : Non-SPDX (NOASSERTION)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      [UIFact] // or [WinFormsFact] or [WpfFact] public async Task WpfFact_OnSTAThread() { Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState()); int originalThread = Environment.CurrentManagedThreadId; await Task.Yield(); Assert.Equal(originalThread, Environment.CurrentManagedThreadId); // still there }
                                                                                  Community Discussions

                                                                                  Trending Discussions on Xunit.StaFact

                                                                                  WPF Frame Content is null in unit test
                                                                                  chevron right

                                                                                  Trending Discussions on Xunit.StaFact

                                                                                  QUESTION

                                                                                  WPF Frame Content is null in unit test
                                                                                  Asked 2021-May-01 at 14:13

                                                                                  I have had success with some other unit tests around WPF Windows. This one has got me.

                                                                                  I have an xunit test project in dotnet core 5 that has a Window. The test sets the content of a frame to a new page. However the assertion to check the content is not null will not work as the ViewNavigator content is null.

                                                                                  This is using Xunit.StaFact to allow running tests under STA thread.

                                                                                  Window
                                                                                  
                                                                                      
                                                                                          
                                                                                      
                                                                                  
                                                                                  
                                                                                  Test
                                                                                  [UIFact]
                                                                                  public void Navigate_To_Pages()
                                                                                  {
                                                                                      FrameNavigationWindow window = new();
                                                                                  
                                                                                      var monitor = new ManualResetEventSlim(false);
                                                                                      window.ViewNavigator.NavigationService.Navigated += (sender, args) => monitor.Set();
                                                                                      window.ViewNavigator.ContentRendered += (sender, args) => monitor.Set();
                                                                                  
                                                                                      // set content here
                                                                                      window.ViewNavigator.Content = new PageNoVm1();
                                                                                  
                                                                                      monitor.Wait(TimeSpan.FromSeconds(5));
                                                                                  
                                                                                      // content always null
                                                                                      Assert.Equal(typeof(PageNoVm1), window.ViewNavigator.Content.GetType());
                                                                                  }
                                                                                  
                                                                                  Page

                                                                                  Just an empty page.

                                                                                  
                                                                                              
                                                                                      
                                                                                  
                                                                                  

                                                                                  I can't spot anything obviously wrong.

                                                                                  ** Updates **

                                                                                  I have tried using different flavours of window.Dispatcher.Invoke to set the Content:

                                                                                  var monitor = new ManualResetEventSlim(false);
                                                                                  
                                                                                  window.ViewNavigator.NavigationService.Navigated += (sender, args) => monitor.Set();
                                                                                  window.ViewNavigator.ContentRendered += (sender, args) => monitor.Set();
                                                                                  
                                                                                  var page = new PageNoVm1();
                                                                                  window.Dispatcher.Invoke(() => window.ViewNavigator.Content = page);
                                                                                  monitor.Wait(TimeSpan.FromSeconds(3));
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-May-01 at 14:13

                                                                                  Why are you synchronously blocking for 3 or 5 seconds? If WPF needs some time, you're not feeding it this way -- you're starving it.

                                                                                  Try changing the test method to be async, and then use await to give WPF time:

                                                                                  -monitor.Wait(TimeSpan.FromSeconds(5));
                                                                                  +await Task.Delay(5000);
                                                                                  

                                                                                  I don't know if this will solve the problem, but it's a better way to pause execution in general.

                                                                                  Source https://stackoverflow.com/questions/67332842

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install Xunit.StaFact

                                                                                  You can download it from GitHub.

                                                                                  Support

                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  CLONE
                                                                                • HTTPS

                                                                                  https://github.com/AArnott/Xunit.StaFact.git

                                                                                • CLI

                                                                                  gh repo clone AArnott/Xunit.StaFact

                                                                                • sshUrl

                                                                                  git@github.com:AArnott/Xunit.StaFact.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Consider Popular C# Libraries

                                                                                  PowerToys

                                                                                  by microsoft

                                                                                  shadowsocks-windows

                                                                                  by shadowsocks

                                                                                  PowerShell

                                                                                  by PowerShell

                                                                                  aspnetcore

                                                                                  by dotnet

                                                                                  v2rayN

                                                                                  by 2dust

                                                                                  Try Top Libraries by AArnott

                                                                                  Nerdbank.Streams

                                                                                  by AArnottC#

                                                                                  IronPigeon

                                                                                  by AArnottC#

                                                                                  PCLCrypto

                                                                                  by AArnottC#

                                                                                  Compare C# Libraries with Highest Support

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit