commit
f68fa84cad
@ -0,0 +1,8 @@
|
||||
// ReSharper disable CheckNamespace
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
[SetUpFixture]
|
||||
public class Fixtures : LoggingFixtures
|
||||
{
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonServiceLocator" version="1.0" />
|
||||
<package id="FluentAssertions" version="1.5.0.0" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1" />
|
||||
<package id="Ninject" version="2.2.1.4" />
|
||||
<package id="NUnit" version="2.5.10.11092" />
|
||||
<package id="Unity" version="2.1.505.0" />
|
||||
<package id="FluentAssertions" version="1.5.0.0" />
|
||||
</packages>
|
@ -0,0 +1,8 @@
|
||||
// ReSharper disable CheckNamespace
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
[SetUpFixture]
|
||||
public class Fixtures : LoggingFixtures
|
||||
{
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using AutoMoq.Unity;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Moq;
|
||||
using Moq.Language.Flow;
|
||||
|
||||
[assembly: InternalsVisibleTo("AutoMoq.Tests")]
|
||||
|
||||
namespace AutoMoq
|
||||
{
|
||||
public class AutoMoqer
|
||||
{
|
||||
internal readonly MockBehavior DefaultBehavior = MockBehavior.Default;
|
||||
internal Type ResolveType;
|
||||
private IUnityContainer container;
|
||||
private IDictionary<Type, object> registeredMocks;
|
||||
|
||||
public AutoMoqer()
|
||||
{
|
||||
SetupAutoMoqer(new UnityContainer());
|
||||
}
|
||||
|
||||
public AutoMoqer(MockBehavior defaultBehavior)
|
||||
{
|
||||
DefaultBehavior = defaultBehavior;
|
||||
SetupAutoMoqer(new UnityContainer());
|
||||
|
||||
}
|
||||
|
||||
internal AutoMoqer(IUnityContainer container)
|
||||
{
|
||||
SetupAutoMoqer(container);
|
||||
}
|
||||
|
||||
public virtual T Resolve<T>()
|
||||
{
|
||||
ResolveType = typeof(T);
|
||||
var result = container.Resolve<T>();
|
||||
SetConstant(result);
|
||||
ResolveType = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual Mock<T> GetMock<T>() where T : class
|
||||
{
|
||||
return GetMock<T>(DefaultBehavior);
|
||||
}
|
||||
|
||||
public virtual Mock<T> GetMock<T>(MockBehavior behavior) where T : class
|
||||
{
|
||||
ResolveType = null;
|
||||
var type = GetTheMockType<T>();
|
||||
if (GetMockHasNotBeenCalledForThisType(type))
|
||||
{
|
||||
CreateANewMockAndRegisterIt<T>(type, behavior);
|
||||
}
|
||||
|
||||
var mock = TheRegisteredMockForThisType<T>(type);
|
||||
|
||||
if (behavior != MockBehavior.Default && mock.Behavior == MockBehavior.Default)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to change be behaviour of a an existing mock.");
|
||||
}
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
||||
internal virtual void SetMock(Type type, Mock mock)
|
||||
{
|
||||
if (registeredMocks.ContainsKey(type) == false)
|
||||
registeredMocks.Add(type, mock);
|
||||
}
|
||||
|
||||
public virtual void SetConstant<T>(T instance)
|
||||
{
|
||||
container.RegisterInstance(instance);
|
||||
SetMock(instance.GetType(), null);
|
||||
}
|
||||
|
||||
public ISetup<T> Setup<T>(Expression<Action<T>> expression) where T : class
|
||||
{
|
||||
return GetMock<T>().Setup(expression);
|
||||
}
|
||||
|
||||
public ISetup<T, TResult> Setup<T, TResult>(Expression<Func<T, TResult>> expression) where T : class
|
||||
{
|
||||
return GetMock<T>().Setup(expression);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, string failMessage) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, failMessage);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, Times times) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, times);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, Times times, string failMessage) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, times, failMessage);
|
||||
}
|
||||
|
||||
public void VerifyAllMocks()
|
||||
{
|
||||
foreach (var registeredMock in registeredMocks)
|
||||
{
|
||||
var mock = registeredMock.Value as Mock;
|
||||
if (mock != null)
|
||||
mock.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
private void SetupAutoMoqer(IUnityContainer container)
|
||||
{
|
||||
this.container = container;
|
||||
container.RegisterInstance(this);
|
||||
|
||||
registeredMocks = new Dictionary<Type, object>();
|
||||
AddTheAutoMockingContainerExtensionToTheContainer(container);
|
||||
}
|
||||
|
||||
private static void AddTheAutoMockingContainerExtensionToTheContainer(IUnityContainer container)
|
||||
{
|
||||
container.AddNewExtension<AutoMockingContainerExtension>();
|
||||
return;
|
||||
}
|
||||
|
||||
private Mock<T> TheRegisteredMockForThisType<T>(Type type) where T : class
|
||||
{
|
||||
return (Mock<T>)registeredMocks.Where(x => x.Key == type).First().Value;
|
||||
}
|
||||
|
||||
private void CreateANewMockAndRegisterIt<T>(Type type, MockBehavior behavior) where T : class
|
||||
{
|
||||
var mock = new Mock<T>(behavior);
|
||||
container.RegisterInstance(mock.Object);
|
||||
SetMock(type, mock);
|
||||
}
|
||||
|
||||
private bool GetMockHasNotBeenCalledForThisType(Type type)
|
||||
{
|
||||
return registeredMocks.ContainsKey(type) == false;
|
||||
}
|
||||
|
||||
private static Type GetTheMockType<T>() where T : class
|
||||
{
|
||||
return typeof(T);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
Copyright (c) 2010 Darren Cauthon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
@ -1,13 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoMoq" version="1.3.1.3" />
|
||||
<package id="CommonServiceLocator" version="1.0" />
|
||||
<package id="FluentAssertions" version="1.5.0.0" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1" />
|
||||
<package id="Ninject" version="2.2.1.4" />
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
<package id="NUnit" version="2.5.10.11092" />
|
||||
<package id="SqlServerCompact" version="4.0.8482.1" />
|
||||
<package id="Unity" version="2.1.505.0" />
|
||||
<package id="FluentAssertions" version="1.5.0.0" />
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
</packages>
|
@ -0,0 +1,28 @@
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
|
||||
namespace NzbDrone.Test.Common
|
||||
{
|
||||
public abstract class LoggingFixtures
|
||||
{
|
||||
|
||||
[SetUp]
|
||||
public void SetUpBase()
|
||||
{
|
||||
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
||||
LogConfiguration.RegisterUdpLogger();
|
||||
|
||||
RegisterExceptionVerification();
|
||||
}
|
||||
|
||||
private static void RegisterExceptionVerification()
|
||||
{
|
||||
var exceptionVerification = new ExceptionVerification();
|
||||
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, exceptionVerification));
|
||||
LogConfiguration.Reload();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonServiceLocator" version="1.0" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
<package id="NUnit" version="2.5.10.11092" />
|
||||
<package id="Unity" version="2.1.505.0" />
|
||||
</packages>
|
@ -1,166 +0,0 @@
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using AutoMoq.Unity;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Moq;
|
||||
using Moq.Language.Flow;
|
||||
|
||||
[assembly: InternalsVisibleTo("AutoMoq.Tests")]
|
||||
|
||||
namespace AutoMoq
|
||||
{
|
||||
public class AutoMoqer
|
||||
{
|
||||
internal readonly MockBehavior DefaultBehavior = MockBehavior.Default;
|
||||
internal Type ResolveType;
|
||||
private IUnityContainer container;
|
||||
private IDictionary<Type, object> registeredMocks;
|
||||
|
||||
public AutoMoqer()
|
||||
{
|
||||
SetupAutoMoqer(new UnityContainer());
|
||||
}
|
||||
|
||||
public AutoMoqer(MockBehavior defaultBehavior)
|
||||
{
|
||||
DefaultBehavior = defaultBehavior;
|
||||
SetupAutoMoqer(new UnityContainer());
|
||||
|
||||
}
|
||||
|
||||
internal AutoMoqer(IUnityContainer container)
|
||||
{
|
||||
SetupAutoMoqer(container);
|
||||
}
|
||||
|
||||
public virtual T Resolve<T>()
|
||||
{
|
||||
ResolveType = typeof(T);
|
||||
var result = container.Resolve<T>();
|
||||
SetConstant(result);
|
||||
ResolveType = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual Mock<T> GetMock<T>() where T : class
|
||||
{
|
||||
return GetMock<T>(DefaultBehavior);
|
||||
}
|
||||
|
||||
public virtual Mock<T> GetMock<T>(MockBehavior behavior) where T : class
|
||||
{
|
||||
ResolveType = null;
|
||||
var type = GetTheMockType<T>();
|
||||
if (GetMockHasNotBeenCalledForThisType(type))
|
||||
{
|
||||
CreateANewMockAndRegisterIt<T>(type, behavior);
|
||||
}
|
||||
|
||||
var mock = TheRegisteredMockForThisType<T>(type);
|
||||
|
||||
if (behavior != MockBehavior.Default && mock.Behavior == MockBehavior.Default)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to change be behaviour of a an existing mock.");
|
||||
}
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
||||
internal virtual void SetMock(Type type, Mock mock)
|
||||
{
|
||||
if (registeredMocks.ContainsKey(type) == false)
|
||||
registeredMocks.Add(type, mock);
|
||||
}
|
||||
|
||||
public virtual void SetConstant<T>(T instance)
|
||||
{
|
||||
container.RegisterInstance(instance);
|
||||
SetMock(instance.GetType(), null);
|
||||
}
|
||||
|
||||
public ISetup<T> Setup<T>(Expression<Action<T>> expression) where T : class
|
||||
{
|
||||
return GetMock<T>().Setup(expression);
|
||||
}
|
||||
|
||||
public ISetup<T, TResult> Setup<T, TResult>(Expression<Func<T, TResult>> expression) where T : class
|
||||
{
|
||||
return GetMock<T>().Setup(expression);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, string failMessage) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, failMessage);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, Times times) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, times);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, Times times, string failMessage) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, times, failMessage);
|
||||
}
|
||||
|
||||
public void VerifyAllMocks()
|
||||
{
|
||||
foreach (var registeredMock in registeredMocks)
|
||||
{
|
||||
var mock = registeredMock.Value as Mock;
|
||||
if (mock != null)
|
||||
mock.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
private void SetupAutoMoqer(IUnityContainer container)
|
||||
{
|
||||
this.container = container;
|
||||
container.RegisterInstance(this);
|
||||
|
||||
registeredMocks = new Dictionary<Type, object>();
|
||||
AddTheAutoMockingContainerExtensionToTheContainer(container);
|
||||
}
|
||||
|
||||
private static void AddTheAutoMockingContainerExtensionToTheContainer(IUnityContainer container)
|
||||
{
|
||||
container.AddNewExtension<AutoMockingContainerExtension>();
|
||||
return;
|
||||
}
|
||||
|
||||
private Mock<T> TheRegisteredMockForThisType<T>(Type type) where T : class
|
||||
{
|
||||
return (Mock<T>)registeredMocks.Where(x => x.Key == type).First().Value;
|
||||
}
|
||||
|
||||
private void CreateANewMockAndRegisterIt<T>(Type type, MockBehavior behavior) where T : class
|
||||
{
|
||||
var mock = new Mock<T>(behavior);
|
||||
container.RegisterInstance(mock.Object);
|
||||
SetMock(type, mock);
|
||||
}
|
||||
|
||||
private bool GetMockHasNotBeenCalledForThisType(Type type)
|
||||
{
|
||||
return registeredMocks.ContainsKey(type) == false;
|
||||
}
|
||||
|
||||
private static Type GetTheMockType<T>() where T : class
|
||||
{
|
||||
return typeof(T);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
Copyright (c) 2010 Darren Cauthon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
@ -0,0 +1,8 @@
|
||||
// ReSharper disable CheckNamespace
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
[SetUpFixture]
|
||||
public class Fixtures : LoggingFixtures
|
||||
{
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonServiceLocator" version="1.0" />
|
||||
<package id="FluentAssertions" version="1.5.0.0" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1" />
|
||||
<package id="NUnit" version="2.5.10.11092" />
|
||||
<package id="Unity" version="2.1.505.0" />
|
||||
</packages>
|
Loading…
Reference in new issue