StaApartmentTests.cs
52 lines
| 1.5 KiB
| text/x-csharp
|
CSharpLexer
/ Implab.Fx.Test / StaApartmentTests.cs
cin
|
r210 | using System; | ||
using System.Reflection; | ||||
using System.Threading; | ||||
using Implab.Parallels; | ||||
using Implab.Components; | ||||
#if MONO | ||||
using NUnit.Framework; | ||||
using TestClassAttribute = NUnit.Framework.TestFixtureAttribute; | ||||
using TestMethodAttribute = NUnit.Framework.TestAttribute; | ||||
using AssertFailedException = NUnit.Framework.AssertionException; | ||||
#else | ||||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||
#endif | ||||
namespace Implab.Fx.Test { | ||||
[TestClass] | ||||
public class StaApartmentTests { | ||||
[TestMethod] | ||||
public void CreateDestroyApartment() { | ||||
var apartment = new StaApartment(); | ||||
try { | ||||
Assert.IsNotNull(apartment.SyncContext); | ||||
Assert.Fail(); | ||||
} catch (InvalidOperationException) { | ||||
// OK | ||||
} | ||||
apartment.Start().Join(); | ||||
Assert.AreEqual(apartment.State, ExecutionState.Running); | ||||
Assert.IsNotNull(apartment.SyncContext); | ||||
apartment.Stop().Join(); | ||||
Assert.IsTrue(apartment.State == ExecutionState.Disposed); | ||||
} | ||||
[TestMethod] | ||||
public void InvokeInApartment() { | ||||
var apartment = new StaApartment(); | ||||
apartment.Start().Join(); | ||||
var apType = apartment.Invoke(() => { return Thread.CurrentThread.GetApartmentState(); }).Join(); | ||||
Assert.AreEqual(apType, ApartmentState.STA); | ||||
apartment.Stop().Join(); | ||||
} | ||||
} | ||||
} | ||||