Repository navigation
Expand file tree
/
Copy pathTestBase.cs
More file actions
101 lines (84 loc) · 2.7 KB
/
Copy pathTestBase.cs
File metadata and controls
101 lines (84 loc) · 2.7 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections;
using System.Reactive.Subjects;
using System.Text;
public class TestBase
{
class Output : ITestOutputHelper
{
public void WriteLine(string message)
{
Console.WriteLine(message);
}
public void WriteLine(string format, params object[] args)
{
Console.WriteLine(format, args);
}
}
readonly ITestOutputHelper output;
protected readonly StringBuilder testOutput = new StringBuilder();
protected DateTimeOffset Now = new DateTimeOffset(0, TimeSpan.FromTicks(0));
public TestBase()
{
output = new Output();
}
public TestBase(ITestOutputHelper output)
{
this.output = output;
}
protected void Dump(string msg)
{
output?.WriteLine(msg);
testOutput.AppendLine(msg);
}
protected void Dump(object prefix, object thing)
{
output?.WriteLine(string.Format("{0} - {1}", prefix, thing));
testOutput.AppendLine(string.Format("{0} - {1}", prefix, thing));
}
protected void Dump(object thing)
{
output?.WriteLine(thing.ToString());
testOutput.AppendLine(thing.ToString());
}
protected void Dump(string title, IEnumerable col)
{
output?.WriteLine(title);
testOutput.AppendLine(title);
var i = 0;
foreach (var l in col)
Dump(i++, l);
}
protected void Dump(IEnumerable col)
{
Dump("Dumping", col);
}
protected bool Compare(Thing thing1, Thing thing2)
{
return Equals(thing1, thing2) && thing1.Title == thing2.Title && thing1.CreatedAt == thing2.CreatedAt && thing1.UpdatedAt == thing2.UpdatedAt;
}
protected void Add(Subject<Thing> source, Thing item)
{
source.OnNext(item);
}
protected Thing GetThing(int id)
{
return new Thing { Number = id };
}
protected Thing GetThing(int id, int minutes)
{
return new Thing { Number = id, Title = "Run 1", CreatedAt = Now + TimeSpan.FromMinutes(minutes), UpdatedAt = Now + TimeSpan.FromMinutes(minutes) };
}
protected Thing GetThing(int id, int minutesc, int minutesu)
{
return new Thing { Number = id, Title = "Run 1", CreatedAt = Now + TimeSpan.FromMinutes(minutesc), UpdatedAt = Now + TimeSpan.FromMinutes(minutesu) };
}
protected Thing GetThing(int id, string title)
{
return new Thing { Number = id, Title = "Run 1" };
}
protected Thing GetThing(int id, int minutesc, int minutesu, string title)
{
return new Thing { Number = id, Title = title, CreatedAt = Now + TimeSpan.FromMinutes(minutesc), UpdatedAt = Now + TimeSpan.FromMinutes(minutesu) };
}
}