-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for UnitOfWork & UnitOfWorkFactory.
- Loading branch information
Wahid Shalaly
committed
Mar 12, 2014
1 parent
36b6e2c
commit db17d20
Showing
23 changed files
with
363 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="xunit.runners" version="1.9.2" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xunit> | ||
<assemblies> | ||
<assembly filename="ReliableUnitOfWork.SqlAzure.UnitTests\bin\Debug\ReliableUnitOfWork.SqlAzure.UnitTests.dll" shadow-copy="true" /> | ||
</assemblies> | ||
</xunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<configSections> | ||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> | ||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | ||
</configSections> | ||
<entityFramework> | ||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> | ||
<providers> | ||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> | ||
</providers> | ||
</entityFramework> | ||
</configuration> |
36 changes: 36 additions & 0 deletions
36
src/ReliableUnitOfWork.SqlAzure.UnitTests/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("ReliableUnitOfWork.SqlAzure.UnitTests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("ReliableUnitOfWork.SqlAzure.UnitTests")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("7d74f221-8745-4313-85e4-0310c58a3528")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
75 changes: 75 additions & 0 deletions
75
src/ReliableUnitOfWork.SqlAzure.UnitTests/ReliableUnitOfWork.SqlAzure.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{EA7B64E9-55F3-4987-BCAF-86B03C985009}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ReliableUnitOfWork.SqlAzure.UnitTests</RootNamespace> | ||
<AssemblyName>ReliableUnitOfWork.SqlAzure.UnitTests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="EntityFramework"> | ||
<HintPath>..\packages\EntityFramework.6.0.2\lib\net45\EntityFramework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="EntityFramework.SqlServer"> | ||
<HintPath>..\packages\EntityFramework.6.0.2\lib\net45\EntityFramework.SqlServer.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.ComponentModel.DataAnnotations" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="xunit"> | ||
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="UnitOfWorkFactoryFacts.cs" /> | ||
<Compile Include="UnitOfWorkFacts.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="TestObjects.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ReliableUnitOfWork.SqlAzure\ReliableUnitOfWork.SqlAzure.csproj"> | ||
<Project>{c450e55f-cde0-4048-bba5-40c06833640f}</Project> | ||
<Name>ReliableUnitOfWork.SqlAzure</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
|
||
namespace ReliableUnitOfWork.SqlAzure.UnitTests | ||
{ | ||
public class TestContext : UnitDbContext | ||
{ | ||
} | ||
|
||
public class TestPlayer1 : UnitOfWorkPlayer<TestContext> | ||
{ | ||
protected override void HandlePlayerJoinedUnit(object sender, EventArgs e) | ||
{ | ||
} | ||
} | ||
|
||
public class TestPlayer2 : UnitOfWorkPlayer<TestContext> | ||
{ | ||
public readonly TestPlayer1 TestPlayer1; | ||
|
||
public TestPlayer2(TestPlayer1 testPlayer1) | ||
{ | ||
TestPlayer1 = testPlayer1; | ||
} | ||
|
||
protected override void HandlePlayerJoinedUnit(object sender, EventArgs e) | ||
{ | ||
TestPlayer1.Join(UnitOfWork); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/ReliableUnitOfWork.SqlAzure.UnitTests/UnitOfWorkFactoryFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using ReliableUnitOfWork.SqlAzure.Interfaces; | ||
using Xunit; | ||
|
||
namespace ReliableUnitOfWork.SqlAzure.UnitTests | ||
{ | ||
public class UnitOfWorkFactoryFacts | ||
{ | ||
public class StartNew_WithoutParameters | ||
{ | ||
private readonly IUnitOfWorkFactory<TestContext> unitOfWorkFactory = new UnitOfWorkFactory<TestContext>(); | ||
|
||
[Fact] | ||
public void ShouldCreateNewUnitOfWork() | ||
{ | ||
var unitOfWork = unitOfWorkFactory.StartNew(); | ||
Assert.NotNull(unitOfWork); | ||
Assert.NotNull(unitOfWork.DbContext); | ||
Assert.IsType<UnitOfWork<TestContext>>(unitOfWork); | ||
Assert.IsType<TestContext>(unitOfWork.DbContext); | ||
} | ||
} | ||
|
||
public class StartNew_WithPlayerHasNoDependencies | ||
{ | ||
private readonly IUnitOfWorkFactory<TestContext> unitOfWorkFactory = new UnitOfWorkFactory<TestContext>(); | ||
|
||
[Fact] | ||
public void ShouldCreateNewUnitOfWork() | ||
{ | ||
var testPlayer1 = new TestPlayer1(); | ||
var unitOfWork = unitOfWorkFactory.StartNew(testPlayer1); | ||
|
||
Assert.NotNull(unitOfWork); | ||
Assert.NotNull(unitOfWork.DbContext); | ||
Assert.IsType<UnitOfWork<TestContext>>(unitOfWork); | ||
Assert.IsType<TestContext>(unitOfWork.DbContext); | ||
} | ||
|
||
[Fact] | ||
public void ShouldJoinPlayerToTheNewUnitOfWork() | ||
{ | ||
var testPlayer1 = new TestPlayer1(); | ||
var unitOfWork = unitOfWorkFactory.StartNew(testPlayer1); | ||
|
||
Assert.Equal(unitOfWork.UniqueId, testPlayer1.UnitOfWork.UniqueId); | ||
} | ||
} | ||
|
||
public class StartNew_WithPlayerHasDependencies | ||
{ | ||
private readonly IUnitOfWorkFactory<TestContext> unitOfWorkFactory = new UnitOfWorkFactory<TestContext>(); | ||
|
||
[Fact] | ||
public void ShouldCreateNewUnitOfWork() | ||
{ | ||
var testPlayer1 = new TestPlayer1(); | ||
var unitOfWork = unitOfWorkFactory.StartNew(testPlayer1); | ||
|
||
Assert.NotNull(unitOfWork); | ||
Assert.NotNull(unitOfWork.DbContext); | ||
Assert.IsType<UnitOfWork<TestContext>>(unitOfWork); | ||
Assert.IsType<TestContext>(unitOfWork.DbContext); | ||
} | ||
|
||
[Fact] | ||
public void ShouldJoinPlayerAndDependenciesToTheNewUnitOfWork() | ||
{ | ||
var testPlayer2 = new TestPlayer2(new TestPlayer1()); | ||
var unitOfWork = unitOfWorkFactory.StartNew(testPlayer2); | ||
|
||
Assert.Equal(unitOfWork.UniqueId, testPlayer2.UnitOfWork.UniqueId); | ||
Assert.Equal(unitOfWork.UniqueId, testPlayer2.TestPlayer1.UnitOfWork.UniqueId); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/ReliableUnitOfWork.SqlAzure.UnitTests/UnitOfWorkFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Xunit; | ||
|
||
namespace ReliableUnitOfWork.SqlAzure.UnitTests | ||
{ | ||
public class UnitOfWorkFacts | ||
{ | ||
public class Constructor | ||
{ | ||
[Fact] | ||
public void ShouldCreateNewInstanceFromUnitDbContext() | ||
{ | ||
var unitOfWork = new UnitOfWork<TestContext>(); | ||
Assert.NotNull(unitOfWork.DbContext); | ||
} | ||
} | ||
|
||
public class Dispose | ||
{ | ||
[Fact] | ||
public void ShouldDisposeTheUnitDbContextToo() | ||
{ | ||
var unitOfWork = new UnitOfWork<TestContext>(); | ||
|
||
unitOfWork.Dispose(); | ||
|
||
Assert.Null(unitOfWork.DbContext); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="EntityFramework" version="6.0.2" targetFramework="net45" /> | ||
<package id="xunit" version="1.9.2" targetFramework="net45" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/ReliableUnitOfWork.SqlAzure/Interfaces/IUnitOfWorkFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/ReliableUnitOfWork.SqlAzure/Interfaces/IUnitOfWorkPlayer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
namespace ReliableUnitOfWork.SqlAzure.Interfaces | ||
{ | ||
public interface IUnitOfWorkPlayer<in TDbContext> : IUniqueIdHolder | ||
public interface IUnitOfWorkPlayer<TDbContext> : IUniqueIdHolder | ||
where TDbContext : IDbContext | ||
{ | ||
IUnitOfWork<TDbContext> UnitOfWork { get; } | ||
|
||
void Join(IUnitOfWork<TDbContext> unitOfWork); | ||
} | ||
} |
18 changes: 9 additions & 9 deletions
18
...eUnitOfWork.SqlAzure/DomainServiceBase.cs → ...k.SqlAzure/Internals/DomainServiceBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
using ReliableUnitOfWork.SqlAzure.Interfaces; | ||
|
||
namespace ReliableUnitOfWork.SqlAzure | ||
{ | ||
public abstract class DomainServiceBase<TDbContext> : UniqueIdHolder, IDomainService<TDbContext> | ||
where TDbContext : class, IDbContext, new() | ||
{ | ||
public abstract IUnitOfWork<TDbContext> StartNewUnit(); | ||
} | ||
using ReliableUnitOfWork.SqlAzure.Interfaces; | ||
|
||
namespace ReliableUnitOfWork.SqlAzure.Internals | ||
{ | ||
public abstract class DomainServiceBase<TDbContext> : UniqueIdHolder, IDomainService<TDbContext> | ||
where TDbContext : class, IDbContext, new() | ||
{ | ||
public abstract IUnitOfWork<TDbContext> StartNewUnit(); | ||
} | ||
} |
20 changes: 11 additions & 9 deletions
20
...ableUnitOfWork.SqlAzure/UnitOfWorkBase.cs → ...Work.SqlAzure/Internals/UnitOfWorkBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
namespace ReliableUnitOfWork.SqlAzure.Interfaces | ||
{ | ||
public abstract class UnitOfWorkBase<TDbContext> : UniqueIdHolder, IUnitOfWork<TDbContext> | ||
where TDbContext : class, IDbContext, new() | ||
{ | ||
public TDbContext DbContext { get; protected set; } | ||
|
||
public abstract void Dispose(); | ||
} | ||
using ReliableUnitOfWork.SqlAzure.Interfaces; | ||
|
||
namespace ReliableUnitOfWork.SqlAzure.Internals | ||
{ | ||
public abstract class UnitOfWorkBase<TDbContext> : UniqueIdHolder, IUnitOfWork<TDbContext> | ||
where TDbContext : class, IDbContext, new() | ||
{ | ||
public TDbContext DbContext { get; protected set; } | ||
|
||
public abstract void Dispose(); | ||
} | ||
} |
Oops, something went wrong.