Added ApartmentState to threads + tests

This commit is contained in:
Ami Bar
2012-07-06 16:32:25 +03:00
parent 4ba09bfa3f
commit 10633fdf9f
4 changed files with 93 additions and 8 deletions
+1
View File
@@ -109,6 +109,7 @@
<Compile Include="AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TestThreadApartmentState.cs" />
<Compile Include="TestParallelMethods.cs" />
<Compile Include="TestFalseFillStateWithParams.cs" />
<Compile Include="TestFillStateWithParams.cs" />
+47
View File
@@ -0,0 +1,47 @@
using System.Threading;
using NUnit.Framework;
using Amib.Threading;
namespace SmartThreadPoolTests
{
/// <summary>
/// Summary description for TestThreadPriority.
/// </summary>
[TestFixture]
[Category("TestThreadApartment")]
public class TestThreadApartmentState
{
[Test]
public void TestSTA()
{
CheckApartmentState(ApartmentState.STA);
}
[Test]
public void TestMTA()
{
CheckApartmentState(ApartmentState.MTA);
}
private static void CheckApartmentState(ApartmentState requestApartmentState)
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.ApartmentState = requestApartmentState;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
IWorkItemResult<ApartmentState> wir = stp.QueueWorkItem(() => GetCurrentThreadApartmentState());
ApartmentState resultApartmentState = wir.GetResult();
stp.WaitForIdle();
Assert.AreEqual(requestApartmentState, resultApartmentState);
}
private static ApartmentState GetCurrentThreadApartmentState()
{
return Thread.CurrentThread.GetApartmentState();
}
}
}