Mercurial > pub > bltoolkit
comparison UnitTests/CS/Mapping/ResultSetTest.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 System.Collections; | |
| 3 using System.Data; | |
| 4 using BLToolkit.Data; | |
| 5 using BLToolkit.Mapping; | |
| 6 | |
| 7 using NUnit.Framework; | |
| 8 | |
| 9 namespace Mapping | |
| 10 { | |
| 11 [TestFixture] | |
| 12 public class ResultSetTest | |
| 13 { | |
| 14 public class Master | |
| 15 { | |
| 16 [MapField("MasterID")] | |
| 17 public int ID; | |
| 18 | |
| 19 public ArrayList Slaves = new ArrayList(); | |
| 20 } | |
| 21 | |
| 22 public class Slave | |
| 23 { | |
| 24 [MapField("SlaveID")] | |
| 25 public int ID; | |
| 26 | |
| 27 public int MasterID; | |
| 28 } | |
| 29 | |
| 30 const string SqlResultSet = @" | |
| 31 SELECT 1 as MasterID | |
| 32 UNION SELECT 2 as MasterID | |
| 33 | |
| 34 SELECT 4 SlaveID, 1 as MasterID | |
| 35 UNION SELECT 5 SlaveID, 2 as MasterID | |
| 36 UNION SELECT 6 SlaveID, 2 as MasterID | |
| 37 UNION SELECT 7 SlaveID, 1 as MasterID"; | |
| 38 | |
| 39 [Test] | |
| 40 public void TestResultSet() | |
| 41 { | |
| 42 MapResultSet[] sets = new MapResultSet[2]; | |
| 43 | |
| 44 sets[0] = new MapResultSet(typeof(Master)); | |
| 45 sets[1] = new MapResultSet(typeof(Slave)); | |
| 46 | |
| 47 sets[0].AddRelation(sets[1], "MasterID", "MasterID", "Slaves"); | |
| 48 | |
| 49 using (DbManager db = new DbManager()) | |
| 50 { | |
| 51 db | |
| 52 #if ORACLE | |
| 53 .SetSpCommand("ResultSetTest") | |
| 54 #else | |
| 55 .SetCommand(SqlResultSet) | |
| 56 #endif | |
| 57 .ExecuteResultSet(sets); | |
| 58 } | |
| 59 | |
| 60 Assert.AreEqual(7, ((Slave)(((Master)sets[0].List[0]).Slaves[1])).ID); | |
| 61 } | |
| 62 | |
| 63 [Test] | |
| 64 [ExpectedException(typeof(MappingException))] | |
| 65 public void TestFailResultSet1() | |
| 66 { | |
| 67 MapResultSet[] sets = new MapResultSet[2]; | |
| 68 | |
| 69 sets[0] = new MapResultSet(typeof(Master)); | |
| 70 sets[1] = new MapResultSet(typeof(Slave)); | |
| 71 | |
| 72 sets[0].AddRelation(sets[1], "MasterID", "ID", "Slaves"); | |
| 73 | |
| 74 using (DbManager db = new DbManager()) | |
| 75 { | |
| 76 db | |
| 77 #if ORACLE | |
| 78 .SetSpCommand("ResultSetTest") | |
| 79 #else | |
| 80 .SetCommand(SqlResultSet) | |
| 81 #endif | |
| 82 .ExecuteResultSet(sets); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 [Test] | |
| 87 [ExpectedException(typeof(MappingException))] | |
| 88 public void TestFailResultSet2() | |
| 89 { | |
| 90 MapResultSet[] sets = new MapResultSet[2]; | |
| 91 | |
| 92 sets[0] = new MapResultSet(typeof(Master)); | |
| 93 sets[1] = new MapResultSet(typeof(Slave)); | |
| 94 | |
| 95 sets[0].AddRelation(sets[1], "Master", "MasterID", "Slaves"); | |
| 96 | |
| 97 using (DbManager db = new DbManager()) | |
| 98 { | |
| 99 db | |
| 100 #if ORACLE | |
| 101 .SetSpCommand("ResultSetTest") | |
| 102 #else | |
| 103 .SetCommand(SqlResultSet) | |
| 104 #endif | |
| 105 .ExecuteResultSet(sets); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 [Test] | |
| 110 [ExpectedException(typeof(MappingException))] | |
| 111 public void TestFailResultSet3() | |
| 112 { | |
| 113 MapResultSet[] sets = new MapResultSet[2]; | |
| 114 | |
| 115 sets[0] = new MapResultSet(typeof(Master)); | |
| 116 sets[1] = new MapResultSet(typeof(Slave)); | |
| 117 | |
| 118 sets[0].AddRelation(sets[1], "MasterID", "MasterID", "Slave"); | |
| 119 | |
| 120 using (DbManager db = new DbManager()) | |
| 121 { | |
| 122 db | |
| 123 #if ORACLE | |
| 124 .SetSpCommand("ResultSetTest") | |
| 125 #else | |
| 126 .SetCommand(SqlResultSet) | |
| 127 #endif | |
| 128 .ExecuteResultSet(sets); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 [Test] | |
| 133 public void TestNextResult() | |
| 134 { | |
| 135 using (DbManager db = new DbManager()) | |
| 136 { | |
| 137 MapResultSet[] sets = db | |
| 138 #if ORACLE | |
| 139 .SetSpCommand("ResultSetTest") | |
| 140 #else | |
| 141 .SetCommand(SqlResultSet) | |
| 142 #endif | |
| 143 .ExecuteResultSet(typeof(Master), | |
| 144 new MapNextResult(typeof(Slave), "MasterID", "MasterID", "Slaves")); | |
| 145 | |
| 146 Assert.AreEqual(7, ((Slave)(((Master)sets[0].List[0]).Slaves[1])).ID); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 [Test] | |
| 151 public void TestDataSet() | |
| 152 { | |
| 153 using (DbManager db = new DbManager()) | |
| 154 { | |
| 155 DataSet set = db | |
| 156 #if ORACLE | |
| 157 .SetSpCommand("ResultSetTest") | |
| 158 #else | |
| 159 .SetCommand(SqlResultSet) | |
| 160 #endif | |
| 161 .ExecuteDataSet(); | |
| 162 | |
| 163 Assert.IsNotNull(set); | |
| 164 Assert.AreEqual(2, set.Tables.Count); | |
| 165 } | |
| 166 | |
| 167 } | |
| 168 | |
| 169 } | |
| 170 } |
