-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExceptionTest.cs
More file actions
61 lines (54 loc) · 1.67 KB
/
ExceptionTest.cs
File metadata and controls
61 lines (54 loc) · 1.67 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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using DirectSQL.SqlLite;
using System.Threading.Tasks;
using System;
using DirectSQL;
namespace TestSqlLiteDatabase
{
[TestClass]
public class ExceptionTest
{
[TestMethod]
public void TestException()
{
const String ERROR_MSG = "Intentinal Exception";
try
{
SqlLiteDatabase db = new SqlLiteDatabase("Data Source=:memory:");
db.Process((connection, transaction) =>
{
throw new ApplicationException(ERROR_MSG);
});
Assert.Fail();
}
catch (DatabaseException ex)
{
Assert.AreEqual(ex.InnerException.Message, ERROR_MSG);
}
}
[TestMethod]
public void TestExceptionAsync()
{
const String ERROR_MSG = "Intentinal Exception for test async";
SqlLiteDatabase db = new SqlLiteDatabase("Data Source=:memory:");
Task task = db.ProcessAsync(async (connection, transaction) =>
{
await Task.Delay(1); //Dummy code to resolve warning in build.
throw new ApplicationException(ERROR_MSG);
});
try
{
task.Wait();
Assert.Fail();
}
catch (AggregateException aggregatedException)
{
Assert.AreEqual(
aggregatedException.InnerExceptions[0].InnerException.Message, //Only this happens
ERROR_MSG
);
}
}
}
}