210
|
1 using System;
|
|
2 using System.Reflection;
|
|
3 using System.Threading;
|
|
4 using Implab.Parallels;
|
|
5 using Implab.Components;
|
|
6
|
|
7 #if MONO
|
|
8
|
|
9 using NUnit.Framework;
|
|
10 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
|
|
11 using TestMethodAttribute = NUnit.Framework.TestAttribute;
|
|
12 using AssertFailedException = NUnit.Framework.AssertionException;
|
|
13 #else
|
|
14
|
|
15 using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
16
|
|
17 #endif
|
|
18 namespace Implab.Fx.Test {
|
|
19 [TestClass]
|
|
20 public class StaApartmentTests {
|
|
21 [TestMethod]
|
|
22 public void CreateDestroyApartment() {
|
|
23 var apartment = new StaApartment();
|
|
24 try {
|
|
25 Assert.IsNotNull(apartment.SyncContext);
|
|
26 Assert.Fail();
|
|
27 } catch (InvalidOperationException) {
|
|
28 // OK
|
|
29 }
|
|
30
|
|
31 apartment.Start().Join();
|
|
32 Assert.AreEqual(apartment.State, ExecutionState.Running);
|
|
33
|
|
34 Assert.IsNotNull(apartment.SyncContext);
|
|
35 apartment.Stop().Join();
|
|
36
|
|
37 Assert.IsTrue(apartment.State == ExecutionState.Disposed);
|
|
38 }
|
|
39
|
|
40 [TestMethod]
|
|
41 public void InvokeInApartment() {
|
|
42 var apartment = new StaApartment();
|
|
43
|
|
44 apartment.Start().Join();
|
|
45
|
|
46 var apType = apartment.Invoke(() => { return Thread.CurrentThread.GetApartmentState(); }).Join();
|
|
47 Assert.AreEqual(apType, ApartmentState.STA);
|
|
48
|
|
49 apartment.Stop().Join();
|
|
50 }
|
|
51 }
|
|
52 }
|