public IniFile(string path) { if (OSUtil.IsWindows() == false) { throw new Exception("This class can be only use on win os."); } this.path = path; }
public async Task Fact_OnMTAThread() { var expectedApartment = OSUtil.IsWindows() ? ApartmentState.MTA : ApartmentState.Unknown; Assert.Equal(expectedApartment, Thread.CurrentThread.GetApartmentState()); await Task.Yield(); Assert.Equal(expectedApartment, Thread.CurrentThread.GetApartmentState()); }
protected override IEnumerable <IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { if (testMethod.Method.ReturnType.Name == "System.Void" && testMethod.Method.GetCustomAttributes(typeof(AsyncStateMachineAttribute)).Any()) { yield return(new ExecutionErrorTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, "Async void methods are not supported.")); } yield return(OSUtil.IsWindows() ? (IXunitTestCase) new UITheoryTestCase(UITestCase.SyncContextType.None, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod) : new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "STA threads only exist on Windows.")); }
public async Task UIFact_OnSTAThread() { int initialThread = Environment.CurrentManagedThreadId; Assert.NotNull(SynchronizationContext.Current); var expectedApartment = OSUtil.IsWindows() ? ApartmentState.STA : ApartmentState.Unknown; Assert.Equal(expectedApartment, Thread.CurrentThread.GetApartmentState()); await Task.Yield(); Assert.Equal(initialThread, Environment.CurrentManagedThreadId); Assert.NotNull(SynchronizationContext.Current); }
static AppRuntimeContext() { string path; try { path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); } catch (NotSupportedException) { path = Directory.GetCurrentDirectory(); } _executingPath = path; if (OSUtil.IsMacOS()) { _executingPath = path.Replace("file:", string.Empty); } if (OSUtil.IsWindows()) { _executingPath = new Uri(path).LocalPath; } }
private static Task <decimal> RunOnStaIfPossibleOtherwiseUseMta(Func <decimal> action) { if (OSUtil.IsWindows()) { var tcs = new TaskCompletionSource <decimal>(); var sta = new Thread(() => { try { tcs.SetResult(action()); } catch (Exception ex) { tcs.SetException(ex); } }); sta.SetApartmentState(ApartmentState.STA); sta.Start(); return(tcs.Task); } return(Task.Run(action)); }
protected override IEnumerable <IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { yield return(OSUtil.IsWindows() ? (IXunitTestCase) new UITheoryTestCase(UITestCase.SyncContextType.WinForms, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod) : new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WinForms only exists on Windows.")); }