New: Update Unity

pull/980/head
ta264 5 years ago
parent cbff5e1c5a
commit 425bd8964f

@ -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<TSubject> : CoreTest<TSubject> where TSubject : class

@ -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<IFileSystem>(new FileSystem());

@ -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<AutoMoqer>();
@ -43,12 +42,12 @@ namespace NzbDrone.Test.Common.AutoMoq.Unity
{
var mocker = _container.Resolve<AutoMoqer>();
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
}
}
}

@ -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
}
}
}

@ -12,7 +12,7 @@
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="RestSharp" Version="106.6.10" />
<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>
<ProjectReference Include="..\NzbDrone.Common\Lidarr.Common.csproj" />

Loading…
Cancel
Save