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