@@ -1,19 +1,20 | |||||
1 | syntax: glob |
|
1 | syntax: glob | |
2 | Implab.Test/bin/ |
|
2 | Implab.Test/bin/ | |
3 | *.user |
|
3 | *.user | |
4 | Implab.Test/obj/ |
|
4 | Implab.Test/obj/ | |
5 | *.userprefs |
|
5 | *.userprefs | |
6 | Implab/bin/ |
|
6 | Implab/bin/ | |
7 | Implab/obj/ |
|
7 | Implab/obj/ | |
8 | TestResults/ |
|
8 | TestResults/ | |
9 | Implab.Fx/obj/ |
|
9 | Implab.Fx/obj/ | |
10 | Implab.Fx/bin/ |
|
10 | Implab.Fx/bin/ | |
11 | Implab.Fx.Test/bin/ |
|
11 | Implab.Fx.Test/bin/ | |
12 | Implab.Fx.Test/obj/ |
|
12 | Implab.Fx.Test/obj/ | |
13 | _ReSharper.Implab/ |
|
13 | _ReSharper.Implab/ | |
14 | Implab.Diagnostics.Interactive/bin/ |
|
14 | Implab.Diagnostics.Interactive/bin/ | |
15 | Implab.Diagnostics.Interactive/obj/ |
|
15 | Implab.Diagnostics.Interactive/obj/ | |
16 | MonoPlay/bin/ |
|
16 | MonoPlay/bin/ | |
17 | MonoPlay/obj/ |
|
17 | MonoPlay/obj/ | |
18 | Implab.Test/Implab.Format.Test/bin/ |
|
18 | Implab.Test/Implab.Format.Test/bin/ | |
19 | Implab.Test/Implab.Format.Test/obj/ |
|
19 | Implab.Test/Implab.Format.Test/obj/ | |
|
20 | *.suo |
@@ -1,82 +1,84 | |||||
1 | ο»Ώ<?xml version="1.0" encoding="utf-8"?> |
|
1 | ο»Ώ<?xml version="1.0" encoding="utf-8"?> | |
2 | <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
2 | <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
3 | <PropertyGroup> |
|
3 | <PropertyGroup> | |
4 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
4 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
5 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
5 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |
6 | <ProductVersion>8.0.30703</ProductVersion> |
|
6 | <ProductVersion>8.0.30703</ProductVersion> | |
7 | <SchemaVersion>2.0</SchemaVersion> |
|
7 | <SchemaVersion>2.0</SchemaVersion> | |
8 | <ProjectGuid>{63F92C0C-61BF-48C0-A377-8D67C3C661D0}</ProjectGuid> |
|
8 | <ProjectGuid>{63F92C0C-61BF-48C0-A377-8D67C3C661D0}</ProjectGuid> | |
9 | <OutputType>Library</OutputType> |
|
9 | <OutputType>Library</OutputType> | |
10 | <AppDesignerFolder>Properties</AppDesignerFolder> |
|
10 | <AppDesignerFolder>Properties</AppDesignerFolder> | |
11 | <RootNamespace>Implab.Test</RootNamespace> |
|
11 | <RootNamespace>Implab.Test</RootNamespace> | |
12 | <AssemblyName>Implab.Test</AssemblyName> |
|
12 | <AssemblyName>Implab.Test</AssemblyName> | |
13 | <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|
13 | <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |
14 | <FileAlignment>512</FileAlignment> |
|
14 | <FileAlignment>512</FileAlignment> | |
15 | <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|
15 | <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | |
16 | <TargetFrameworkProfile /> |
|
16 | <TargetFrameworkProfile /> | |
17 | </PropertyGroup> |
|
17 | </PropertyGroup> | |
18 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
18 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
19 | <DebugSymbols>true</DebugSymbols> |
|
19 | <DebugSymbols>true</DebugSymbols> | |
20 | <DebugType>full</DebugType> |
|
20 | <DebugType>full</DebugType> | |
21 | <Optimize>false</Optimize> |
|
21 | <Optimize>false</Optimize> | |
22 | <OutputPath>bin\Debug\</OutputPath> |
|
22 | <OutputPath>bin\Debug\</OutputPath> | |
23 | <DefineConstants>DEBUG;TRACE</DefineConstants> |
|
23 | <DefineConstants>DEBUG;TRACE</DefineConstants> | |
24 | <ErrorReport>prompt</ErrorReport> |
|
24 | <ErrorReport>prompt</ErrorReport> | |
25 | <WarningLevel>4</WarningLevel> |
|
25 | <WarningLevel>4</WarningLevel> | |
26 | <Prefer32Bit>false</Prefer32Bit> |
|
26 | <Prefer32Bit>false</Prefer32Bit> | |
27 | </PropertyGroup> |
|
27 | </PropertyGroup> | |
28 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|
28 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
29 | <DebugType>pdbonly</DebugType> |
|
29 | <DebugType>pdbonly</DebugType> | |
30 | <Optimize>true</Optimize> |
|
30 | <Optimize>true</Optimize> | |
31 | <OutputPath>bin\Release\</OutputPath> |
|
31 | <OutputPath>bin\Release\</OutputPath> | |
32 | <DefineConstants>TRACE</DefineConstants> |
|
32 | <DefineConstants>TRACE</DefineConstants> | |
33 | <ErrorReport>prompt</ErrorReport> |
|
33 | <ErrorReport>prompt</ErrorReport> | |
34 | <WarningLevel>4</WarningLevel> |
|
34 | <WarningLevel>4</WarningLevel> | |
35 | <Prefer32Bit>false</Prefer32Bit> |
|
35 | <Prefer32Bit>false</Prefer32Bit> | |
36 | </PropertyGroup> |
|
36 | </PropertyGroup> | |
37 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' "> |
|
37 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' "> | |
38 | <DebugSymbols>true</DebugSymbols> |
|
38 | <DebugSymbols>true</DebugSymbols> | |
39 | <DebugType>full</DebugType> |
|
39 | <DebugType>full</DebugType> | |
40 | <Optimize>false</Optimize> |
|
40 | <Optimize>false</Optimize> | |
41 | <OutputPath>bin\Debug\</OutputPath> |
|
41 | <OutputPath>bin\Debug\</OutputPath> | |
42 | <DefineConstants>DEBUG;TRACE</DefineConstants> |
|
42 | <DefineConstants>DEBUG;TRACE</DefineConstants> | |
43 | <ErrorReport>prompt</ErrorReport> |
|
43 | <ErrorReport>prompt</ErrorReport> | |
44 | <WarningLevel>4</WarningLevel> |
|
44 | <WarningLevel>4</WarningLevel> | |
45 | <Prefer32Bit>false</Prefer32Bit> |
|
45 | <Prefer32Bit>false</Prefer32Bit> | |
46 | </PropertyGroup> |
|
46 | </PropertyGroup> | |
47 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' "> |
|
47 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' "> | |
48 | <DebugType>pdbonly</DebugType> |
|
48 | <DebugType>pdbonly</DebugType> | |
49 | <Optimize>true</Optimize> |
|
49 | <Optimize>true</Optimize> | |
50 | <OutputPath>bin\Release\</OutputPath> |
|
50 | <OutputPath>bin\Release\</OutputPath> | |
51 | <DefineConstants>TRACE</DefineConstants> |
|
51 | <DefineConstants>TRACE</DefineConstants> | |
52 | <ErrorReport>prompt</ErrorReport> |
|
52 | <ErrorReport>prompt</ErrorReport> | |
53 | <WarningLevel>4</WarningLevel> |
|
53 | <WarningLevel>4</WarningLevel> | |
54 | <Prefer32Bit>false</Prefer32Bit> |
|
54 | <Prefer32Bit>false</Prefer32Bit> | |
55 | </PropertyGroup> |
|
55 | </PropertyGroup> | |
56 | <ItemGroup> |
|
56 | <ItemGroup> | |
57 | <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
|
57 | <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |
58 | <Reference Include="System" /> |
|
58 | <Reference Include="System" /> | |
59 | <Reference Include="System.Core"> |
|
59 | <Reference Include="System.Core"> | |
60 | <RequiredTargetFramework>3.5</RequiredTargetFramework> |
|
60 | <RequiredTargetFramework>3.5</RequiredTargetFramework> | |
61 | </Reference> |
|
61 | </Reference> | |
62 | </ItemGroup> |
|
62 | </ItemGroup> | |
63 | <ItemGroup> |
|
63 | <ItemGroup> | |
64 | <Compile Include="AsyncTests.cs" /> |
|
64 | <Compile Include="AsyncTests.cs" /> | |
|
65 | <Compile Include="CancelationTests.cs" /> | |||
65 | <Compile Include="PromiseHelper.cs" /> |
|
66 | <Compile Include="PromiseHelper.cs" /> | |
66 | <Compile Include="Properties\AssemblyInfo.cs" /> |
|
67 | <Compile Include="Properties\AssemblyInfo.cs" /> | |
|
68 | <Compile Include="RunnableComponentTests.cs" /> | |||
67 | </ItemGroup> |
|
69 | </ItemGroup> | |
68 | <ItemGroup> |
|
70 | <ItemGroup> | |
69 | <ProjectReference Include="..\Implab\Implab.csproj"> |
|
71 | <ProjectReference Include="..\Implab\Implab.csproj"> | |
70 | <Project>{99B95D0D-9CF9-4F70-8ADF-F4D0AA5CB0D9}</Project> |
|
72 | <Project>{99B95D0D-9CF9-4F70-8ADF-F4D0AA5CB0D9}</Project> | |
71 | <Name>Implab</Name> |
|
73 | <Name>Implab</Name> | |
72 | </ProjectReference> |
|
74 | </ProjectReference> | |
73 | </ItemGroup> |
|
75 | </ItemGroup> | |
74 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
|
76 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | |
75 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|
77 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |
76 | Other similar extension points exist, see Microsoft.Common.targets. |
|
78 | Other similar extension points exist, see Microsoft.Common.targets. | |
77 | <Target Name="BeforeBuild"> |
|
79 | <Target Name="BeforeBuild"> | |
78 | </Target> |
|
80 | </Target> | |
79 | <Target Name="AfterBuild"> |
|
81 | <Target Name="AfterBuild"> | |
80 | </Target> |
|
82 | </Target> | |
81 | --> |
|
83 | --> | |
82 | </Project> No newline at end of file |
|
84 | </Project> |
@@ -1,194 +1,195 | |||||
1 | using System; |
|
1 | using System; | |
2 | using System.Reflection; |
|
2 | using System.Reflection; | |
3 | using System.Threading; |
|
3 | using System.Threading; | |
4 | using Implab.Parallels; |
|
4 | using Implab.Parallels; | |
5 | using Implab.Components; |
|
5 | using Implab.Components; | |
6 |
|
6 | |||
7 | #if MONO |
|
7 | #if MONO | |
8 |
|
8 | |||
9 | using NUnit.Framework; |
|
9 | using NUnit.Framework; | |
10 | using TestClassAttribute = NUnit.Framework.TestFixtureAttribute; |
|
10 | using TestClassAttribute = NUnit.Framework.TestFixtureAttribute; | |
11 | using TestMethodAttribute = NUnit.Framework.TestAttribute; |
|
11 | using TestMethodAttribute = NUnit.Framework.TestAttribute; | |
12 |
|
12 | using AssertFailedException = NUnit.Framework.AssertionException; | ||
13 | #else |
|
13 | #else | |
14 |
|
14 | |||
15 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
|
15 | using Microsoft.VisualStudio.TestTools.UnitTesting; | |
16 |
|
16 | |||
17 | #endif |
|
17 | #endif | |
18 |
|
18 | |||
19 | namespace Implab.Test { |
|
19 | namespace Implab.Test { | |
20 | [TestClass] |
|
20 | [TestClass] | |
21 | public class RunnableComponentTests { |
|
21 | public class RunnableComponentTests { | |
22 |
|
22 | |||
23 | static void ShouldThrow(Action action) { |
|
23 | static void ShouldThrow(Action action) { | |
24 | try { |
|
24 | try { | |
25 | action(); |
|
25 | action(); | |
26 | Assert.Fail(); |
|
26 | Assert.Fail(); | |
27 |
} catch(Assert |
|
27 | } catch (AssertFailedException) { | |
28 | throw; |
|
28 | throw; | |
29 | } catch { |
|
29 | } catch { | |
30 | } |
|
30 | } | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | class Runnable : RunnableComponent { |
|
33 | class Runnable : RunnableComponent { | |
34 | public Runnable(bool initialized) : base(initialized) { |
|
34 | public Runnable(bool initialized) : base(initialized) { | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | public Action MockInit { |
|
37 | public Action MockInit { | |
38 | get; |
|
38 | get; | |
39 | set; |
|
39 | set; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | public Func<IPromise> MockStart { |
|
42 | public Func<IPromise> MockStart { | |
43 | get; |
|
43 | get; | |
44 | set; |
|
44 | set; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | public Func<IPromise> MockStop { |
|
47 | public Func<IPromise> MockStop { | |
48 | get; |
|
48 | get; | |
49 | set; |
|
49 | set; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | protected override IPromise OnStart() { |
|
52 | protected override IPromise OnStart() { | |
53 | return MockStart != null ? MockStart() : base.OnStart(); |
|
53 | return MockStart != null ? MockStart() : base.OnStart(); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | protected override IPromise OnStop() { |
|
56 | protected override IPromise OnStop() { | |
57 | return MockStop != null ? MockStop() : base.OnStart(); |
|
57 | return MockStop != null ? MockStop() : base.OnStart(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | protected override void OnInitialize() { |
|
60 | protected override void OnInitialize() { | |
61 | if (MockInit != null) |
|
61 | if (MockInit != null) | |
62 | MockInit(); |
|
62 | MockInit(); | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | [TestMethod] |
|
66 | [TestMethod] | |
67 | public void NormalFlowTest() { |
|
67 | public void NormalFlowTest() { | |
68 | var comp = new Runnable(false); |
|
68 | var comp = new Runnable(false); | |
69 |
|
69 | |||
70 | Assert.AreEqual(ExecutionState.Created, comp.State); |
|
70 | Assert.AreEqual(ExecutionState.Created, comp.State); | |
71 |
|
71 | |||
72 | comp.Init(); |
|
72 | comp.Init(); | |
73 |
|
73 | |||
74 | Assert.AreEqual(ExecutionState.Ready, comp.State); |
|
74 | Assert.AreEqual(ExecutionState.Ready, comp.State); | |
75 |
|
75 | |||
76 | comp.Start().Join(1000); |
|
76 | comp.Start().Join(1000); | |
77 |
|
77 | |||
78 | Assert.AreEqual(ExecutionState.Running, comp.State); |
|
78 | Assert.AreEqual(ExecutionState.Running, comp.State); | |
79 |
|
79 | |||
80 | comp.Stop().Join(1000); |
|
80 | comp.Stop().Join(1000); | |
81 |
|
81 | |||
82 | Assert.AreEqual(ExecutionState.Disposed, comp.State); |
|
82 | Assert.AreEqual(ExecutionState.Disposed, comp.State); | |
83 |
|
83 | |||
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | [TestMethod] |
|
86 | [TestMethod] | |
87 | public void InitFailTest() { |
|
87 | public void InitFailTest() { | |
88 | var comp = new Runnable(false) { |
|
88 | var comp = new Runnable(false) { | |
89 | MockInit = () => { |
|
89 | MockInit = () => { | |
90 | throw new Exception("BAD"); |
|
90 | throw new Exception("BAD"); | |
91 | } |
|
91 | } | |
92 | }; |
|
92 | }; | |
93 |
|
93 | |||
94 | ShouldThrow(() => comp.Start()); |
|
94 | ShouldThrow(() => comp.Start()); | |
95 | ShouldThrow(() => comp.Stop()); |
|
95 | ShouldThrow(() => comp.Stop()); | |
96 | Assert.AreEqual(ExecutionState.Created, comp.State); |
|
96 | Assert.AreEqual(ExecutionState.Created, comp.State); | |
97 |
|
97 | |||
98 | ShouldThrow(comp.Init); |
|
98 | ShouldThrow(comp.Init); | |
99 |
|
99 | |||
100 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
100 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
101 |
|
101 | |||
102 | ShouldThrow(() => comp.Start()); |
|
102 | ShouldThrow(() => comp.Start()); | |
103 | ShouldThrow(() => comp.Stop()); |
|
103 | ShouldThrow(() => comp.Stop()); | |
104 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
104 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
105 |
|
105 | |||
106 | comp.Dispose(); |
|
106 | comp.Dispose(); | |
107 | Assert.AreEqual(ExecutionState.Disposed, comp.State); |
|
107 | Assert.AreEqual(ExecutionState.Disposed, comp.State); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | [TestMethod] |
|
110 | [TestMethod] | |
111 | public void DisposedTest() { |
|
111 | public void DisposedTest() { | |
112 |
|
112 | |||
113 | var comp = new Runnable(false); |
|
113 | var comp = new Runnable(false); | |
114 | comp.Dispose(); |
|
114 | comp.Dispose(); | |
115 |
|
115 | |||
116 | ShouldThrow(() => comp.Start()); |
|
116 | ShouldThrow(() => comp.Start()); | |
117 | ShouldThrow(() => comp.Stop()); |
|
117 | ShouldThrow(() => comp.Stop()); | |
118 | ShouldThrow(comp.Init); |
|
118 | ShouldThrow(comp.Init); | |
119 |
|
119 | |||
120 | Assert.AreEqual(ExecutionState.Disposed, comp.State); |
|
120 | Assert.AreEqual(ExecutionState.Disposed, comp.State); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | [TestMethod] |
|
123 | [TestMethod] | |
124 | public void StartCancelTest() { |
|
124 | public void StartCancelTest() { | |
125 | var comp = new Runnable(true) { |
|
125 | var comp = new Runnable(true) { | |
126 | MockStart = () => PromiseHelper.Sleep(100000, 0) |
|
126 | MockStart = () => PromiseHelper.Sleep(100000, 0) | |
127 | }; |
|
127 | }; | |
128 |
|
128 | |||
129 | var p = comp.Start(); |
|
129 | var p = comp.Start(); | |
130 | Assert.AreEqual(ExecutionState.Starting, comp.State); |
|
130 | Assert.AreEqual(ExecutionState.Starting, comp.State); | |
131 | p.Cancel(); |
|
131 | p.Cancel(); | |
132 | ShouldThrow(() => p.Join(1000)); |
|
132 | ShouldThrow(() => p.Join(1000)); | |
133 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
133 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
134 | Assert.IsInstanceOfType(typeof(OperationCanceledException), comp.LastError); |
|
134 | ||
|
135 | Assert.IsInstanceOfType(comp.LastError, typeof(OperationCanceledException)); | |||
135 |
|
136 | |||
136 | comp.Dispose(); |
|
137 | comp.Dispose(); | |
137 | } |
|
138 | } | |
138 |
|
139 | |||
139 | [TestMethod] |
|
140 | [TestMethod] | |
140 | public void StartStopTest() { |
|
141 | public void StartStopTest() { | |
141 | var stop = new Signal(); |
|
142 | var stop = new Signal(); | |
142 | var comp = new Runnable(true) { |
|
143 | var comp = new Runnable(true) { | |
143 | MockStart = () => PromiseHelper.Sleep(100000, 0), |
|
144 | MockStart = () => PromiseHelper.Sleep(100000, 0), | |
144 | MockStop = () => AsyncPool.RunThread(stop.Wait) |
|
145 | MockStop = () => AsyncPool.RunThread(stop.Wait) | |
145 | }; |
|
146 | }; | |
146 |
|
147 | |||
147 | var p1 = comp.Start(); |
|
148 | var p1 = comp.Start(); | |
148 | var p2 = comp.Stop(); |
|
149 | var p2 = comp.Stop(); | |
149 | // should enter stopping state |
|
150 | // should enter stopping state | |
150 |
|
151 | |||
151 | ShouldThrow(p1.Join); |
|
152 | ShouldThrow(p1.Join); | |
152 | Assert.IsTrue(p1.IsCancelled); |
|
153 | Assert.IsTrue(p1.IsCancelled); | |
153 | Assert.AreEqual(ExecutionState.Stopping, comp.State); |
|
154 | Assert.AreEqual(ExecutionState.Stopping, comp.State); | |
154 |
|
155 | |||
155 | stop.Set(); |
|
156 | stop.Set(); | |
156 | p2.Join(1000); |
|
157 | p2.Join(1000); | |
157 | Assert.AreEqual(ExecutionState.Disposed, comp.State); |
|
158 | Assert.AreEqual(ExecutionState.Disposed, comp.State); | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | [TestMethod] |
|
161 | [TestMethod] | |
161 | public void StartStopFailTest() { |
|
162 | public void StartStopFailTest() { | |
162 | var comp = new Runnable(true) { |
|
163 | var comp = new Runnable(true) { | |
163 | MockStart = () => PromiseHelper.Sleep(100000, 0).Then(null,null,x => { throw new Exception("I'm dead"); }) |
|
164 | MockStart = () => PromiseHelper.Sleep(100000, 0).Then(null,null,x => { throw new Exception("I'm dead"); }) | |
164 | }; |
|
165 | }; | |
165 |
|
166 | |||
166 | comp.Start(); |
|
167 | comp.Start(); | |
167 | var p = comp.Stop(); |
|
168 | var p = comp.Stop(); | |
168 | // if Start fails to cancel, should fail to stop |
|
169 | // if Start fails to cancel, should fail to stop | |
169 | ShouldThrow(() => p.Join(1000)); |
|
170 | ShouldThrow(() => p.Join(1000)); | |
170 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
171 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
171 | Assert.IsNotNull(comp.LastError); |
|
172 | Assert.IsNotNull(comp.LastError); | |
172 | Assert.AreEqual("I'm dead", comp.LastError.Message); |
|
173 | Assert.AreEqual("I'm dead", comp.LastError.Message); | |
173 | } |
|
174 | } | |
174 |
|
175 | |||
175 | [TestMethod] |
|
176 | [TestMethod] | |
176 | public void StopCancelTest() { |
|
177 | public void StopCancelTest() { | |
177 | var comp = new Runnable(true) { |
|
178 | var comp = new Runnable(true) { | |
178 | MockStop = () => PromiseHelper.Sleep(100000, 0) |
|
179 | MockStop = () => PromiseHelper.Sleep(100000, 0) | |
179 | }; |
|
180 | }; | |
180 |
|
181 | |||
181 | comp.Start(); |
|
182 | comp.Start(); | |
182 | var p = comp.Stop(); |
|
183 | var p = comp.Stop(); | |
183 | Assert.AreEqual(ExecutionState.Stopping, comp.State); |
|
184 | Assert.AreEqual(ExecutionState.Stopping, comp.State); | |
184 | p.Cancel(); |
|
185 | p.Cancel(); | |
185 | ShouldThrow(() => p.Join(1000)); |
|
186 | ShouldThrow(() => p.Join(1000)); | |
186 | Assert.AreEqual(ExecutionState.Failed, comp.State); |
|
187 | Assert.AreEqual(ExecutionState.Failed, comp.State); | |
187 |
Assert.IsInstanceOfType(typeof(OperationCanceledException) |
|
188 | Assert.IsInstanceOfType(comp.LastError, typeof(OperationCanceledException)); | |
188 |
|
189 | |||
189 | comp.Dispose(); |
|
190 | comp.Dispose(); | |
190 | } |
|
191 | } | |
191 |
|
192 | |||
192 | } |
|
193 | } | |
193 | } |
|
194 | } | |
194 |
|
195 |
General Comments 0
You need to be logged in to leave comments.
Login now