annotate Implab.Fx.Test/StaApartmentTests.cs @ 216:1e082fb67a46 v2

Fixed component container
author cin
date Tue, 25 Apr 2017 19:51:33 +0300
parents 5dc21f6a3222
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
210
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
1 using System;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
2 using System.Reflection;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
3 using System.Threading;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
4 using Implab.Parallels;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
5 using Implab.Components;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
6
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
7 #if MONO
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
8
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
9 using NUnit.Framework;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
10 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
11 using TestMethodAttribute = NUnit.Framework.TestAttribute;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
12 using AssertFailedException = NUnit.Framework.AssertionException;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
13 #else
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
14
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
15 using Microsoft.VisualStudio.TestTools.UnitTesting;
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
16
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
17 #endif
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
18 namespace Implab.Fx.Test {
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
19 [TestClass]
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
20 public class StaApartmentTests {
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
21 [TestMethod]
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
22 public void CreateDestroyApartment() {
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
23 var apartment = new StaApartment();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
24 try {
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
25 Assert.IsNotNull(apartment.SyncContext);
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
26 Assert.Fail();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
27 } catch (InvalidOperationException) {
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
28 // OK
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
29 }
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
30
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
31 apartment.Start().Join();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
32 Assert.AreEqual(apartment.State, ExecutionState.Running);
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
33
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
34 Assert.IsNotNull(apartment.SyncContext);
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
35 apartment.Stop().Join();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
36
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
37 Assert.IsTrue(apartment.State == ExecutionState.Disposed);
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
38 }
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
39
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
40 [TestMethod]
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
41 public void InvokeInApartment() {
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
42 var apartment = new StaApartment();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
43
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
44 apartment.Start().Join();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
45
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
46 var apType = apartment.Invoke(() => { return Thread.CurrentThread.GetApartmentState(); }).Join();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
47 Assert.AreEqual(apType, ApartmentState.STA);
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
48
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
49 apartment.Stop().Join();
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
50 }
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
51 }
5dc21f6a3222 Code review for RunnableComponent
cin
parents:
diff changeset
52 }