annotate Implab.Test/AsyncTests.cs @ 4:381095ad0a69

Implab.Fx: implemented animation object Implab.Fx: implemented transparency animation helper
author cin
date Tue, 17 Sep 2013 04:27:30 +0400
parents 279591fb4df3
children aa33d0bb8c0c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
1 using System;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
2 using Microsoft.VisualStudio.TestTools.UnitTesting;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
3 using Implab;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
4 using System.Reflection;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
5 using System.Threading;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
6
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
7 namespace Implab.Tests
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
8 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
9 [TestClass]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
10 public class AsyncTests
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
11 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
12 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
13 public void ResolveTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
14 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
15 int res = -1;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
16 var p = new Promise<int> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
17 p.Then (x => res = x);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
18 p.Resolve (100);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
19
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
20 Assert.AreEqual (res, 100);
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
21 }
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
22
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
23 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
24 public void RejectTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
25 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
26 int res = -1;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
27 Exception err = null;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
28
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
29 var p = new Promise<int> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
30 p.Then (x => res = x, e => err = e);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
31 p.Reject (new ApplicationException ("error"));
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
32
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
33 Assert.AreEqual (res, -1);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
34 Assert.AreEqual (err.Message, "error");
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
35
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
36 }
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
37
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
38 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
39 public void JoinSuccessTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
40 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
41 var p = new Promise<int> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
42 p.Resolve (100);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
43 Assert.AreEqual (p.Join (), 100);
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
44 }
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
45
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
46 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
47 public void JoinFailTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
48 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
49 var p = new Promise<int> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
50 p.Reject (new ApplicationException ("failed"));
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
51
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
52 try {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
53 p.Join ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
54 throw new ApplicationException ("WRONG!");
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
55 } catch (TargetInvocationException err) {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
56 Assert.AreEqual (err.InnerException.Message, "failed");
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
57 } catch {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
58 Assert.Fail ("Got wrong excaption");
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
59 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
60 }
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
61
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
62 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
63 public void MapTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
64 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
65 var p = new Promise<int> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
66
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
67 var p2 = p.Map (x => x.ToString ());
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
68 p.Resolve (100);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
69
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
70 Assert.AreEqual (p2.Join (), "100");
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
71 }
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
72
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
73 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
74 public void ChainTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
75 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
76 var p1 = new Promise<int> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
77
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
78 var p3 = p1.Chain (x => {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
79 var p2 = new Promise<string> ();
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
80 p2.Resolve (x.ToString ());
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
81 return p2;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
82 });
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
83
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
84 p1.Resolve (100);
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
85
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
86 Assert.AreEqual (p3.Join (), "100");
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
87 }
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
88
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
89 [TestMethod]
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
90 public void PoolTest ()
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
91 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
92 var pid = Thread.CurrentThread.ManagedThreadId;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
93 var p = AsyncPool.Invoke (() => {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
94 return Thread.CurrentThread.ManagedThreadId;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
95 });
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
96
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
97 Assert.AreNotEqual (pid, p.Join ());
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
98 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
99 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
100 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
101