forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdoAdapterExceptionTest.cs
More file actions
88 lines (77 loc) · 3.37 KB
/
AdoAdapterExceptionTest.cs
File metadata and controls
88 lines (77 loc) · 3.37 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
namespace Simple.Data.Ado.Test
{
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using NUnit.Framework;
[TestFixture]
public class AdoAdapterExceptionTest
{
[Test]
public void EmptyConstructorShouldSetAdapterType()
{
var actual = new AdoAdapterException();
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
}
[Test]
public void SingleStringConstructorShouldSetMessageAndAdapterType()
{
var actual = new AdoAdapterException("Foo");
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
Assert.AreEqual("Foo", actual.Message);
}
[Test]
public void StringAndExceptionConstructorShouldSetMessageAndInnerExceptionAndAdapterType()
{
var inner = new Exception();
var actual = new AdoAdapterException("Foo", inner);
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
Assert.AreEqual("Foo", actual.Message);
Assert.AreSame(inner, actual.InnerException);
}
[Test]
public void StringAndDbCommandConstructorShouldSetMessageAndCommandTextAndAdapterType()
{
var command = new SqlCommand("Bar");
var actual = new AdoAdapterException("Foo", command);
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
Assert.AreEqual("Foo", actual.Message);
Assert.AreEqual(command.CommandText, actual.CommandText);
}
[Test]
public void StringAndDictionaryConstructorShouldSetCommandTextAndParametersAndAdapterType()
{
var param = new Dictionary<string, object> { { "P", "quux" } };
var actual = new AdoAdapterException("Foo", param);
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
Assert.AreEqual("Foo", actual.CommandText);
Assert.AreEqual("quux", actual.Parameters["P"]);
}
[Test]
public void StringAndStringAndDictionaryConstructorShouldSetMessageAndCommandTextAndParametersAndAdapterType()
{
var param = new Dictionary<string, object> { { "P", "quux" } };
var actual = new AdoAdapterException("Foo", "Bar", param);
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
Assert.AreEqual("Foo", actual.Message);
Assert.AreEqual("Bar", actual.CommandText);
Assert.AreEqual("quux", actual.Parameters["P"]);
}
[Test]
public void SerializationTest()
{
var param = new Dictionary<string, object> { { "P", "quux" } };
var source = new AdoAdapterException("Foo", param);
var stream = new MemoryStream();
var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
serializer.Serialize(stream, source);
stream.Position = 0;
var actual = serializer.Deserialize(stream) as AdoAdapterException;
Assert.IsNotNull(actual);
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
Assert.AreEqual("Foo", actual.CommandText);
Assert.AreEqual("quux", actual.Parameters["P"]);
}
}
}