mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 05:23:31 -07:00
New: Update Unity
This commit is contained in:
parent
cbff5e1c5a
commit
425bd8964f
5 changed files with 25 additions and 18 deletions
|
@ -1,7 +1,8 @@
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System.IO.Abstractions.TestingHelpers;
|
using System.IO.Abstractions.TestingHelpers;
|
||||||
using Microsoft.Practices.Unity;
|
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
|
using Unity.Resolution;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Framework
|
namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
public abstract class FileSystemTest<TSubject> : CoreTest<TSubject> where TSubject : class
|
public abstract class FileSystemTest<TSubject> : CoreTest<TSubject> where TSubject : class
|
||||||
|
|
|
@ -6,12 +6,13 @@ using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Microsoft.Practices.Unity;
|
using Unity;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Language.Flow;
|
using Moq.Language.Flow;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Test.Common.AutoMoq.Unity;
|
using NzbDrone.Test.Common.AutoMoq.Unity;
|
||||||
|
using Unity.Resolution;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("AutoMoq.Tests")]
|
[assembly: InternalsVisibleTo("AutoMoq.Tests")]
|
||||||
|
|
||||||
|
@ -188,12 +189,18 @@ namespace NzbDrone.Test.Common.AutoMoq
|
||||||
assemblyName = "Lidarr.Mono";
|
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
|
// 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");
|
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)
|
// 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.
|
// if not specified, giving the old behaviour before we switched to System.IO.Abstractions.
|
||||||
SetConstant<IFileSystem>(new FileSystem());
|
SetConstant<IFileSystem>(new FileSystem());
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.Practices.ObjectBuilder2;
|
using Unity;
|
||||||
using Microsoft.Practices.Unity;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using Unity.Strategies;
|
||||||
|
using Unity.Builder;
|
||||||
|
|
||||||
namespace NzbDrone.Test.Common.AutoMoq.Unity
|
namespace NzbDrone.Test.Common.AutoMoq.Unity
|
||||||
{
|
{
|
||||||
|
@ -24,7 +23,7 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity
|
||||||
_container = container;
|
_container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PreBuildUp(IBuilderContext context)
|
public override void PreBuildUp(ref BuilderContext context)
|
||||||
{
|
{
|
||||||
var autoMoqer = _container.Resolve<AutoMoqer>();
|
var autoMoqer = _container.Resolve<AutoMoqer>();
|
||||||
|
|
||||||
|
@ -43,12 +42,12 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity
|
||||||
{
|
{
|
||||||
var mocker = _container.Resolve<AutoMoqer>();
|
var mocker = _container.Resolve<AutoMoqer>();
|
||||||
return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type);
|
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)
|
private bool TypeIsNotRegistered(Type type)
|
||||||
|
@ -82,4 +81,4 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Practices.Unity;
|
using Unity.Builder;
|
||||||
using Microsoft.Practices.Unity.ObjectBuilder;
|
using Unity.Extension;
|
||||||
|
|
||||||
namespace NzbDrone.Test.Common.AutoMoq.Unity
|
namespace NzbDrone.Test.Common.AutoMoq.Unity
|
||||||
{
|
{
|
||||||
|
@ -36,4 +36,4 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<PackageReference Include="NUnit" Version="3.11.0" />
|
<PackageReference Include="NUnit" Version="3.11.0" />
|
||||||
<PackageReference Include="RestSharp" Version="106.6.10" />
|
<PackageReference Include="RestSharp" Version="106.6.10" />
|
||||||
<PackageReference Include="System.IO.Abstractions" Version="4.0.11" />
|
<PackageReference Include="System.IO.Abstractions" Version="4.0.11" />
|
||||||
<PackageReference Include="Unity" Version="4.0.1" />
|
<PackageReference Include="Unity" Version="5.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NzbDrone.Common\Lidarr.Common.csproj" />
|
<ProjectReference Include="..\NzbDrone.Common\Lidarr.Common.csproj" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue