Mercurial > pub > bltoolkit
view UnitTests/Fluent/MockDataBase/MockDb.cs @ 4:f757da6161a1
!bug 100 + 2h fixed gregression
author | cin |
---|---|
date | Sun, 24 Aug 2014 17:57:42 +0400 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using System.Collections.Generic; using System.Data; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace BLToolkit.Fluent.Test.MockDataBase { /// <summary> /// DB configure start point /// </summary> public partial class MockDb : IDbConnection { private int _cmdIndex = -1; private readonly List<MockCommandData> _commands = new List<MockCommandData>(); public List<MockCommandData> Commands { get { return _commands; } } private MockCommandData NextCommand() { _cmdIndex++; if (_cmdIndex == _commands.Count) { Assert.Fail("Command not define"); } return _commands[_cmdIndex]; } /// <summary> /// New IDataReader query /// </summary> /// <param name="fields"></param> /// <returns></returns> public MockDb NewReader(params string[] fields) { CurrentSetupCommandData = new MockCommandData { ReaderResult = new MockReaderData() }; return NextResult(fields); } /// <summary> /// Next result into current IDataReader context /// </summary> /// <param name="fields"></param> /// <returns></returns> public MockDb NextResult(params string[] fields) { var data = new MockReaderResultData(); data.SetNames(fields); CurrentSetupCommandData.ReaderResult.CurrentResult = data; return this; } public MockDb NewRow(params object[] values) { CurrentSetupCommandData.ReaderResult.CurrentResult.Values.Add(values); return this; } private MockCommandData CurrentSetupCommandData { get { return _commands.LastOrDefault(); } set { _commands.Add(value); } } public MockDb NewNonQuery(int value = 1) { CurrentSetupCommandData = new MockCommandData { NonQueryResult = value }; return this; } } }