This commit is contained in:
ENikS 2023-03-05 12:15:24 -08:00
Родитель 26fc9607ae
Коммит 4ced540846
5 изменённых файлов: 128 добавлений и 108 удалений

Просмотреть файл

@ -23,6 +23,7 @@
<!-- v4 Exclusions -->
<ItemGroup>
<Compile Remove="**\*.!45.cs" />
<Compile Remove="**\*.v5.cs" />
<Compile Remove="**\*.v8.cs" />
@ -39,6 +40,7 @@
<Compile Remove="Patterns\Injection\Annotation\Overrides\Dependency.Import.cs" />
<Compile Remove="Patterns\Injection\Annotation\Overrides\OptionalParameter.cs" />
<Compile Remove="Patterns\Injection\Annotation\Overrides\ResolvedParameter.cs" />
<Compile Remove="Patterns\Injection\Override\Dependency.Injected.!v4.cs" />
<Compile Remove="Patterns\Lifetime\LifetimeManager.cs" />
<Compile Remove="Patterns\Lifetime\LifetimeManager\Disposable.cs" />
<Compile Remove="Patterns\Selection\Implementation\Fields\Annotated.cs" />

Просмотреть файл

@ -5,7 +5,6 @@ using Microsoft.Practices.Unity;
#else
using Unity.Resolution;
using Unity.Injection;
using Unity;
#endif
namespace Regression

Просмотреть файл

@ -118,9 +118,11 @@ namespace Injection
#endif
#if BEHAVIOR_V4 || BEHAVIOR_V5
[TestCategory(CATEGORY_INJECT)]
#if !BEHAVIOR_V4 && !BEHAVIOR_V5
#if BEHAVIOR_V4
#elif BEHAVIOR_V5
[ExpectedException(typeof(InvalidOperationException))]
#else
[ExpectedException(typeof(ResolutionFailedException))]
#endif
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
@ -133,7 +135,6 @@ namespace Injection
}
#else
=> Assert_Fail(NoPublicMember.MakeGenericType(type), InjectionMember_Value(injected));
#endif
#endif
}
}

Просмотреть файл

@ -0,0 +1,122 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Regression;
using System;
using Unity.Injection;
using Unity.Resolution;
namespace Injection
{
public abstract partial class Pattern
{
#region Type
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByType(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestType.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter()),
new DependencyOverride(type, overridden), overridden);
#if BEHAVIOR_V5
[Ignore("https://github.com/unitycontainer/container/issues/140")]
#endif
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByType_Named(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestNamed.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter(Name)),
new DependencyOverride(type, overridden), overridden);
#endregion
#region Name
#if BEHAVIOR_V5
[Ignore("https://github.com/unitycontainer/container/issues/140")]
#endif
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByName(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestType.MakeGenericType(type),
InjectionMember_Value(injected),
new DependencyOverride((string)null, overridden), overridden);
#if BEHAVIOR_V5
[Ignore("https://github.com/unitycontainer/container/issues/140")]
#endif
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByName_Named(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestNamed.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter(Name)),
new DependencyOverride(Name, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByName_NoMatch(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
{
var target = BaselineTestNamed.MakeGenericType(type);
// Arrange
Container.RegisterType(null, target, null, null, InjectionMember_Value(new ResolvedParameter(Name)));
// Register missing types
RegisterTypes();
// Act
var instance = Container.Resolve(target, null, new DependencyOverride((string)null, overridden)) as PatternBaseType;
// Validate
Assert.IsNotNull(instance);
Assert.AreEqual(named, instance.Value);
}
#endregion
#region Contract
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public void Dependency_Injected_ByContract(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestType.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter()),
new DependencyOverride(type, null, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByContract_Named(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestNamed.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter(Name)),
new DependencyOverride(type, Name, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public void Dependency_Injected_ByContract_Ignored(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_FixtureBaseType(BaselineTestType.MakeGenericType(type),
new DependencyOverride(type, Name, overridden),
registered, @default);
#endregion
}
}

Просмотреть файл

@ -14,26 +14,6 @@ namespace Injection
{
#region Type
#if !UNITY_V4
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByType(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestType.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter()),
new DependencyOverride(type, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByType_Named(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestNamed.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter(Name)),
new DependencyOverride(type, overridden), overridden);
#endif
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
@ -45,89 +25,5 @@ namespace Injection
new DependencyOverride(typeof(Pattern), overridden),
injected);
#endregion
#region Name
#if !UNITY_V4
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByName(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestType.MakeGenericType(type),
InjectionMember_Value(injected),
new DependencyOverride((string)null, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByName_Named(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestNamed.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter(Name)),
new DependencyOverride(Name, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByName_NoMatch(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
{
var target = BaselineTestNamed.MakeGenericType(type);
// Arrange
Container.RegisterType(null, target, null, null, InjectionMember_Value(new ResolvedParameter(Name)));
// Register missing types
RegisterTypes();
// Act
var instance = Container.Resolve(target, null, new DependencyOverride((string)null, overridden)) as PatternBaseType;
// Validate
Assert.IsNotNull(instance);
Assert.AreEqual(named, instance.Value);
}
#endif
#endregion
#region Contract
#if !UNITY_V4
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public void Dependency_Injected_ByContract(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestType.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter()),
new DependencyOverride(type, null, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public virtual void Dependency_Injected_ByContract_Named(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_AlwaysSuccessful(BaselineTestNamed.MakeGenericType(type),
InjectionMember_Value(new ResolvedParameter(Name)),
new DependencyOverride(type, Name, overridden), overridden);
[TestProperty(OVERRIDE, nameof(DependencyOverride))]
[DataTestMethod, DynamicData(nameof(Test_Type_Data), typeof(PatternBase))]
public void Dependency_Injected_ByContract_Ignored(string test, Type type, object defaultValue,
object defaultAttr, object registered, object named,
object injected, object overridden, object @default)
=> Assert_FixtureBaseType(BaselineTestType.MakeGenericType(type),
new DependencyOverride(type, Name, overridden),
registered, @default);
#endif
#endregion
}
}