##// END OF EJS Templates
sync
sync

File last commit:

r4:381095ad0a69 default
r9:c82e0dfbb4dd promises
Show More
AsyncTests.cs
101 lines | 2.0 KiB | text/x-csharp | CSharpLexer
cin
Implab.Fx: implemented animation object...
r4 using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Implab;
using System.Reflection;
using System.Threading;
namespace Implab.Tests
{
[TestClass]
public class AsyncTests
{
[TestMethod]
public void ResolveTest ()
{
int res = -1;
var p = new Promise<int> ();
p.Then (x => res = x);
p.Resolve (100);
Assert.AreEqual (res, 100);
user@factory.site.local
initial commit...
r0 }
cin
Implab.Fx: implemented animation object...
r4 [TestMethod]
public void RejectTest ()
{
int res = -1;
Exception err = null;
var p = new Promise<int> ();
p.Then (x => res = x, e => err = e);
p.Reject (new ApplicationException ("error"));
Assert.AreEqual (res, -1);
Assert.AreEqual (err.Message, "error");
user@factory.site.local
initial commit...
r0 }
cin
Implab.Fx: implemented animation object...
r4 [TestMethod]
public void JoinSuccessTest ()
{
var p = new Promise<int> ();
p.Resolve (100);
Assert.AreEqual (p.Join (), 100);
user@factory.site.local
initial commit...
r0 }
cin
Implab.Fx: implemented animation object...
r4 [TestMethod]
public void JoinFailTest ()
{
var p = new Promise<int> ();
p.Reject (new ApplicationException ("failed"));
try {
p.Join ();
throw new ApplicationException ("WRONG!");
} catch (TargetInvocationException err) {
Assert.AreEqual (err.InnerException.Message, "failed");
} catch {
Assert.Fail ("Got wrong excaption");
}
user@factory.site.local
initial commit...
r0 }
cin
Implab.Fx: implemented animation object...
r4 [TestMethod]
public void MapTest ()
{
var p = new Promise<int> ();
var p2 = p.Map (x => x.ToString ());
p.Resolve (100);
Assert.AreEqual (p2.Join (), "100");
user@factory.site.local
initial commit...
r0 }
cin
Implab.Fx: implemented animation object...
r4 [TestMethod]
public void ChainTest ()
{
var p1 = new Promise<int> ();
var p3 = p1.Chain (x => {
var p2 = new Promise<string> ();
p2.Resolve (x.ToString ());
return p2;
});
p1.Resolve (100);
Assert.AreEqual (p3.Join (), "100");
user@factory.site.local
initial commit...
r0 }
cin
Implab.Fx: implemented animation object...
r4 [TestMethod]
public void PoolTest ()
{
var pid = Thread.CurrentThread.ManagedThreadId;
var p = AsyncPool.Invoke (() => {
return Thread.CurrentThread.ManagedThreadId;
});
Assert.AreNotEqual (pid, p.Join ());
}
}
}