Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/MockDbProvider.Tests/AcceptanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,19 @@ public void CanGetScalar()
var result = SUT.DataAccess.GetUserId("abc", "test");
Assert.AreEqual(15559, result);
}

[TestMethod]
public void CanCreateTransaction()
{
var factory = DbProviderFactories.GetFactory("MockDbProvider") as MockDbProviderFactory;

using (var conn = factory.CreateConnection())
{
using (var trn = conn.BeginTransaction())
{
Assert.IsNotNull(trn);
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/MockDbProvider/MockDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal MockDbConnection(IMockCommandExecution exec)
}
protected override DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
{
throw new NotImplementedException();
return new MockDbTransaction(isolationLevel, this);
}

public override void ChangeDatabase(string databaseName)
Expand Down
3 changes: 2 additions & 1 deletion src/MockDbProvider/MockDbProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="IMockCommandExecution.cs" />
<Compile Include="MockDbDataReader.cs" />
<Compile Include="MockDbParameterCollection.cs" />
<Compile Include="MockDbTransaction.cs" />
<Compile Include="Syntax\MockCommandBehavior.cs" />
<Compile Include="MockDbCommandBuilder.cs">
<SubType>Component</SubType>
Expand Down Expand Up @@ -79,4 +80,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
37 changes: 37 additions & 0 deletions src/MockDbProvider/MockDbTransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace MockDbProvider
{
public class MockDbTransaction
: DbTransaction
{
private readonly IsolationLevel _isolationLevel;

public override IsolationLevel IsolationLevel { get { return _isolationLevel; } }

private readonly DbConnection _dbConnection;

protected override DbConnection DbConnection { get { return _dbConnection; } }

public override void Commit()
{ // in a mock setting I am not sure how this functionality is mockable

}

public override void Rollback()
{ // in a mock setting I am not sure how this functionality is mockable

}

internal MockDbTransaction(IsolationLevel isolationLevel, DbConnection connection)
{
_isolationLevel = isolationLevel;
_dbConnection = connection;
}
}
}