0
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Data;
|
|
4 using System.Linq;
|
|
5 using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
6
|
|
7 namespace BLToolkit.Fluent.Test.MockDataBase
|
|
8 {
|
|
9 /// <summary>
|
|
10 /// DB configure start point
|
|
11 /// </summary>
|
|
12 public partial class MockDb : IDbConnection
|
|
13 {
|
|
14 private int _cmdIndex = -1;
|
|
15 private readonly List<MockCommandData> _commands = new List<MockCommandData>();
|
|
16
|
|
17 public List<MockCommandData> Commands { get { return _commands; } }
|
|
18
|
|
19 private MockCommandData NextCommand()
|
|
20 {
|
|
21 _cmdIndex++;
|
|
22 if (_cmdIndex == _commands.Count)
|
|
23 {
|
|
24 Assert.Fail("Command not define");
|
|
25 }
|
|
26 return _commands[_cmdIndex];
|
|
27 }
|
|
28
|
|
29 /// <summary>
|
|
30 /// New IDataReader query
|
|
31 /// </summary>
|
|
32 /// <param name="fields"></param>
|
|
33 /// <returns></returns>
|
|
34 public MockDb NewReader(params string[] fields)
|
|
35 {
|
|
36 CurrentSetupCommandData = new MockCommandData { ReaderResult = new MockReaderData() };
|
|
37 return NextResult(fields);
|
|
38 }
|
|
39
|
|
40 /// <summary>
|
|
41 /// Next result into current IDataReader context
|
|
42 /// </summary>
|
|
43 /// <param name="fields"></param>
|
|
44 /// <returns></returns>
|
|
45 public MockDb NextResult(params string[] fields)
|
|
46 {
|
|
47 var data = new MockReaderResultData();
|
|
48 data.SetNames(fields);
|
|
49 CurrentSetupCommandData.ReaderResult.CurrentResult = data;
|
|
50 return this;
|
|
51 }
|
|
52
|
|
53 public MockDb NewRow(params object[] values)
|
|
54 {
|
|
55 CurrentSetupCommandData.ReaderResult.CurrentResult.Values.Add(values);
|
|
56 return this;
|
|
57 }
|
|
58
|
|
59 private MockCommandData CurrentSetupCommandData
|
|
60 {
|
|
61 get { return _commands.LastOrDefault(); }
|
|
62 set { _commands.Add(value); }
|
|
63 }
|
|
64
|
|
65 public MockDb NewNonQuery(int value = 1)
|
|
66 {
|
|
67 CurrentSetupCommandData = new MockCommandData { NonQueryResult = value };
|
|
68 return this;
|
|
69 }
|
|
70 }
|
|
71 } |