forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockDatabase.cs
More file actions
33 lines (29 loc) · 1.13 KB
/
MockDatabase.cs
File metadata and controls
33 lines (29 loc) · 1.13 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
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text.RegularExpressions;
namespace Simple.Data.Mocking.Ado
{
public class MockDatabase
{
private readonly List<string> _commandTexts = new List<string>();
private readonly List<Dictionary<string,object>> _commandParameters = new List<Dictionary<string, object>>();
public void Record(IDbCommand command)
{
Sql = Regex.Replace(command.CommandText, @"\s+", " ");
CommandTexts.Add(Sql);
Parameters = command.Parameters.Cast<IDataParameter>().Select(p => p.Value).ToArray();
_commandParameters.Add(command.Parameters.Cast<IDataParameter>().ToDictionary(p => p.ParameterName, p => p.Value));
}
public string Sql { get; private set; }
public object[] Parameters { get; private set; }
public List<string> CommandTexts
{
get { return _commandTexts; }
}
public List<Dictionary<string, object>> CommandParameters
{
get { return _commandParameters; }
}
}
}