From 4ae268b8e5e58dbf0e4c67080d1a9076e846bc46 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 23 Oct 2011 22:54:09 -0700 Subject: [PATCH] lots of different things ;) --- .gitignore | 2 +- NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs | 187 ------------------ NzbDrone.App.Test/Fixtures.cs | 8 + NzbDrone.App.Test/NzbDrone.App.Test.csproj | 21 +- NzbDrone.App.Test/packages.config | 4 +- NzbDrone.Common.Test/DiskProviderTests.cs | 65 ++++++ .../EnviromentProviderTest.cs | 6 + NzbDrone.Common.Test/Fixtures.cs | 8 + .../NzbDrone.Common.Test.csproj | 10 +- NzbDrone.Common/DiskProvider.cs | 19 ++ NzbDrone.Common/EnviromentProvider.cs | 18 ++ .../ExceptioneerTarget.cs | 2 +- NzbDrone.Common/LogConfiguration.cs | 93 +++++++++ NzbDrone.Common/NzbDrone.Common.csproj | 6 + NzbDrone.Core.Test/CentralDispatchTest.cs | 2 + NzbDrone.Core.Test/EpisodeStatusTest.cs | 4 +- .../Framework/AutoMoq/AutoMoqer.cs | 166 ---------------- .../Framework/AutoMoq/License.txt | 22 --- .../Unity/AutoMockingBuilderStrategy.cs | 84 -------- .../Unity/AutoMockingContainerExtension.cs | 40 ---- NzbDrone.Core.Test/Framework/Fixtures.cs | 33 +--- NzbDrone.Core.Test/Framework/MockLib.cs | 3 - NzbDrone.Core.Test/Framework/TestBase.cs | 10 +- NzbDrone.Core.Test/IndexerTests.cs | 1 + .../JobTests/DiskScanJobTest.cs | 1 + .../JobTests/ImportNewSeriesJobTest.cs | 1 + NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 28 +-- .../ProviderTests/DiskScanProviderTest.cs | 1 + .../DiskScanProviderTest_ImportFile.cs | 1 + .../InventoryProvider_IsAcceptableSizeTest.cs | 3 +- .../InventoryProvider_IsMonitoredTest.cs | 2 - .../InventoryProvider_QualityNeededTest.cs | 3 - .../ProviderTests/JobProviderTest.cs | 1 + .../ProviderTests/LogProviderTest.cs | 70 ++----- .../ProcessDownloadFixture.cs | 1 + .../ProviderTests/SabProviderTest.cs | 1 + .../SearchProviderTest_Episode.cs | 1 + .../SearchProviderTest_Season.cs | 1 + .../UpcomingEpisodesProviderTest.cs | 4 +- NzbDrone.Core.Test/dbBenchmark.cs | 5 +- NzbDrone.Core.Test/packages.config | 6 +- NzbDrone.Core/CentralDispatch.cs | 2 +- .../Instrumentation/DatabaseTarget.cs | 10 +- .../Instrumentation/LogConfiguration.cs | 32 ++- NzbDrone.Core/NzbDrone.Core.csproj | 8 +- NzbDrone.Core/Providers/SeriesProvider.cs | 2 - .../AutoMoq/AutoMoqer.cs | 0 .../AutoMoq/License.txt | 0 .../Unity/AutoMockingBuilderStrategy.cs | 0 .../Unity/AutoMockingContainerExtension.cs | 0 .../ExceptionVerification.cs | 19 +- NzbDrone.Test.Common/LoggingFixtures.cs | 28 +++ .../NzbDrone.Test.Common.csproj | 95 +++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ NzbDrone.Test.Common/packages.config | 8 + NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs | 166 ---------------- NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs | 187 ------------------ NzbDrone.Update.Test/AutoMoq/License.txt | 22 --- .../Unity/AutoMockingBuilderStrategy.cs | 84 -------- .../Unity/AutoMockingContainerExtension.cs | 40 ---- NzbDrone.Update.Test/Fixtures.cs | 8 + .../NzbDrone.Update.Test.csproj | 21 +- NzbDrone.Update.Test/packages.config | 2 - NzbDrone.Update/Providers/UpdateProvider.cs | 4 +- NzbDrone.Web/Global.asax.cs | 2 +- NzbDrone.Web/log.config | 4 - NzbDrone.sln | 20 +- NzbDrone/CentralDispatch.cs | 3 +- NzbDrone/Providers/ConfigProvider.cs | 5 - NzbDrone/Providers/IISProvider.cs | 2 +- packages/repositories.config | 1 + 71 files changed, 526 insertions(+), 1229 deletions(-) delete mode 100644 NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs create mode 100644 NzbDrone.App.Test/Fixtures.cs create mode 100644 NzbDrone.Common.Test/DiskProviderTests.cs create mode 100644 NzbDrone.Common.Test/Fixtures.cs rename {NzbDrone.Core/Instrumentation => NzbDrone.Common}/ExceptioneerTarget.cs (95%) create mode 100644 NzbDrone.Common/LogConfiguration.cs delete mode 100644 NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqer.cs delete mode 100644 NzbDrone.Core.Test/Framework/AutoMoq/License.txt delete mode 100644 NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingBuilderStrategy.cs delete mode 100644 NzbDrone.Core.Test/Framework/AutoMoq/Unity/AutoMockingContainerExtension.cs rename {NzbDrone.App.Test => NzbDrone.Test.Common}/AutoMoq/AutoMoqer.cs (100%) rename {NzbDrone.App.Test => NzbDrone.Test.Common}/AutoMoq/License.txt (100%) rename {NzbDrone.App.Test => NzbDrone.Test.Common}/AutoMoq/Unity/AutoMockingBuilderStrategy.cs (100%) rename {NzbDrone.App.Test => NzbDrone.Test.Common}/AutoMoq/Unity/AutoMockingContainerExtension.cs (100%) rename {NzbDrone.Core.Test/Framework => NzbDrone.Test.Common}/ExceptionVerification.cs (86%) create mode 100644 NzbDrone.Test.Common/LoggingFixtures.cs create mode 100644 NzbDrone.Test.Common/NzbDrone.Test.Common.csproj create mode 100644 NzbDrone.Test.Common/Properties/AssemblyInfo.cs create mode 100644 NzbDrone.Test.Common/packages.config delete mode 100644 NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs delete mode 100644 NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs delete mode 100644 NzbDrone.Update.Test/AutoMoq/License.txt delete mode 100644 NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs delete mode 100644 NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingContainerExtension.cs create mode 100644 NzbDrone.Update.Test/Fixtures.cs diff --git a/.gitignore b/.gitignore index dc442bdbe..62edc661d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ Thumbs.db *.cache *.ilk *.log -[Bb]in +[Bb]in*/ [Dd]ebug*/ *.lib *.sbr diff --git a/NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs b/NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs deleted file mode 100644 index da0677763..000000000 --- a/NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs +++ /dev/null @@ -1,187 +0,0 @@ -// ReSharper disable RedundantUsingDirective -using System; -using AutoMoq; -using Moq; -using NUnit.Framework; - -namespace NzbDrone.App.Test -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class AutoMoqerTest - { - [Test] - public void GetMock_on_interface_returns_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var mock = mocker.GetMock(); - - //Assert - Assert.IsNotNull(mock); - } - - [Test] - public void GetMock_on_concrete_returns_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var mock = mocker.GetMock(); - - //Assert - Assert.IsNotNull(mock); - } - - - [Test] - public void Resolve_doesnt_return_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var result = mocker.Resolve().Do(); - - //Assert - Assert.AreEqual("hello", result); - } - - [Test] - public void Resolve_with_dependency_doesnt_return_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var result = mocker.Resolve().VirtualMethod(); - - //Assert - Assert.AreEqual("hello", result); - } - - [Test] - public void Resolve_with_mocked_dependency_uses_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - mocker.GetMock() - .Setup(m => m.VirtualMethod()) - .Returns("mocked"); - - //Act - var result = mocker.Resolve().CallVirtualChild(); - - //Assert - Assert.AreEqual("mocked", result); - } - - - [Test] - public void Resolve_with_unbound_concerete_dependency_uses_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var result = mocker.Resolve().CallVirtualChild(); - - var mockedResult = new Mock().Object.VirtualMethod(); - - //Assert - Assert.AreEqual(mockedResult, result); - } - - - [Test] - public void Resolve_with_constant_concerete_dependency_uses_constant() - { - //Arrange - var mocker = new AutoMoqer(); - - var constant = new VirtualDependency { PropValue = Guid.NewGuid().ToString() }; - - mocker.SetConstant(constant); - - //Act - var result = mocker.Resolve().GetVirtualProperty(); - - //Assert - Assert.AreEqual(constant.PropValue, result); - } - } - - public class ConcreteClass - { - public string Do() - { - return "hello"; - } - } - - public class Dependency : IDependency - { - } - - public interface IDependency - { - } - - public class ClassWithDependencies - { - public ClassWithDependencies(IDependency dependency) - { - Dependency = dependency; - } - - public IDependency Dependency { get; set; } - } - - public class ClassWithVirtualDependencies - { - private readonly VirtualDependency _virtualDependency; - - public ClassWithVirtualDependencies(IDependency dependency, VirtualDependency virtualDependency) - { - _virtualDependency = virtualDependency; - Dependency = dependency; - } - - public IDependency Dependency { get; set; } - - public string CallVirtualChild() - { - return _virtualDependency.VirtualMethod(); - } - - public string GetVirtualProperty() - { - return _virtualDependency.PropValue; - } - } - - public class VirtualDependency - { - private readonly IDependency _dependency; - - public VirtualDependency() - { - } - - public VirtualDependency(IDependency dependency) - { - _dependency = dependency; - } - - public string PropValue { get; set; } - - public virtual string VirtualMethod() - { - return "hello"; - } - } -} \ No newline at end of file diff --git a/NzbDrone.App.Test/Fixtures.cs b/NzbDrone.App.Test/Fixtures.cs new file mode 100644 index 000000000..b3a5640d5 --- /dev/null +++ b/NzbDrone.App.Test/Fixtures.cs @@ -0,0 +1,8 @@ +// ReSharper disable CheckNamespace +using NUnit.Framework; +using NzbDrone.Test.Common; + +[SetUpFixture] +public class Fixtures : LoggingFixtures +{ +} diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 515023417..1fdbe99ca 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -38,15 +38,6 @@ ..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll - - ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll - - - ..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.dll - - - ..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.Configuration.dll - ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll @@ -72,11 +63,8 @@ - - - - + @@ -93,6 +81,10 @@ {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} NzbDrone.Common + + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} + NzbDrone.Test.Common + {FAFB5948-A222-4CF6-AD14-026BE7564802} NzbDrone.Test.Dummy @@ -102,9 +94,6 @@ NzbDrone - - - + \ No newline at end of file diff --git a/NzbDrone.Test.Common/Properties/AssemblyInfo.cs b/NzbDrone.Test.Common/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..83d18e1be --- /dev/null +++ b/NzbDrone.Test.Common/Properties/AssemblyInfo.cs @@ -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("NzbDrone.Test.Common")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("NzbDrone.Test.Common")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[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("f3e91f6e-d01d-4f20-8255-147cc10f04e3")] + +// 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")] diff --git a/NzbDrone.Test.Common/packages.config b/NzbDrone.Test.Common/packages.config new file mode 100644 index 000000000..56905ca53 --- /dev/null +++ b/NzbDrone.Test.Common/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs b/NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs deleted file mode 100644 index 27b2eee78..000000000 --- a/NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs +++ /dev/null @@ -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 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() - { - ResolveType = typeof(T); - var result = container.Resolve(); - SetConstant(result); - ResolveType = null; - return result; - } - - public virtual Mock GetMock() where T : class - { - return GetMock(DefaultBehavior); - } - - public virtual Mock GetMock(MockBehavior behavior) where T : class - { - ResolveType = null; - var type = GetTheMockType(); - if (GetMockHasNotBeenCalledForThisType(type)) - { - CreateANewMockAndRegisterIt(type, behavior); - } - - var mock = TheRegisteredMockForThisType(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 instance) - { - container.RegisterInstance(instance); - SetMock(instance.GetType(), null); - } - - public ISetup Setup(Expression> expression) where T : class - { - return GetMock().Setup(expression); - } - - public ISetup Setup(Expression> expression) where T : class - { - return GetMock().Setup(expression); - } - - public void Verify(Expression> expression) where T : class - { - GetMock().Verify(expression); - } - - public void Verify(Expression> expression, string failMessage) where T : class - { - GetMock().Verify(expression, failMessage); - } - - public void Verify(Expression> expression, Times times) where T : class - { - GetMock().Verify(expression, times); - } - - public void Verify(Expression> expression, Times times, string failMessage) where T : class - { - GetMock().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(); - AddTheAutoMockingContainerExtensionToTheContainer(container); - } - - private static void AddTheAutoMockingContainerExtensionToTheContainer(IUnityContainer container) - { - container.AddNewExtension(); - return; - } - - private Mock TheRegisteredMockForThisType(Type type) where T : class - { - return (Mock)registeredMocks.Where(x => x.Key == type).First().Value; - } - - private void CreateANewMockAndRegisterIt(Type type, MockBehavior behavior) where T : class - { - var mock = new Mock(behavior); - container.RegisterInstance(mock.Object); - SetMock(type, mock); - } - - private bool GetMockHasNotBeenCalledForThisType(Type type) - { - return registeredMocks.ContainsKey(type) == false; - } - - private static Type GetTheMockType() where T : class - { - return typeof(T); - } - - #endregion - } -} \ No newline at end of file diff --git a/NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs b/NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs deleted file mode 100644 index da0677763..000000000 --- a/NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs +++ /dev/null @@ -1,187 +0,0 @@ -// ReSharper disable RedundantUsingDirective -using System; -using AutoMoq; -using Moq; -using NUnit.Framework; - -namespace NzbDrone.App.Test -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class AutoMoqerTest - { - [Test] - public void GetMock_on_interface_returns_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var mock = mocker.GetMock(); - - //Assert - Assert.IsNotNull(mock); - } - - [Test] - public void GetMock_on_concrete_returns_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var mock = mocker.GetMock(); - - //Assert - Assert.IsNotNull(mock); - } - - - [Test] - public void Resolve_doesnt_return_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var result = mocker.Resolve().Do(); - - //Assert - Assert.AreEqual("hello", result); - } - - [Test] - public void Resolve_with_dependency_doesnt_return_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var result = mocker.Resolve().VirtualMethod(); - - //Assert - Assert.AreEqual("hello", result); - } - - [Test] - public void Resolve_with_mocked_dependency_uses_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - mocker.GetMock() - .Setup(m => m.VirtualMethod()) - .Returns("mocked"); - - //Act - var result = mocker.Resolve().CallVirtualChild(); - - //Assert - Assert.AreEqual("mocked", result); - } - - - [Test] - public void Resolve_with_unbound_concerete_dependency_uses_mock() - { - //Arrange - var mocker = new AutoMoqer(); - - //Act - var result = mocker.Resolve().CallVirtualChild(); - - var mockedResult = new Mock().Object.VirtualMethod(); - - //Assert - Assert.AreEqual(mockedResult, result); - } - - - [Test] - public void Resolve_with_constant_concerete_dependency_uses_constant() - { - //Arrange - var mocker = new AutoMoqer(); - - var constant = new VirtualDependency { PropValue = Guid.NewGuid().ToString() }; - - mocker.SetConstant(constant); - - //Act - var result = mocker.Resolve().GetVirtualProperty(); - - //Assert - Assert.AreEqual(constant.PropValue, result); - } - } - - public class ConcreteClass - { - public string Do() - { - return "hello"; - } - } - - public class Dependency : IDependency - { - } - - public interface IDependency - { - } - - public class ClassWithDependencies - { - public ClassWithDependencies(IDependency dependency) - { - Dependency = dependency; - } - - public IDependency Dependency { get; set; } - } - - public class ClassWithVirtualDependencies - { - private readonly VirtualDependency _virtualDependency; - - public ClassWithVirtualDependencies(IDependency dependency, VirtualDependency virtualDependency) - { - _virtualDependency = virtualDependency; - Dependency = dependency; - } - - public IDependency Dependency { get; set; } - - public string CallVirtualChild() - { - return _virtualDependency.VirtualMethod(); - } - - public string GetVirtualProperty() - { - return _virtualDependency.PropValue; - } - } - - public class VirtualDependency - { - private readonly IDependency _dependency; - - public VirtualDependency() - { - } - - public VirtualDependency(IDependency dependency) - { - _dependency = dependency; - } - - public string PropValue { get; set; } - - public virtual string VirtualMethod() - { - return "hello"; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Update.Test/AutoMoq/License.txt b/NzbDrone.Update.Test/AutoMoq/License.txt deleted file mode 100644 index 5ead6991a..000000000 --- a/NzbDrone.Update.Test/AutoMoq/License.txt +++ /dev/null @@ -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. diff --git a/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs b/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs deleted file mode 100644 index af393fbee..000000000 --- a/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs +++ /dev/null @@ -1,84 +0,0 @@ -// ReSharper disable RedundantUsingDirective -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Microsoft.Practices.ObjectBuilder2; -using Microsoft.Practices.Unity; -using Moq; - -namespace AutoMoq.Unity -{ - internal class AutoMockingBuilderStrategy : BuilderStrategy - { - private readonly IUnityContainer _container; - private readonly MockRepository _mockFactory; - private readonly IEnumerable _registeredTypes; - - public AutoMockingBuilderStrategy(IEnumerable registeredTypes, IUnityContainer container) - { - var autoMoqer = container.Resolve(); - _mockFactory = new MockRepository(autoMoqer.DefaultBehavior); - _registeredTypes = registeredTypes; - _container = container; - } - - public override void PreBuildUp(IBuilderContext context) - { - var autoMoqer = _container.Resolve(); - - var type = GetTheTypeFromTheBuilderContext(context); - if (AMockObjectShouldBeCreatedForThisType(type)) - { - var mock = CreateAMockObject(type); - context.Existing = mock.Object; - autoMoqer.SetMock(type, mock); - } - } - - #region private methods - - private bool AMockObjectShouldBeCreatedForThisType(Type type) - { - var mocker = _container.Resolve(); - return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type); - //return TypeIsNotRegistered(type) && type.IsInterface; - } - - private static Type GetTheTypeFromTheBuilderContext(IBuilderContext context) - { - return (context.OriginalBuildKey).Type; - } - - private bool TypeIsNotRegistered(Type type) - { - return _registeredTypes.Any(x => x.Equals(type)) == false; - } - - private Mock CreateAMockObject(Type type) - { - var createMethod = GenerateAnInterfaceMockCreationMethod(type); - - return InvokeTheMockCreationMethod(createMethod); - } - - private Mock InvokeTheMockCreationMethod(MethodInfo createMethod) - { - return (Mock)createMethod.Invoke(_mockFactory, new object[] { new List().ToArray() }); - } - - private MethodInfo GenerateAnInterfaceMockCreationMethod(Type type) - { - var createMethodWithNoParameters = _mockFactory.GetType().GetMethod("Create", EmptyArgumentList()); - - return createMethodWithNoParameters.MakeGenericMethod(new[] { type }); - } - - private static Type[] EmptyArgumentList() - { - return new[] { typeof(object[]) }; - } - - #endregion - } -} \ No newline at end of file diff --git a/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingContainerExtension.cs b/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingContainerExtension.cs deleted file mode 100644 index d9979df32..000000000 --- a/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingContainerExtension.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ReSharper disable RedundantUsingDirective -using System; -using System.Collections.Generic; -using Microsoft.Practices.Unity; -using Microsoft.Practices.Unity.ObjectBuilder; - -namespace AutoMoq.Unity -{ - internal class AutoMockingContainerExtension : UnityContainerExtension - { - private readonly IList registeredTypes = new List(); - - protected override void Initialize() - { - SetEventsOnContainerToTrackAllRegisteredTypes(); - SetBuildingStrategyForBuildingUnregisteredTypes(); - } - - #region private methods - - private void SetEventsOnContainerToTrackAllRegisteredTypes() - { - Context.Registering += ((sender, e) => RegisterType(e.TypeFrom)); - Context.RegisteringInstance += ((sender, e) => RegisterType(e.RegisteredType)); - } - - private void RegisterType(Type typeToRegister) - { - registeredTypes.Add(typeToRegister); - } - - private void SetBuildingStrategyForBuildingUnregisteredTypes() - { - var strategy = new AutoMockingBuilderStrategy(registeredTypes, Container); - Context.Strategies.Add(strategy, UnityBuildStage.PreCreation); - } - - #endregion - } -} \ No newline at end of file diff --git a/NzbDrone.Update.Test/Fixtures.cs b/NzbDrone.Update.Test/Fixtures.cs new file mode 100644 index 000000000..b3a5640d5 --- /dev/null +++ b/NzbDrone.Update.Test/Fixtures.cs @@ -0,0 +1,8 @@ +// ReSharper disable CheckNamespace +using NUnit.Framework; +using NzbDrone.Test.Common; + +[SetUpFixture] +public class Fixtures : LoggingFixtures +{ +} diff --git a/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj b/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj index e8de74c36..c74d7370e 100644 --- a/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj +++ b/NzbDrone.Update.Test/NzbDrone.Update.Test.csproj @@ -44,15 +44,6 @@ ..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll - - ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll - - - ..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.dll - - - ..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.Configuration.dll - ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll @@ -74,10 +65,7 @@ - - - - + @@ -90,14 +78,15 @@ {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} NzbDrone.Common + + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} + NzbDrone.Test.Common + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7} NzbDrone.Update - - -