-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01)IntroDemo.cs
More file actions
54 lines (43 loc) · 1.94 KB
/
Copy path01)IntroDemo.cs
File metadata and controls
54 lines (43 loc) · 1.94 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
namespace ExtensionsTests.Exceptions;
public class IntroDemo
{
public static void WILL_NOT_COMPILE() {
//throw new InvalidOperation();
//throw new InvalidOperation("message");
//throw new NotImplemented();
//throw new NotSupported("test");
//throw new Argument(1, 2, 3);
//throw new Argument("can't ", null);
}
[Test]
public void System() {
var exc = Assert.Throws<NotImplementedException>(() => NotImplemented.Throw("Test of exception itself"));
Assert.That(exc?.Message, Is.Not.Empty);
var inOp = Assert.Throws<InvalidOperationException>(() => InvalidOperation.Throw(""));
Assert.That(inOp.Message, Is.Empty);
var noSup = Assert.Throws<NotSupportedException>(() => NotSupported.Throw(nameof(IntroDemo)));
Assert.That(noSup?.Message, Is.EqualTo(nameof(IntroDemo)));
var argNull = Assert.Throws<ArgumentNullException>(() => ArgumentNull.Throw("<NAME OF ARG_PROTO>"));
}
[Test]
public void NonStringMessage() {
var plane = 747;
var argExc = Assert.Throws<ArgumentException>(() => Argument.Throw(plane));
Assert.That(argExc?.Message, Does.Contain(nameof(plane)));
Assert.That(argExc?.Message, Does.Contain("747"));
var exc = Assert.Throws<EntityNotFound>(() => EntityNotFound.Throw(new Dummy()));
Assert.That(exc?.Message, Does.Contain(Dummy.ToStringProduced));
}
[Test]
public void Custom() {
Assert.Throws<UniqueConstraint>(() => UniqueConstraint.Throw("The same key <...> exists"));
Assert.Throws<EntityNotFound>(() => EntityNotFound.Throw($"unid: ..., name: ..."));
Assert.Throws<DuplicatedArgument>(() =>
DuplicatedArgument.Throw("Repeated IDs found: <..., ...>"));
}
private class Dummy
{
public const string ToStringProduced = "TO_STRING_TEST_MESSAGE";
public override string ToString() => ToStringProduced;
}
}