diff --git a/src/NzbDrone.Core.Test/Framework/FileSystemTest.cs b/src/NzbDrone.Core.Test/Framework/FileSystemTest.cs index 8e43591a2..6d37ea2d3 100644 --- a/src/NzbDrone.Core.Test/Framework/FileSystemTest.cs +++ b/src/NzbDrone.Core.Test/Framework/FileSystemTest.cs @@ -1,7 +1,8 @@ using NUnit.Framework; using System.IO.Abstractions.TestingHelpers; -using Microsoft.Practices.Unity; using NzbDrone.Common.Disk; +using Unity.Resolution; + namespace NzbDrone.Core.Test.Framework { public abstract class FileSystemTest : CoreTest where TSubject : class diff --git a/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs b/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs index f83e1d789..04e3de3a7 100644 --- a/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs +++ b/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs @@ -6,12 +6,13 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; -using Microsoft.Practices.Unity; +using Unity; using Moq; using Moq.Language.Flow; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Test.Common.AutoMoq.Unity; +using Unity.Resolution; [assembly: InternalsVisibleTo("AutoMoq.Tests")] @@ -188,12 +189,18 @@ namespace NzbDrone.Test.Common.AutoMoq assemblyName = "Lidarr.Mono"; } - var assembly = Assembly.Load(assemblyName); + var types = Assembly.Load(assemblyName).GetTypes(); // This allows us to resolve the platform specific disk provider in FileSystemTest - var diskProvider = assembly.GetTypes().Where(x => x.Name == "DiskProvider").SingleOrDefault(); + var diskProvider = types.Where(x => x.Name == "DiskProvider").SingleOrDefault(); container.RegisterType(typeof(IDiskProvider), diskProvider, "ActualDiskProvider"); + // This seems to be required now so that Unity can resolve the extra arguments to the + // Mono DiskProvider. I don't understand why we need this now but didn't before. + // It's auto registering everything in the assembly with Ixxx -> xxx. + types.Except(new [] { diskProvider }).Where(t => t.GetInterfaces().Any(i => i.Name == "I" + t.Name)).ToList() + .ForEach(t => container.RegisterType(t.GetInterface("I" + t.Name, false), t)); + // This tells the mocker to resolve IFileSystem using an actual filesystem (and not a mock) // if not specified, giving the old behaviour before we switched to System.IO.Abstractions. SetConstant(new FileSystem()); diff --git a/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs b/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs index b586a3416..1756fe656 100644 --- a/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs +++ b/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingBuilderStrategy.cs @@ -1,12 +1,11 @@ - - -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.Practices.ObjectBuilder2; -using Microsoft.Practices.Unity; +using Unity; using Moq; +using Unity.Strategies; +using Unity.Builder; namespace NzbDrone.Test.Common.AutoMoq.Unity { @@ -24,7 +23,7 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity _container = container; } - public override void PreBuildUp(IBuilderContext context) + public override void PreBuildUp(ref BuilderContext context) { var autoMoqer = _container.Resolve(); @@ -43,12 +42,12 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity { var mocker = _container.Resolve(); return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type); - //return TypeIsNotRegistered(type) && type.IsInterface; } - private static Type GetTheTypeFromTheBuilderContext(IBuilderContext context) + private static Type GetTheTypeFromTheBuilderContext(BuilderContext context) { - return (context.OriginalBuildKey).Type; + // return (context.OriginalBuildKey).Type; + return context.Type; } private bool TypeIsNotRegistered(Type type) @@ -82,4 +81,4 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity #endregion } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs b/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs index 9c6170ce6..b764c929d 100644 --- a/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs +++ b/src/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using Microsoft.Practices.Unity; -using Microsoft.Practices.Unity.ObjectBuilder; +using Unity.Builder; +using Unity.Extension; namespace NzbDrone.Test.Common.AutoMoq.Unity { @@ -36,4 +36,4 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity #endregion } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj b/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj index 417cf6c35..b2327aa32 100644 --- a/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj +++ b/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj @@ -12,7 +12,7 @@ - +