comparison UnitTests/CS/Data/EventsTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using NUnit.Framework;
3 using BLToolkit.Data;
4
5 namespace Data
6 {
7 [TestFixture]
8 public class EventsTest
9 {
10 [Test]
11 public void BeforeAfterInitTest()
12 {
13 using (DbManager db = new DbManager())
14 {
15 db.BeforeOperation += HandleBeforeOperation;
16 db.AfterOperation += HandleAfterOperation;
17 db.InitCommand += HandleInitCommand;
18
19 db
20 .SetCommand("SELECT * FROM Person")
21 .ExecuteDataSet();
22 }
23 }
24
25 private static void HandleBeforeOperation(object sender, OperationTypeEventArgs ea)
26 {
27 Console.WriteLine("Before operation: " + ea.Operation);
28 }
29
30 private static void HandleAfterOperation(object sender, OperationTypeEventArgs ea)
31 {
32 Console.WriteLine("After operation: " + ea.Operation);
33 }
34
35 private static void HandleInitCommand(object sender, InitCommandEventArgs ea)
36 {
37 Console.WriteLine("Init command: " + ea.Command.CommandText);
38 }
39
40 [Test, ExpectedException(typeof(DataException))]
41 public void ExceptionTest()
42 {
43 using (DbManager db = new DbManager())
44 {
45 db.OperationException += HandleOperationException;
46
47 db
48 .SetCommand("SELECT * FROM NoSuchTableEverExist")
49 .ExecuteDataSet();
50 }
51 }
52
53 private static void HandleOperationException(object sender, OperationExceptionEventArgs ea)
54 {
55 Assert.That(ea, Is.Not.Null);
56 Assert.That(ea.Exception, Is.Not.Null);
57 Assert.That(ea.Exception.Number, Is.Not.Null);
58
59 Console.WriteLine("Operation: " + ea.Operation);
60 Console.WriteLine("Error number: " + ea.Exception.Number);
61 Console.WriteLine("Exception: " + ea.Exception.GetBaseException().Message);
62 }
63 }
64 }