-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMeadowAsserter.cs
128 lines (102 loc) · 4.03 KB
/
MeadowAsserter.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Threading.Tasks;
namespace Meadow.UnitTestTemplate
{
public class MeadowAsserter : Asserter
{
public static readonly MeadowAsserter Instance = new MeadowAsserter();
static readonly CollectionAsserter _collectionAsserter = new CollectionAsserter();
public CollectionAsserter Collection => _collectionAsserter;
public void StringContains(string value, string substring)
{
StringAssert.Contains(value, substring);
}
public void StringStartsWith(string value, string substring)
{
StringAssert.StartsWith(value, substring);
}
public void StringEndsWith(string value, string substring)
{
StringAssert.EndsWith(value, substring);
}
public void AreEqual(string expected, string actual)
{
Assert.AreEqual(expected, actual);
}
public void AreEqual<T>(IEnumerable<T> expected, IEnumerable<T> actual)
{
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
}
public void AreEqual(BigInteger expected, BigInteger actual)
{
Assert.AreEqual(expected, actual);
}
public Task<T> ThrowsExceptionAsync<T>(Func<Task> action) where T : Exception
{
return Assert.ThrowsExceptionAsync<T>(action);
}
public Task<T> ThrowsExceptionAsync<T>(Func<Task> action, string message) where T : Exception
{
return Assert.ThrowsExceptionAsync<T>(action, message);
}
public Task<T> ThrowsExceptionAsync<T>(Func<Task> action, string message, params object[] parameters) where T : Exception
{
return Assert.ThrowsExceptionAsync<T>(action, message, parameters);
}
public T ThrowsException<T>(Func<object> action) where T : Exception
{
return Assert.ThrowsException<T>(action);
}
public T ThrowsException<T>(Func<object> action, string message) where T : Exception
{
return Assert.ThrowsException<T>(action, message);
}
public T ThrowsException<T>(Func<object> action, string message, params object[] parameters) where T : Exception
{
return Assert.ThrowsException<T>(action, message, parameters);
}
public T ThrowsException<T>(Action action) where T : Exception
{
return Assert.ThrowsException<T>(action);
}
public T ThrowsException<T>(Action action, string message) where T : Exception
{
return Assert.ThrowsException<T>(action, message);
}
public T ThrowsException<T>(Action action, string message, params object[] parameters) where T : Exception
{
return Assert.ThrowsException<T>(action, message, parameters);
}
public string ReplaceNullChars(string input)
{
return Assert.ReplaceNullChars(input);
}
#if CHECK_CONSISTENCY
// Ensure this Assert class instance has all the methods that the static Assert class has.
static MeadowAsserter()
{
var originalMethods = typeof(Assert)
.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
.Where(m => !m.IsSpecialName)
.Select(m => m.ToString());
var thisMethods = typeof(MeadowAsserter)
.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
.Select(m => m.ToString());
foreach (var method in originalMethods)
{
var match = thisMethods.Contains(method);
if (!match)
{
throw new Exception();
}
}
}
#endif
}
}