forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromiseTest.cs
52 lines (47 loc) · 1.43 KB
/
PromiseTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Simple.Data.UnitTest
{
using System.Threading;
using NUnit.Framework;
[TestFixture]
public class PromiseTest
{
[Test]
public void PromiseShouldHaveHasValueFalseWhenCreated()
{
Action<int> setAction;
var actual = Promise<int>.Create(out setAction);
Assert.IsFalse(actual.HasValue);
}
[Test]
public void PromiseShouldHaveValueAfterSetActionIsCalled()
{
Action<int> setAction;
var actual = Promise<int>.Create(out setAction);
setAction(42);
Assert.IsTrue(actual.HasValue);
Assert.AreEqual(42, actual.Value);
}
[Test]
public void PromiseShouldImplicitlyCastToType()
{
Action<int> setAction;
var actual = Promise<int>.Create(out setAction);
setAction(42);
Assert.AreEqual(42, actual);
}
[Test]
public void PromiseShouldSpinWhenValueAccessedButNotSet()
{
Action<int> setAction;
var actual = Promise<int>.Create(out setAction);
using (new Timer(_ => setAction(42), null, 100, Timeout.Infinite))
{
Assert.AreEqual(42, actual.Value);
}
}
}
}