Mercurial > pub > bltoolkit
comparison UnitTests/Fluent/MockDataBase/MockReader.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.Data; | |
3 using System.Linq; | |
4 | |
5 namespace BLToolkit.Fluent.Test.MockDataBase | |
6 { | |
7 public partial class MockDb | |
8 { | |
9 private partial class MockCommand : IDbCommand | |
10 { | |
11 /// <summary> | |
12 /// IDataReader | |
13 /// </summary> | |
14 private class MockReader : IDataReader | |
15 { | |
16 private readonly MockReaderData _data; | |
17 private int _rowIndex = -1; | |
18 private int _resultIndex = 0; | |
19 private MockCommandData _cmd; | |
20 | |
21 public MockReader(MockCommandData data) | |
22 { | |
23 _cmd = data; | |
24 _data = data.ReaderResult; | |
25 } | |
26 | |
27 public void Dispose() | |
28 { | |
29 } | |
30 | |
31 public string GetName(int i) | |
32 { | |
33 return _data.Results[_resultIndex].Names[i]; | |
34 } | |
35 | |
36 public string GetDataTypeName(int i) | |
37 { | |
38 throw new NotImplementedException(); | |
39 } | |
40 | |
41 public Type GetFieldType(int i) | |
42 { | |
43 Type type = _data.Results[_resultIndex].Types[i]; | |
44 if (null == type) | |
45 { | |
46 object o = _data.Results[_resultIndex].Values.First()[i]; | |
47 if (null == o) | |
48 { | |
49 throw new ArgumentException(); | |
50 } | |
51 type = o.GetType(); | |
52 } | |
53 return type; | |
54 } | |
55 | |
56 public object GetValue(int i) | |
57 { | |
58 return _data.Results[_resultIndex].Values[_rowIndex][i]; | |
59 } | |
60 | |
61 public int GetValues(object[] values) | |
62 { | |
63 _data.Results[_resultIndex].Values[_rowIndex].CopyTo(values, 0); | |
64 return Math.Min(_data.Results[_resultIndex].Values[_rowIndex].Length, values.Length); | |
65 } | |
66 | |
67 public int GetOrdinal(string name) | |
68 { | |
69 throw new NotImplementedException(); | |
70 } | |
71 | |
72 public bool GetBoolean(int i) | |
73 { | |
74 return Convert.ToBoolean(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
75 } | |
76 | |
77 public byte GetByte(int i) | |
78 { | |
79 return Convert.ToByte(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
80 } | |
81 | |
82 public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) | |
83 { | |
84 throw new NotImplementedException(); | |
85 } | |
86 | |
87 public char GetChar(int i) | |
88 { | |
89 return Convert.ToChar(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
90 } | |
91 | |
92 public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) | |
93 { | |
94 throw new NotImplementedException(); | |
95 } | |
96 | |
97 public Guid GetGuid(int i) | |
98 { | |
99 throw new NotImplementedException(); | |
100 } | |
101 | |
102 public short GetInt16(int i) | |
103 { | |
104 return Convert.ToInt16(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
105 } | |
106 | |
107 public int GetInt32(int i) | |
108 { | |
109 return Convert.ToInt32(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
110 } | |
111 | |
112 public long GetInt64(int i) | |
113 { | |
114 return Convert.ToInt64(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
115 } | |
116 | |
117 public float GetFloat(int i) | |
118 { | |
119 throw new NotImplementedException(); | |
120 } | |
121 | |
122 public double GetDouble(int i) | |
123 { | |
124 return Convert.ToDouble(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
125 } | |
126 | |
127 public string GetString(int i) | |
128 { | |
129 return Convert.ToString(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
130 } | |
131 | |
132 public decimal GetDecimal(int i) | |
133 { | |
134 return Convert.ToDecimal(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
135 } | |
136 | |
137 public DateTime GetDateTime(int i) | |
138 { | |
139 return Convert.ToDateTime(_data.Results[_resultIndex].Values[_rowIndex][i]); | |
140 } | |
141 | |
142 public IDataReader GetData(int i) | |
143 { | |
144 throw new NotImplementedException(); | |
145 } | |
146 | |
147 public bool IsDBNull(int i) | |
148 { | |
149 return null == _data.Results[_resultIndex].Values[_rowIndex][i]; | |
150 } | |
151 | |
152 public int FieldCount | |
153 { | |
154 get { return _data.Results[_resultIndex].Names.Count; } | |
155 } | |
156 | |
157 object IDataRecord.this[int i] | |
158 { | |
159 get { throw new NotImplementedException(); } | |
160 } | |
161 | |
162 object IDataRecord.this[string name] | |
163 { | |
164 get { throw new NotImplementedException(); } | |
165 } | |
166 | |
167 public void Close() | |
168 { | |
169 IsClosed = true; | |
170 } | |
171 | |
172 public DataTable GetSchemaTable() | |
173 { | |
174 throw new NotImplementedException(); | |
175 } | |
176 | |
177 public bool NextResult() | |
178 { | |
179 _rowIndex = -1; | |
180 _resultIndex += 1; | |
181 return _data.Results.Count > _resultIndex; | |
182 } | |
183 | |
184 public bool Read() | |
185 { | |
186 _cmd.IsUsing = true; | |
187 _rowIndex++; | |
188 return _data.Results[_resultIndex].Values.Count > _rowIndex; | |
189 } | |
190 | |
191 public int Depth | |
192 { | |
193 get { throw new NotImplementedException(); } | |
194 } | |
195 | |
196 public bool IsClosed { get; set; } | |
197 | |
198 public int RecordsAffected | |
199 { | |
200 get { return _rowIndex + 1; } | |
201 } | |
202 } | |
203 } | |
204 } | |
205 } |