-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding infrastructure unit testing. related #1
- Loading branch information
1 parent
40a67c3
commit dcea725
Showing
5 changed files
with
179 additions
and
3 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
51 changes: 51 additions & 0 deletions
51
src/Test/PetStore.Core.Test/Infrastructure/InversionOfControl/IoCTest.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,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Moq; | ||
using NUnit.Framework; | ||
using PetStore.Core.Infrastructure.InversionOfControl; | ||
using PetStore.Core.Infrastructure.Logging; | ||
using PetStore.Core.Infrastructure.UnitOfWork; | ||
using PetStore.Core.Test.Infrastructure.Logging; | ||
using PetStore.Core.Test.Infrastructure.UnitOfWork; | ||
|
||
namespace PetStore.Core.Test.Infrastructure.InversionOfControl | ||
{ | ||
[TestFixture] | ||
public class IoCTest | ||
{ | ||
#region Test Methods | ||
|
||
[Test] | ||
public void InitializeShouldNotThrowException() | ||
{ | ||
IDependencyResolver dependencyResolverMock = GetIDependencyResolverMock(); | ||
IoC.Initialize(dependencyResolverMock); | ||
} | ||
|
||
[Test] | ||
public void ResolveShouldReturnCorrectResult() | ||
{ | ||
IDependencyResolver dependencyResolverMock = GetIDependencyResolverMock(); | ||
IoC.Initialize(dependencyResolverMock); | ||
ILogger logger = IoC.Resolve<ILogger>(); | ||
Assert.IsNotNull(logger); | ||
} | ||
#endregion | ||
|
||
#region Static Methods | ||
|
||
public static IDependencyResolver GetIDependencyResolverMock() | ||
{ | ||
Mock<IDependencyResolver> dependencyResolver = new Mock<IDependencyResolver>(); | ||
|
||
dependencyResolver.Setup(d => d.Resolve<ILogger>()).Returns(LoggerTest.GetILogMock()); | ||
dependencyResolver.Setup(d => d.Resolve<IUnitOfWork>()).Returns(UnitOfWorkManagerTest.GetUnitOfWorkMock()); | ||
|
||
return dependencyResolver.Object; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/Test/PetStore.Core.Test/Infrastructure/Logging/LoggerTest.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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using PetStore.Core.Infrastructure.InversionOfControl; | ||
using PetStore.Core.Infrastructure.Logging; | ||
using PetStore.Core.Test.Infrastructure.InversionOfControl; | ||
using PetStore.TestBase.Mocks.Core.Infrastructure.Logging; | ||
|
||
namespace PetStore.Core.Test.Infrastructure.Logging | ||
{ | ||
[TestFixture] | ||
public class LoggerTest | ||
{ | ||
#region Test Methods | ||
|
||
[Test] | ||
public void InfoShouldReturnCorrectResult() | ||
{ | ||
const string msg = "Info Message 1"; | ||
IoC.Initialize(IoCTest.GetIDependencyResolverMock()); | ||
int numOfLoggedMessagesBefore = LoggerMock.Messages.Count; | ||
Logger.Info(msg); | ||
int numOfLoggedMessagesAfter = LoggerMock.Messages.Count; | ||
Assert.AreEqual(numOfLoggedMessagesBefore + 1, numOfLoggedMessagesAfter); | ||
Assert.AreEqual(msg, LoggerMock.Messages.Last()); | ||
} | ||
|
||
[Test] | ||
public void WaringShouldReturnCorrectResult() | ||
{ | ||
const string msg = "Warning Message 1"; | ||
IoC.Initialize(IoCTest.GetIDependencyResolverMock()); | ||
int numOfLoggedMessagesBefore = LoggerMock.Messages.Count; | ||
Logger.Warning(msg); | ||
int numOfLoggedMessagesAfter = LoggerMock.Messages.Count; | ||
Assert.AreEqual(numOfLoggedMessagesBefore + 1, numOfLoggedMessagesAfter); | ||
Assert.AreEqual(msg, LoggerMock.Messages.Last()); | ||
} | ||
|
||
[Test] | ||
public void ErrorShouldReturnCorrectResult() | ||
{ | ||
const string msg = "Error Message 1"; | ||
IoC.Initialize(IoCTest.GetIDependencyResolverMock()); | ||
int numOfLoggedMessagesBefore = LoggerMock.Messages.Count; | ||
Logger.Error(msg); | ||
int numOfLoggedMessagesAfter = LoggerMock.Messages.Count; | ||
Assert.AreEqual(numOfLoggedMessagesBefore + 1, numOfLoggedMessagesAfter); | ||
Assert.AreEqual(msg, LoggerMock.Messages.Last()); | ||
} | ||
|
||
[Test] | ||
public void ExceptionShouldReturnCorrectResult() | ||
{ | ||
const string msg = "Exception Message 1"; | ||
ApplicationException applicationException = new ApplicationException(msg); | ||
IoC.Initialize(IoCTest.GetIDependencyResolverMock()); | ||
int numOfLoggedMessagesBefore = LoggerMock.Messages.Count; | ||
Logger.Exception(applicationException); | ||
int numOfLoggedMessagesAfter = LoggerMock.Messages.Count; | ||
Assert.AreEqual(numOfLoggedMessagesBefore + 1, numOfLoggedMessagesAfter); | ||
Assert.AreEqual(msg, LoggerMock.Messages.Last()); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static Methods | ||
|
||
public static ILogger GetILogMock() | ||
{ | ||
return new LoggerMock(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Test/PetStore.Core.Test/Infrastructure/UnitOfWork/UnitOfWorkManagerTest.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,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Moq; | ||
using NUnit.Framework; | ||
using PetStore.Core.Infrastructure.InversionOfControl; | ||
using PetStore.Core.Infrastructure.UnitOfWork; | ||
using PetStore.Core.Test.Infrastructure.InversionOfControl; | ||
|
||
namespace PetStore.Core.Test.Infrastructure.UnitOfWork | ||
{ | ||
[TestFixture] | ||
public class UnitOfWorkManagerTest | ||
{ | ||
#region Test Methods | ||
|
||
[Test] | ||
public void BeginShouldReturnCorrectResult() | ||
{ | ||
IoC.Initialize(IoCTest.GetIDependencyResolverMock()); | ||
|
||
IUnitOfWork unitOfWork = UnitOfWorkManager.Begin(); | ||
|
||
Assert.IsNotNull(unitOfWork); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static Methods | ||
|
||
public static IUnitOfWork GetUnitOfWorkMock() | ||
{ | ||
Mock<IUnitOfWork> unitOfWorkMock = new Mock<IUnitOfWork>(); | ||
return unitOfWorkMock.Object; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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