Пример #1
0
 public IniFile(string path)
 {
     if (OSUtil.IsWindows() == false)
     {
         throw new Exception("This class can be only use on win os.");
     }
     this.path = path;
 }
Пример #2
0
    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());
    }
Пример #3
0
        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."));
        }
Пример #4
0
    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);
    }
Пример #5
0
        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;
            }
        }
Пример #6
0
        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));
        }
Пример #7
0
 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."));
 }