forked from Jarno458/TsRandomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemTrackerUplinkFixture.cs
73 lines (64 loc) · 1.64 KB
/
ItemTrackerUplinkFixture.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Threading.Tasks;
using NUnit.Framework;
using TsRandomizer.ItemTracker;
namespace TsRandomizer.Tests
{
[TestFixture]
class ItemTrackerUplinkFixture
{
[Test]
public void Should_save_and_read_item_tracker_state()
{
var originalState = new ItemTrackerState
{
CardA = true,
Dash = true,
FireRing = true,
DoubleJump = true,
Timestop = false,
CardB = false,
PyramidKeys = false,
DinsFire = false
};
ItemTrackerUplink.UpdateState(originalState);
var retreivedState = ItemTrackerUplink.LoadState();
Assert.IsTrue(retreivedState.CardA);
Assert.IsTrue(retreivedState.Dash);
Assert.IsTrue(retreivedState.FireRing);
Assert.IsTrue(retreivedState.DoubleJump);
Assert.IsFalse(retreivedState.Timestop);
Assert.IsFalse(retreivedState.CardB);
Assert.IsFalse(retreivedState.PyramidKeys);
Assert.IsFalse(retreivedState.DinsFire);
}
[Test]
public void Parralel_read_and_writes_should_not_throw_exception()
{
var originalState = new ItemTrackerState
{
CardA = true,
Dash = true,
FireRing = true,
DoubleJump = true,
Timestop = false,
CardB = false,
PyramidKeys = false,
DinsFire = false
};
ItemTrackerUplink.UpdateState(originalState);
ItemTrackerUplink.LoadState();
var writer = Task.Factory.StartNew(() => {
for (int i = 0; i < 1000; i++)
ItemTrackerUplink.UpdateState(originalState);
});
var reader = Task.Factory.StartNew(() => {
for (int i = 0; i < 1000; i++)
{
var retreivedState = ItemTrackerUplink.LoadState();
Assert.IsTrue(retreivedState.CardA);
}
});
Task.WaitAll(writer, reader);
}
}
}