Skip to content

Commit

Permalink
Added unit tests for DomainService.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wahid Shalaly committed Mar 12, 2014
1 parent db17d20 commit 42df176
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ReliableUnitOfWork.SqlAzure.UnitTests/DomainServiceFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ReliableUnitOfWork.SqlAzure.Interfaces;
using Xunit;

namespace ReliableUnitOfWork.SqlAzure.UnitTests
{
public class DomainServiceFacts
{
private readonly IUnitOfWorkFactory<TestContext> unitOfWorkFactory = new UnitOfWorkFactory<TestContext>();
private readonly TestPlayer1 player = new TestPlayer1();

[Fact]
public void ShouldCreateUnitOfWorkPerMethodAndJoinPlayersAccordingly()
{
var service = new TestService(unitOfWorkFactory, player);

Assert.True(service.FirstCall());
Assert.True(service.AnothertCall());
Assert.True(service.FirstCall());
Assert.True(service.AnothertCall());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DomainServiceFacts.cs" />
<Compile Include="UnitOfWorkFactoryFacts.cs" />
<Compile Include="UnitOfWorkFacts.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
28 changes: 28 additions & 0 deletions src/ReliableUnitOfWork.SqlAzure.UnitTests/TestObjects.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ReliableUnitOfWork.SqlAzure.Interfaces;

namespace ReliableUnitOfWork.SqlAzure.UnitTests
{
Expand Down Expand Up @@ -27,4 +28,31 @@ protected override void HandlePlayerJoinedUnit(object sender, EventArgs e)
TestPlayer1.Join(UnitOfWork);
}
}

public class TestService : DomainService<TestContext>
{
private readonly TestPlayer1 player;

public TestService(IUnitOfWorkFactory<TestContext> unitOfWorkFactory, TestPlayer1 testPlayer1)
: base(unitOfWorkFactory, testPlayer1)
{
player = testPlayer1;
}

public bool FirstCall()
{
using (var uow = StartNewUnit())
{
return uow.UniqueId == player.UnitOfWork.UniqueId;
}
}

public bool AnothertCall()
{
using (var uow = StartNewUnit())
{
return uow.UniqueId == player.UnitOfWork.UniqueId;
}
}
}
}

0 comments on commit 42df176

Please sign in to comment.