Adding more tests
This commit is contained in:
Родитель
7453459b6e
Коммит
4dced1b64c
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
protected abstract InjectionMember Get_ByName_Member(Type type, string name);
|
||||
|
||||
protected abstract InjectionMember Get_Resolved_Member(Type type, string name);
|
||||
|
||||
protected abstract InjectionMember Get_Optional_Member(Type type, string name);
|
||||
|
||||
protected abstract InjectionMember Get_Generic_Member(Type type, string name);
|
||||
|
||||
protected abstract InjectionMember Get_GenericOptional_Member(Type type, string name);
|
||||
|
||||
|
||||
protected abstract InjectionMember GetInjectionMember(object argument);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Regression.Tests;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by factory
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A resolver is an object that implements "IResolverFactory" interface
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(resolver),
|
||||
/// new InjectionMethod("Method", resolver) ,
|
||||
/// new InjectionField("Field", resolver),
|
||||
/// new InjectionProperty("Property", resolver));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_Implicitly_ByFactory(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(new ValidatingResolverFactory(expected)));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
|
||||
#region From Empty
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by factory from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_Implicitly_ByFactory_FromEmpty(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(new ValidatingResolverFactory(expected)));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -11,8 +11,6 @@ namespace Specification
|
|||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
#region Passing
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by member name
|
||||
/// </summary>
|
||||
|
@ -27,14 +25,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Registered_Data))]
|
||||
[DynamicData(nameof(Registered_Data))]
|
||||
public virtual void Injected_ByName(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetMemberByName());
|
||||
Container.RegisterType(target, Get_ByName_Member(dependency, name));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
|
@ -46,8 +44,6 @@ namespace Specification
|
|||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Required
|
||||
|
||||
|
@ -60,7 +56,7 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Required_Data))]
|
||||
[DynamicData(nameof(Required_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_ByName_Required(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
|
@ -68,7 +64,7 @@ namespace Specification
|
|||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetMemberByName());
|
||||
Container.RegisterType(target, Get_ByName_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(target, name) as PatternBase;
|
||||
|
@ -88,14 +84,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Optional_Data))]
|
||||
[DynamicData(nameof(Optional_Data))]
|
||||
public virtual void Injected_ByName_Optional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetMemberByName());
|
||||
Container.RegisterType(target, Get_ByName_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
@ -119,14 +115,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_WithDefault_Data))]
|
||||
[DynamicData(nameof(Default_Data))]
|
||||
public virtual void Injected_ByName_Default(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetMemberByName());
|
||||
Container.RegisterType(target, Get_ByName_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Regression.Tests;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by resolver
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A resolver is an object that implements "IResolve" interface
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(resolver),
|
||||
/// new InjectionMethod("Method", resolver) ,
|
||||
/// new InjectionField("Field", resolver),
|
||||
/// new InjectionProperty("Property", resolver));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_Implicitly_ByResolver(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(new ValidatingResolver(expected)));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
|
||||
#region From Empty
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by resolver from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_Implicitly_ByResolver_FromEmpty(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(new ValidatingResolver(expected)));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -11,8 +11,6 @@ namespace Specification
|
|||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
#region Passing
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by type
|
||||
/// </summary>
|
||||
|
@ -28,8 +26,8 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Registered_Data))]
|
||||
public virtual void Injected_Implicitly(string test, Type type, string name, Type dependency, object expected)
|
||||
[DynamicData(nameof(Registered_Data))]
|
||||
public virtual void Injected_Implicitly_ByType(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
|
@ -47,8 +45,6 @@ namespace Specification
|
|||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Required
|
||||
|
||||
|
@ -61,7 +57,7 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Required_Data))]
|
||||
[DynamicData(nameof(Required_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_Implicitly_Required(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
|
@ -89,7 +85,7 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Optional_Data))]
|
||||
[DynamicData(nameof(Optional_Data))]
|
||||
public virtual void Injected_Implicitly_Optional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
|
@ -120,7 +116,7 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_WithDefault_Data))]
|
||||
[DynamicData(nameof(Default_Data))]
|
||||
public virtual void Injected_Implicitly_Default(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by value
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(value),
|
||||
/// new InjectionMethod("Method", value) ,
|
||||
/// new InjectionField("Field", value),
|
||||
/// new InjectionProperty("Property", value));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_Implicitly_ByValue(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(expected));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
|
||||
#region From Empty
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by value from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_Implicitly_ByValue_FromEmpty(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(expected));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
/// <summary>
|
||||
/// Testing unsupported parapeter types
|
||||
/// </summary>
|
||||
/// <example>
|
||||
///
|
||||
/// public class PocoType
|
||||
/// {
|
||||
/// [InjectionConstructor]
|
||||
/// public PocoType(ref int value) { }
|
||||
///
|
||||
/// [InjectionMethod]
|
||||
/// public void Method(out int value) { }
|
||||
/// }
|
||||
///
|
||||
/// </example>
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Parameter_Data))]
|
||||
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
|
||||
public virtual void Injected_Implicitly_Parameter(string target, Type dependency)
|
||||
{
|
||||
var type = TargetType(target);
|
||||
|
||||
// Arrange
|
||||
Container.RegisterType(type, GetInjectionMember(dependency));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(type);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Parameter_Data))]
|
||||
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
|
||||
public virtual void Injected_ByName_Parameter(string target, Type dependency)
|
||||
{
|
||||
var type = TargetType(target);
|
||||
|
||||
// Arrange
|
||||
Container.RegisterType(type, GetMemberByName());
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(type);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Parameter_Data))]
|
||||
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
|
||||
public virtual void Injected_ByResolving_Parameter(string target, Type dependency)
|
||||
{
|
||||
var type = TargetType(target);
|
||||
|
||||
// Arrange
|
||||
Container.RegisterType(type, GetResolvedMember(dependency, null));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(type);
|
||||
}
|
||||
|
||||
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Parameter_Data))]
|
||||
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
|
||||
public virtual void Injected_ByOptional_Parameter(string target, Type dependency)
|
||||
{
|
||||
var type = TargetType(target);
|
||||
|
||||
// Arrange
|
||||
Container.RegisterType(type, GetOptionalMember(dependency, null));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(type);
|
||||
}
|
||||
|
||||
|
||||
#region Test Data
|
||||
|
||||
public static IEnumerable<object[]> Parameter_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// // Type Dependency
|
||||
|
||||
yield return new object[] { "Implicit_Dependency_Ref", typeof(Unresolvable) };
|
||||
yield return new object[] { "Implicit_Dependency_Out", typeof(Unresolvable) };
|
||||
yield return new object[] { "Required_Dependency_Ref", typeof(Unresolvable) };
|
||||
yield return new object[] { "Required_Dependency_Out", typeof(Unresolvable) };
|
||||
yield return new object[] { "Optional_Dependency_Ref", typeof(Unresolvable) };
|
||||
yield return new object[] { "Optional_Dependency_Out", typeof(Unresolvable) };
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
using Unity.Regression.Tests;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by factory wrapped in parameter
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A resolver is an object that implements "IResolve" interface
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new InjectionParameter(factory)),
|
||||
/// new InjectionMethod("Method", new InjectionParameter(factory)) ,
|
||||
/// new InjectionField("Field", new InjectionParameter(factory)),
|
||||
/// new InjectionProperty("Property", new InjectionParameter(factory)));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_ByFactory(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
var factory = new ValidatingResolverFactory(expected);
|
||||
var parameter = new InjectionParameter(dependency, factory);
|
||||
Container.RegisterType(target, name, GetInjectionMember(parameter));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by factory wrapped in parameter from empty container
|
||||
/// </summary>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_ByFactory_FromEmpty(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
var factory = new ValidatingResolverFactory(expected);
|
||||
var parameter = new InjectionParameter(dependency, factory);
|
||||
Container.RegisterType(target, name, GetInjectionMember(parameter));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
#region Passing
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by generic parameter
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new GenericParameter(T)),
|
||||
/// new InjectionMethod("Method", new GenericParameter(T)) ,
|
||||
/// new InjectionField("Field", new GenericParameter(T)),
|
||||
/// new InjectionProperty("Property", new GenericParameter(T)));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Registered_Data))]
|
||||
public virtual void Injected_ByGeneric(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) return;
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
RegisterTypes();
|
||||
|
||||
Container.RegisterType(definition, Get_Generic_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Required
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by generic parameter required dependencies from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Required_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_ByGeneric_Required(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) throw new ResolutionFailedException(type, name, "Not Generic");
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
Container.RegisterType(definition, Get_Generic_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(target) as PatternBase;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Optional
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by generic parameter optional dependencies from empty container
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The injection member overrides Optional attribute and throws if dependency
|
||||
/// could not be resolved.
|
||||
/// </remarks>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Optional_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_ByGeneric_Optional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) throw new ResolutionFailedException(type, name, "Not Generic");
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
Container.RegisterType(definition, Get_Generic_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(target) as PatternBase;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region With Default
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by generic parameter dependencies with default from empty container
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Injected member overrides existing default and either is resolved or throws
|
||||
/// </remarks>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Default_Data))]
|
||||
public virtual void Injected_ByGeneric_Default(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) return;
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
RegisterTypes();
|
||||
|
||||
Container.RegisterType(definition, Get_Generic_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
#region Passing
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by optional generic parameter
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new OptionalGenericParameter(T)),
|
||||
/// new InjectionMethod("Method", new OptionalGenericParameter(T)) ,
|
||||
/// new InjectionField("Field", new OptionalGenericParameter(T)),
|
||||
/// new InjectionProperty("Property", new OptionalGenericParameter(T)));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Registered_Data))]
|
||||
public virtual void Injected_ByGenericOptional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) return;
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
RegisterTypes();
|
||||
|
||||
Container.RegisterType(definition, Get_GenericOptional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Required
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by optional generic parameter required dependencies from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Required_Data))]
|
||||
public virtual void Injected_ByGenericOptional_Required(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) return;
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
Container.RegisterType(definition, Get_GenericOptional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Optional
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by optional generic parameter optional dependencies from empty container
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The injection member overrides Optional attribute and throws if dependency
|
||||
/// could not be resolved.
|
||||
/// </remarks>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Optional_Data))]
|
||||
public virtual void Injected_ByGenericOptional_Optional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) return;
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
Container.RegisterType(definition, Get_GenericOptional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region With Default
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by optional generic parameter dependencies with default from empty container
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Injected member overrides existing default and either is resolved or throws
|
||||
/// </remarks>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Default_Data))]
|
||||
public virtual void Injected_ByGenericOptional_Default(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
if (!type.IsGenericType) return;
|
||||
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
// Arrange
|
||||
Container.RegisterType(definition, Get_GenericOptional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by value wrapped in parameter
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new InjectionParameter(value)),
|
||||
/// new InjectionMethod("Method", new InjectionParameter(value)) ,
|
||||
/// new InjectionField("Field", new InjectionParameter(value)),
|
||||
/// new InjectionProperty("Property", new InjectionParameter(value)));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_ByInjection(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(new InjectionParameter(dependency, expected)));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by value wrapped in parameter from empty container
|
||||
/// </summary>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_ByInjection_FromEmpty(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, name, GetInjectionMember(new InjectionParameter(dependency, expected)));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace Specification
|
|||
#region Passing
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by resolution
|
||||
/// Tests injecting dependencies by optional parameter
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new OptionalParameter(type)),
|
||||
|
@ -28,14 +28,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Registered_Data))]
|
||||
[DynamicData(nameof(Registered_Data))]
|
||||
public virtual void Injected_ByOptional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetOptionalMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Optional_Member(dependency, name));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace Specification
|
|||
#region Required
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by resolution required dependencies from empty container
|
||||
/// Tests injecting by optional parameter required dependencies from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
|
@ -61,14 +61,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Required_Data))]
|
||||
[DynamicData(nameof(Required_Data))]
|
||||
public virtual void Injected_ByOptional_Required(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetOptionalMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Optional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
@ -84,7 +84,7 @@ namespace Specification
|
|||
#region Optional
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by resolution optional dependencies from empty container
|
||||
/// Tests injecting by optional parameter optional dependencies from empty container
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The injection member overrides Optional attribute and throws if dependency
|
||||
|
@ -96,14 +96,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Optional_Data))]
|
||||
[DynamicData(nameof(Optional_Data))]
|
||||
public virtual void Injected_ByOptional_Optional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetOptionalMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Optional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
||||
|
@ -119,7 +119,7 @@ namespace Specification
|
|||
#region With Default
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting by resolution dependencies with default from empty container
|
||||
/// Tests injecting by optional parameter dependencies with default from empty container
|
||||
/// </summary>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
|
@ -127,14 +127,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_WithDefault_Data))]
|
||||
[DynamicData(nameof(Default_Data))]
|
||||
public virtual void Injected_ByOptional_Default(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetOptionalMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Optional_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
|
@ -0,0 +1,118 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
/// <summary>
|
||||
/// Testing unsupported (out and ref) parapeter types
|
||||
/// </summary>
|
||||
/// <example>
|
||||
///
|
||||
/// public class PocoType
|
||||
/// {
|
||||
/// [InjectionConstructor]
|
||||
/// public PocoType(ref int value) { }
|
||||
///
|
||||
/// [InjectionMethod]
|
||||
/// public void Method(out int value) { }
|
||||
/// }
|
||||
///
|
||||
/// </example>
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting of REF and OUT parameters with various ways
|
||||
/// </summary>
|
||||
/// <param name="target">Name of test type</param>
|
||||
/// <param name="method"></param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Parameter_Validation_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_Parameters(string target, string method)
|
||||
{
|
||||
var type = Type.GetType(target ?? throw new InvalidOperationException());
|
||||
|
||||
Type constructed = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(typeof(Unresolvable))
|
||||
: type;
|
||||
|
||||
InjectionMember member;
|
||||
|
||||
try
|
||||
{
|
||||
var factory = GetType().GetMethod(method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
member = (InjectionMember)factory.Invoke(this, new[] { typeof(Unresolvable), null });
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
when (ex.InnerException is NotSupportedException)
|
||||
{
|
||||
throw new ResolutionFailedException(typeof(Unresolvable), null, "Not Supported");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
Type definition = type.IsGenericTypeDefinition
|
||||
? type
|
||||
: type.GetGenericTypeDefinition();
|
||||
|
||||
Container.RegisterType(definition, member);
|
||||
}
|
||||
else
|
||||
{
|
||||
Container.RegisterType(type, member);
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
throw new ResolutionFailedException(typeof(Unresolvable), null, "Invalid Registration");
|
||||
}
|
||||
|
||||
|
||||
// Arrange
|
||||
RegisterTypes();
|
||||
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(constructed) as PatternBase;
|
||||
}
|
||||
|
||||
#region Test Data
|
||||
|
||||
public static IEnumerable<object[]> Parameter_Validation_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var info in typeof(VerificationPattern).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
.Where(method => method.Name.StartsWith("Get_") && method.Name.EndsWith("_Member"))
|
||||
.Select(method => method.Name))
|
||||
{
|
||||
yield return new object[] { Type_Implicit_Dependency_Ref, info };
|
||||
yield return new object[] { Type_Implicit_Dependency_Out, info };
|
||||
yield return new object[] { Type_Implicit_Generic_Ref, info };
|
||||
yield return new object[] { Type_Implicit_Generic_Out, info };
|
||||
yield return new object[] { Type_Required_Dependency_Ref, info };
|
||||
yield return new object[] { Type_Required_Dependency_Out, info };
|
||||
yield return new object[] { Type_Required_Generic_Ref, info };
|
||||
yield return new object[] { Type_Required_Generic_Out, info };
|
||||
yield return new object[] { Type_Optional_Dependency_Ref, info };
|
||||
yield return new object[] { Type_Optional_Dependency_Out, info };
|
||||
yield return new object[] { Type_Optional_Generic_Ref, info };
|
||||
yield return new object[] { Type_Optional_Generic_Out, info };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
using Unity.Regression.Tests;
|
||||
#endif
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
public abstract partial class VerificationPattern
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by resolver wrapped in parameter
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A resolver is an object that implements "IResolve" interface
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new InjectionParameter(resolver)),
|
||||
/// new InjectionMethod("Method", new InjectionParameter(resolver)) ,
|
||||
/// new InjectionField("Field", new InjectionParameter(resolver)),
|
||||
/// new InjectionProperty("Property", new InjectionParameter(resolver)));
|
||||
/// </example>
|
||||
/// <param name="test">Test name</param>
|
||||
/// <param name="type">Resolved type</param>
|
||||
/// <param name="name">Contract name</param>
|
||||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_ByResolver(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
var resolver = new ValidatingResolver(expected);
|
||||
var parameter = new InjectionParameter(dependency, resolver);
|
||||
Container.RegisterType(target, name, GetInjectionMember(parameter));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by resolver wrapped in parameter from empty container
|
||||
/// </summary>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Injected_Data))]
|
||||
public virtual void Injected_ByResolver_FromEmpty(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
var resolver = new ValidatingResolver(expected);
|
||||
var parameter = new InjectionParameter(dependency, resolver);
|
||||
Container.RegisterType(target, name, GetInjectionMember(parameter));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target, name) as PatternBase;
|
||||
|
||||
// Validate
|
||||
Assert.IsNotNull(instance);
|
||||
Assert.AreEqual(expected, instance.Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace Specification
|
|||
#region Passing
|
||||
|
||||
/// <summary>
|
||||
/// Tests injecting dependencies by resolution
|
||||
/// Tests injecting dependencies by resolution parameter
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// Container.RegisterType(target, new InjectionConstructor(new ResolvedParameter(type)),
|
||||
|
@ -28,14 +28,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Registered_Data))]
|
||||
[DynamicData(nameof(Registered_Data))]
|
||||
public virtual void Injected_ByResolving(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetResolvedMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Resolved_Member(dependency, name));
|
||||
|
||||
RegisterTypes();
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Required_Data))]
|
||||
[DynamicData(nameof(Required_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_ByResolving_Required(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ namespace Specification
|
|||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetResolvedMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Resolved_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(target, name) as PatternBase;
|
||||
|
@ -93,7 +93,7 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_Optional_Data))]
|
||||
[DynamicData(nameof(Optional_Data))]
|
||||
[ExpectedException(typeof(ResolutionFailedException))]
|
||||
public virtual void Injected_ByResolving_Optional(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ namespace Specification
|
|||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetResolvedMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Resolved_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
_ = Container.Resolve(target) as PatternBase;
|
||||
|
@ -124,14 +124,14 @@ namespace Specification
|
|||
/// <param name="dependency">Dependency type</param>
|
||||
/// <param name="expected">Expected value</param>
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Inject_WithDefault_Data))]
|
||||
[DynamicData(nameof(Default_Data))]
|
||||
public virtual void Injected_ByResolving_Default(string test, Type type, string name, Type dependency, object expected)
|
||||
{
|
||||
Type target = type.IsGenericTypeDefinition
|
||||
? type.MakeGenericType(dependency)
|
||||
: type;
|
||||
// Arrange
|
||||
Container.RegisterType(target, GetResolvedMember(dependency, name));
|
||||
Container.RegisterType(target, Get_Resolved_Member(dependency, name));
|
||||
|
||||
// Act
|
||||
var instance = Container.Resolve(target) as PatternBase;
|
|
@ -11,7 +11,7 @@ namespace Specification
|
|||
public abstract partial class VerificationPattern
|
||||
{
|
||||
// Passing Registered Data
|
||||
public static IEnumerable<object[]> Inject_Registered_Data
|
||||
public static IEnumerable<object[]> Injected_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -20,15 +20,60 @@ namespace Specification
|
|||
|
||||
// Implicit
|
||||
|
||||
yield return new object[] { "Value", PocoType, null, typeof(int), RegisteredInt };
|
||||
yield return new object[] { "Class", PocoType, null, typeof(Unresolvable), Singleton };
|
||||
yield return new object[] { "Struct", PocoType, null, typeof(TestStruct), RegisteredStruct };
|
||||
yield return new object[] { "Implicit_Value", PocoType, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Implicit_Class", PocoType, null, typeof(Unresolvable), InjectedSingleton };
|
||||
|
||||
yield return new object[] { "Value_Type_Name", PocoType, null, typeof(int), RegisteredInt };
|
||||
yield return new object[] { "Class_Type_Name", PocoType, null, typeof(Unresolvable), Singleton };
|
||||
yield return new object[] { "Implicit_Value_Type_Name", PocoType, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Implicit_Class_Type_Name", PocoType, null, typeof(Unresolvable), InjectedSingleton };
|
||||
|
||||
yield return new object[] { "Default_Value", PocoType_Default_Value, null, typeof(int), RegisteredInt };
|
||||
yield return new object[] { "Default_Class", PocoType_Default_Class, null, typeof(string), RegisteredString };
|
||||
yield return new object[] { "Implicit_Default_Value", PocoType_Default_Value, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Implicit_Default_Class", PocoType_Default_Class, null, typeof(string), InjectedString };
|
||||
|
||||
// Required
|
||||
|
||||
yield return new object[] { "Required_Value", Required, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Required_Class", Required, null, typeof(Unresolvable), InjectedSingleton };
|
||||
|
||||
yield return new object[] { "Required_Value_Named", Required_Named, Name, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Required_Class_Named", Required_Named, Name, typeof(Unresolvable), InjectedSingleton };
|
||||
|
||||
yield return new object[] { "Required_Default_Value", Required_Default_Value, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Required_Default_Class", Required_Default_String, null, typeof(string), InjectedString };
|
||||
|
||||
//// Optional
|
||||
|
||||
yield return new object[] { "Optional_Value", Optional, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Optional_Class", Optional, null, typeof(Unresolvable), InjectedSingleton };
|
||||
|
||||
yield return new object[] { "Optional_Value_Named", Optional_Named, Name, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Optional_Class_Named", Optional_Named, Name, typeof(Unresolvable), InjectedSingleton };
|
||||
|
||||
yield return new object[] { "Optional_Default_Value", Optional_Default_Value, null, typeof(int), InjectedInt };
|
||||
yield return new object[] { "Optional_Default_Class", Optional_Default_Class, null, typeof(string), InjectedString };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Passing Registered Data
|
||||
public static IEnumerable<object[]> Registered_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Name Type Name Dependency Expected
|
||||
|
||||
// Implicit
|
||||
|
||||
yield return new object[] { "Implicit_Value", PocoType, null, typeof(int), RegisteredInt };
|
||||
yield return new object[] { "Implicit_Class", PocoType, null, typeof(Unresolvable), Singleton };
|
||||
yield return new object[] { "Implicit_Struct", PocoType, null, typeof(TestStruct), RegisteredStruct };
|
||||
|
||||
yield return new object[] { "Implicit_Value_Type_Name", PocoType, null, typeof(int), RegisteredInt };
|
||||
yield return new object[] { "Implicit_Class_Type_Name", PocoType, null, typeof(Unresolvable), Singleton };
|
||||
|
||||
yield return new object[] { "Implicit_Default_Value", PocoType_Default_Value, null, typeof(int), RegisteredInt };
|
||||
yield return new object[] { "Implicit_Default_Class", PocoType_Default_Class, null, typeof(string), RegisteredString };
|
||||
|
||||
// Required
|
||||
|
||||
|
@ -57,15 +102,15 @@ namespace Specification
|
|||
}
|
||||
|
||||
// With Default Data
|
||||
public static IEnumerable<object[]> Inject_WithDefault_Data
|
||||
public static IEnumerable<object[]> Default_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Name Type Name Dependency Expected
|
||||
|
||||
yield return new object[] { "Default_Value", PocoType_Default_Value, null, typeof(int), DefaultInt };
|
||||
yield return new object[] { "Default_Class", PocoType_Default_Class, null, typeof(string), DefaultString };
|
||||
yield return new object[] { "Implicit_Default_Value", PocoType_Default_Value, null, typeof(int), DefaultInt };
|
||||
yield return new object[] { "Implicit_Default_Class", PocoType_Default_Class, null, typeof(string), DefaultString };
|
||||
|
||||
yield return new object[] { "Required_Default_Value", Required_Default_Value, null, typeof(int), DefaultInt };
|
||||
yield return new object[] { "Required_Default_Class", Required_Default_String, null, typeof(string), DefaultString };
|
||||
|
@ -77,7 +122,7 @@ namespace Specification
|
|||
|
||||
|
||||
// Optional Data
|
||||
public static IEnumerable<object[]> Inject_Optional_Data
|
||||
public static IEnumerable<object[]> Optional_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -94,23 +139,23 @@ namespace Specification
|
|||
|
||||
// Required Data
|
||||
|
||||
public static IEnumerable<object[]> Inject_Required_Data
|
||||
public static IEnumerable<object[]> Required_Data
|
||||
{
|
||||
get
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Name Type Name Dependency Expected
|
||||
|
||||
yield return new object[] { "Value", PocoType, null, typeof(int), 0 };
|
||||
yield return new object[] { "Class", PocoType, null, typeof(Unresolvable), null };
|
||||
//yield return new object[] { "Struct", PocoType, null, typeof(TestStruct), };
|
||||
yield return new object[] { "Required_Value", PocoType, null, typeof(int), 0 };
|
||||
yield return new object[] { "Required_Class", PocoType, null, typeof(Unresolvable), null };
|
||||
//yield return new object[] { "Required_Struct", PocoType, null, typeof(TestStruct), };
|
||||
|
||||
yield return new object[] { "Value_Type_Name", PocoType, Name, typeof(int), 0 };
|
||||
yield return new object[] { "Class_Type_Name", PocoType, Name, typeof(Unresolvable), null };
|
||||
yield return new object[] { "Required_Value_Type_Name", PocoType, Name, typeof(int), 0 };
|
||||
yield return new object[] { "Required_Class_Type_Name", PocoType, Name, typeof(Unresolvable), null };
|
||||
|
||||
yield return new object[] { "Required_Value", Required, null, typeof(int), 0 };
|
||||
yield return new object[] { "Required_Class", Required, null, typeof(Unresolvable), null };
|
||||
//yield return new object[] { "Required_Struct", Required, null, typeof(TestStruct), };
|
||||
//yield return new object[] { "Required_Struct", Required, null, typeof(TestStruct), };
|
||||
|
||||
yield return new object[] { "Required_Value_Named", Required_Named, null, typeof(int), 0 };
|
||||
yield return new object[] { "Required_Class_Named", Required_Named, null, typeof(Unresolvable), null };
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Specification
|
|||
{
|
||||
#region Fields
|
||||
|
||||
// Test Constants
|
||||
protected const int NamedInt = 123;
|
||||
protected const int DefaultInt = 345;
|
||||
protected const int InjectedInt = 678;
|
||||
|
@ -29,16 +30,29 @@ namespace Specification
|
|||
public readonly static Unresolvable InjectedSingleton = SubUnresolvable.Create("injected");
|
||||
public readonly static object RegisteredStruct = new TestStruct(55, "struct");
|
||||
|
||||
// Generic type names
|
||||
protected static string Type_Implicit_Dependency_Ref;
|
||||
protected static string Type_Implicit_Dependency_Out;
|
||||
protected static string Type_Implicit_Generic_Ref;
|
||||
protected static string Type_Implicit_Generic_Out;
|
||||
protected static string Type_Required_Dependency_Ref;
|
||||
protected static string Type_Required_Dependency_Out;
|
||||
protected static string Type_Required_Generic_Ref;
|
||||
protected static string Type_Required_Generic_Out;
|
||||
protected static string Type_Optional_Dependency_Ref;
|
||||
protected static string Type_Optional_Dependency_Out;
|
||||
protected static string Type_Optional_Generic_Ref;
|
||||
protected static string Type_Optional_Generic_Out;
|
||||
|
||||
// Test types
|
||||
protected static Type PocoType;
|
||||
protected static Type Required;
|
||||
protected static Type Optional;
|
||||
protected static Type Required_Named;
|
||||
protected static Type Optional_Named;
|
||||
|
||||
protected static Type PocoType_Default_Value;
|
||||
protected static Type Required_Default_Value;
|
||||
protected static Type Optional_Default_Value;
|
||||
|
||||
protected static Type PocoType_Default_Class;
|
||||
protected static Type Required_Default_String;
|
||||
protected static Type Optional_Default_Class;
|
||||
|
@ -70,16 +84,6 @@ namespace Specification
|
|||
.RegisterInstance(Name, NamedSingleton);
|
||||
}
|
||||
|
||||
protected abstract InjectionMember GetMemberByName();
|
||||
|
||||
protected abstract InjectionMember GetInjectionMethodBase(object argument);
|
||||
|
||||
protected abstract InjectionMember GetResolvedMember(Type type, string name);
|
||||
|
||||
protected abstract InjectionMember GetOptionalMember(Type type, string name);
|
||||
|
||||
protected abstract InjectionMember GetInjectionMember(object argument);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Specification
|
||||
{
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification.Pattern
|
||||
{
|
||||
[TestClass]
|
||||
public partial class Constructors : VerificationPattern
|
||||
{
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
PocoType = typeof(Implicit_Dependency_Generic<>);
|
||||
Required = typeof(Required_Dependency_Generic<>);
|
||||
Optional = typeof(Optional_Dependency_Generic<>);
|
||||
|
||||
Required_Named = typeof(Required_Dependency_Named<>);
|
||||
Optional_Named = typeof(Optional_Dependency_Named<>);
|
||||
|
||||
PocoType_Default_Value = typeof(Implicit_WithDefault_Value);
|
||||
Required_Default_Value = typeof(Required_WithDefault_Value);
|
||||
Optional_Default_Value = typeof(Optional_WithDefault_Value);
|
||||
|
||||
PocoType_Default_Class = typeof(Implicit_WithDefault_Class);
|
||||
Required_Default_String = typeof(Required_WithDefault_Class);
|
||||
Optional_Default_Class = typeof(Optional_WithDefault_Class);
|
||||
|
||||
|
||||
Type_Implicit_Dependency_Ref = typeof(Implicit_Dependency_Ref).FullName;
|
||||
Type_Implicit_Dependency_Out = typeof(Implicit_Dependency_Out).FullName;
|
||||
Type_Implicit_Generic_Ref = typeof(Implicit_Generic_Ref<>).FullName;
|
||||
Type_Implicit_Generic_Out = typeof(Implicit_Generic_Out<>).FullName;
|
||||
Type_Required_Dependency_Ref = typeof(Required_Dependency_Ref).FullName;
|
||||
Type_Required_Dependency_Out = typeof(Required_Dependency_Out).FullName;
|
||||
Type_Required_Generic_Ref = typeof(Required_Generic_Ref<>).FullName;
|
||||
Type_Required_Generic_Out = typeof(Required_Generic_Out<>).FullName;
|
||||
Type_Optional_Dependency_Ref = typeof(Optional_Dependency_Ref).FullName;
|
||||
Type_Optional_Dependency_Out = typeof(Optional_Dependency_Out).FullName;
|
||||
Type_Optional_Generic_Ref = typeof(Optional_Generic_Ref<>).FullName;
|
||||
Type_Optional_Generic_Out = typeof(Optional_Generic_Out<>).FullName;
|
||||
}
|
||||
|
||||
|
||||
protected override InjectionMember Get_ByName_Member(Type type, string name)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
protected override InjectionMember Get_Resolved_Member(Type type, string name)
|
||||
=> new InjectionConstructor(new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember Get_Optional_Member(Type type, string name)
|
||||
=> new InjectionConstructor(new OptionalParameter(type, name));
|
||||
|
||||
protected override InjectionMember Get_Generic_Member(Type _, string name)
|
||||
=> new InjectionConstructor(new GenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember Get_GenericOptional_Member(Type type, string name)
|
||||
=> new InjectionConstructor(new OptionalGenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember GetInjectionMember(object argument)
|
||||
=> new InjectionConstructor(argument);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification.Pattern
|
||||
{
|
||||
[TestClass]
|
||||
public partial class Constructors : VerificationPattern
|
||||
{
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
PocoType = typeof(Implicit_Dependency_Generic<>);
|
||||
Required = typeof(Required_Dependency_Generic<>);
|
||||
Optional = typeof(Optional_Dependency_Generic<>);
|
||||
|
||||
Required_Named = typeof(Required_Dependency_Named<>);
|
||||
Optional_Named = typeof(Optional_Dependency_Named<>);
|
||||
|
||||
PocoType_Default_Value = typeof(Implicit_WithDefault_Value);
|
||||
Required_Default_Value = typeof(Required_WithDefault_Value);
|
||||
Optional_Default_Value = typeof(Optional_WithDefault_Value);
|
||||
|
||||
PocoType_Default_Class = typeof(Implicit_WithDefault_Class);
|
||||
Required_Default_String = typeof(Required_WithDefault_Class);
|
||||
Optional_Default_Class = typeof(Optional_WithDefault_Class);
|
||||
}
|
||||
|
||||
|
||||
protected override InjectionMember GetMemberByName()
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
protected override InjectionMember GetInjectionMethodBase(object argument)
|
||||
=> new InjectionConstructor(argument);
|
||||
|
||||
protected override InjectionMember GetResolvedMember(Type type, string name)
|
||||
=> new InjectionConstructor(new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember GetOptionalMember(Type type, string name)
|
||||
=> new InjectionConstructor(new OptionalParameter(type, name));
|
||||
|
||||
protected override InjectionMember GetInjectionMember(object argument)
|
||||
=> new InjectionConstructor(argument);
|
||||
}
|
||||
}
|
|
@ -27,16 +27,6 @@ namespace Specification.Pattern
|
|||
public Implicit_Dependency_Dynamic(dynamic value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Ref : PatternBase
|
||||
{
|
||||
public Implicit_Dependency_Ref(ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Out : PatternBase
|
||||
{
|
||||
public Implicit_Dependency_Out(out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Generic<T> : PatternBase
|
||||
{
|
||||
public Implicit_Dependency_Generic(T value) => Value = value;
|
||||
|
@ -72,16 +62,6 @@ namespace Specification.Pattern
|
|||
public Required_Dependency_Dynamic([Dependency] dynamic value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Ref : PatternBase
|
||||
{
|
||||
public Required_Dependency_Ref([Dependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Out : PatternBase
|
||||
{
|
||||
public Required_Dependency_Out([Dependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Generic<T> : PatternBase
|
||||
{
|
||||
public Required_Dependency_Generic([Dependency] T value) => Value = value;
|
||||
|
@ -122,16 +102,6 @@ namespace Specification.Pattern
|
|||
public Optional_Dependency_Dynamic([OptionalDependency] dynamic value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Ref : PatternBase
|
||||
{
|
||||
public Optional_Dependency_Ref([OptionalDependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Out : PatternBase
|
||||
{
|
||||
public Optional_Dependency_Out([OptionalDependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Generic<T> : PatternBase
|
||||
{
|
||||
public Optional_Dependency_Generic([OptionalDependency] T value) => Value = value;
|
||||
|
@ -153,5 +123,72 @@ namespace Specification.Pattern
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Unsupported
|
||||
|
||||
public class Implicit_Dependency_Ref : PatternBase
|
||||
{
|
||||
public Implicit_Dependency_Ref(ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Out : PatternBase
|
||||
{
|
||||
public Implicit_Dependency_Out(out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Implicit_Generic_Ref<T> : PatternBase where T : class
|
||||
{
|
||||
public Implicit_Generic_Ref(ref T value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Generic_Out<T> : PatternBase where T : class
|
||||
{
|
||||
public Implicit_Generic_Out(out T value) => value = null;
|
||||
}
|
||||
|
||||
|
||||
public class Required_Dependency_Ref : PatternBase
|
||||
{
|
||||
public Required_Dependency_Ref([Dependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Out : PatternBase
|
||||
{
|
||||
public Required_Dependency_Out([Dependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Required_Generic_Ref<T> : PatternBase where T : class
|
||||
{
|
||||
public Required_Generic_Ref([Dependency] ref T value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Generic_Out<T> : PatternBase where T : class
|
||||
{
|
||||
public Required_Generic_Out([Dependency] out T value) => value = null;
|
||||
}
|
||||
|
||||
|
||||
public class Optional_Dependency_Ref : PatternBase
|
||||
{
|
||||
public Optional_Dependency_Ref([OptionalDependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Out : PatternBase
|
||||
{
|
||||
public Optional_Dependency_Out([OptionalDependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Optional_Generic_Ref<T> : PatternBase where T : class
|
||||
{
|
||||
public Optional_Generic_Ref([OptionalDependency] ref T value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Generic_Out<T> : PatternBase where T : class
|
||||
{
|
||||
public Optional_Generic_Out([OptionalDependency] out T value) => value = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace Specification.Pattern
|
|||
public override void Injected_ByName_Required(string test, Type type, string name, Type dependency, object expected) { }
|
||||
public override void Injected_ByName_Optional(string test, Type type, string name, Type dependency, object expected) { }
|
||||
public override void Injected_ByName_Default(string test, Type type, string name, Type dependency, object expected) { }
|
||||
public override void Injected_ByName_Parameter(string target, Type dependency) { }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,18 +31,21 @@ namespace Specification.Pattern
|
|||
Optional_Default_Class = typeof(Optional_WithDefault_Class);
|
||||
}
|
||||
|
||||
protected override InjectionMember GetMemberByName()
|
||||
protected override InjectionMember Get_ByName_Member(Type type, string name)
|
||||
=> new InjectionField("Field");
|
||||
|
||||
protected override InjectionMember GetInjectionMethodBase(object argument)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
protected override InjectionMember GetResolvedMember(Type type, string name)
|
||||
protected override InjectionMember Get_Resolved_Member(Type type, string name)
|
||||
=> new InjectionField("Field", new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember GetOptionalMember(Type type, string name)
|
||||
protected override InjectionMember Get_Optional_Member(Type type, string name)
|
||||
=> new InjectionField("Field", new OptionalParameter(type, name));
|
||||
|
||||
protected override InjectionMember Get_Generic_Member(Type _, string name)
|
||||
=> new InjectionField("Field", new GenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember Get_GenericOptional_Member(Type type, string name)
|
||||
=> new InjectionField("Field", new OptionalGenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember GetInjectionMember(object argument)
|
||||
=> new InjectionField("Field", argument);
|
||||
}
|
|
@ -23,9 +23,6 @@ namespace Specification.Pattern
|
|||
// Fields do not support parameters
|
||||
public override void Implicit_Parameters(string name) { }
|
||||
public override void Annotated_Parameters(string target) { }
|
||||
public override void Injected_ByName_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_Implicitly_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_ByResolving_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_ByOptional_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_Parameters(string target, string method) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification.Pattern
|
||||
{
|
||||
[TestClass]
|
||||
public partial class Methods : VerificationPattern
|
||||
{
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
PocoType = typeof(Implicit_Dependency_Generic<>);
|
||||
Required = typeof(Required_Dependency_Generic<>);
|
||||
Optional = typeof(Optional_Dependency_Generic<>);
|
||||
|
||||
Required_Named = typeof(Required_Dependency_Named<>);
|
||||
Optional_Named = typeof(Optional_Dependency_Named<>);
|
||||
|
||||
PocoType_Default_Value = typeof(Implicit_WithDefault_Value);
|
||||
Required_Default_Value = typeof(Required_WithDefault_Value);
|
||||
Optional_Default_Value = typeof(Optional_WithDefault_Value);
|
||||
|
||||
PocoType_Default_Class = typeof(Implicit_WithDefault_Class);
|
||||
Required_Default_String = typeof(Required_WithDefault_Class);
|
||||
Optional_Default_Class = typeof(Optional_WithDefault_Class);
|
||||
|
||||
|
||||
Type_Implicit_Dependency_Ref = typeof(Implicit_Dependency_Ref).FullName;
|
||||
Type_Implicit_Dependency_Out = typeof(Implicit_Dependency_Out).FullName;
|
||||
Type_Implicit_Generic_Ref = typeof(Implicit_Generic_Ref<>).FullName;
|
||||
Type_Implicit_Generic_Out = typeof(Implicit_Generic_Out<>).FullName;
|
||||
Type_Required_Dependency_Ref = typeof(Required_Dependency_Ref).FullName;
|
||||
Type_Required_Dependency_Out = typeof(Required_Dependency_Out).FullName;
|
||||
Type_Required_Generic_Ref = typeof(Required_Generic_Ref<>).FullName;
|
||||
Type_Required_Generic_Out = typeof(Required_Generic_Out<>).FullName;
|
||||
Type_Optional_Dependency_Ref = typeof(Optional_Dependency_Ref).FullName;
|
||||
Type_Optional_Dependency_Out = typeof(Optional_Dependency_Out).FullName;
|
||||
Type_Optional_Generic_Ref = typeof(Optional_Generic_Ref<>).FullName;
|
||||
Type_Optional_Generic_Out = typeof(Optional_Generic_Out<>).FullName;
|
||||
}
|
||||
|
||||
protected override InjectionMember Get_ByName_Member(Type type, string name)
|
||||
=> new InjectionMethod("Method");
|
||||
|
||||
protected override InjectionMember Get_Resolved_Member(Type type, string name)
|
||||
=> new InjectionMethod("Method", new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember Get_Optional_Member(Type type, string name)
|
||||
=> new InjectionMethod("Method", new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember Get_Generic_Member(Type _, string name)
|
||||
=> new InjectionMethod("Method", new GenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember Get_GenericOptional_Member(Type type, string name)
|
||||
=> new InjectionMethod("Method", new OptionalGenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember GetInjectionMember(object argument)
|
||||
=> new InjectionMethod("Method", argument);
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
#if V4
|
||||
using Microsoft.Practices.Unity;
|
||||
#else
|
||||
using Unity;
|
||||
using Unity.Injection;
|
||||
#endif
|
||||
|
||||
namespace Specification.Pattern
|
||||
{
|
||||
[TestClass]
|
||||
public partial class Methods : VerificationPattern
|
||||
{
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
PocoType = typeof(Implicit_Dependency_Generic<>);
|
||||
Required = typeof(Required_Dependency_Generic<>);
|
||||
Optional = typeof(Optional_Dependency_Generic<>);
|
||||
|
||||
Required_Named = typeof(Required_Dependency_Named<>);
|
||||
Optional_Named = typeof(Optional_Dependency_Named<>);
|
||||
|
||||
PocoType_Default_Value = typeof(Implicit_WithDefault_Value);
|
||||
Required_Default_Value = typeof(Required_WithDefault_Value);
|
||||
Optional_Default_Value = typeof(Optional_WithDefault_Value);
|
||||
|
||||
PocoType_Default_Class = typeof(Implicit_WithDefault_Class);
|
||||
Required_Default_String = typeof(Required_WithDefault_Class);
|
||||
Optional_Default_Class = typeof(Optional_WithDefault_Class);
|
||||
}
|
||||
|
||||
protected override InjectionMember GetMemberByName()
|
||||
=> new InjectionMethod("Method");
|
||||
|
||||
protected override InjectionMember GetInjectionMethodBase(object argument)
|
||||
=> new InjectionMethod("Method", argument);
|
||||
|
||||
protected override InjectionMember GetResolvedMember(Type type, string name)
|
||||
=> new InjectionMethod("Method", new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember GetOptionalMember(Type type, string name)
|
||||
=> new InjectionMethod("Method", new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember GetInjectionMember(object argument)
|
||||
=> new InjectionMethod("Method", argument);
|
||||
}
|
||||
}
|
|
@ -30,18 +30,6 @@ namespace Specification.Pattern
|
|||
public void Method(dynamic value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Ref : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method(ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Out : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method(out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Generic<T> : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
|
@ -83,18 +71,6 @@ namespace Specification.Pattern
|
|||
public void Method([Dependency] dynamic value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Ref : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([Dependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Out : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([Dependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Generic<T> : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
|
@ -142,18 +118,6 @@ namespace Specification.Pattern
|
|||
public void Method([OptionalDependency] dynamic value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Ref : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([OptionalDependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Out : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([OptionalDependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Generic<T> : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
|
@ -191,5 +155,89 @@ namespace Specification.Pattern
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region Unsupported
|
||||
|
||||
|
||||
public class Implicit_Dependency_Ref : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method(ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Dependency_Out : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method(out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Implicit_Generic_Ref<T> : PatternBase where T : class
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method(ref T value) => Value = value;
|
||||
}
|
||||
|
||||
public class Implicit_Generic_Out<T> : PatternBase where T : class
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method(out T value) => value = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class Required_Dependency_Ref : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([Dependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Dependency_Out : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([Dependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Required_Generic_Ref<T> : PatternBase where T : class
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([Dependency] ref T value) => Value = value;
|
||||
}
|
||||
|
||||
public class Required_Generic_Out<T> : PatternBase where T : class
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([Dependency] out T value) => value = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class Optional_Dependency_Ref : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([OptionalDependency] ref Unresolvable value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Dependency_Out : PatternBase
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([OptionalDependency] out Unresolvable value) => value = null;
|
||||
}
|
||||
|
||||
public class Optional_Generic_Ref<T> : PatternBase where T : class
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([OptionalDependency] ref T value) => Value = value;
|
||||
}
|
||||
|
||||
public class Optional_Generic_Out<T> : PatternBase where T : class
|
||||
{
|
||||
[InjectionMethod]
|
||||
public void Method([OptionalDependency] out T value) => value = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,18 +31,22 @@ namespace Specification.Pattern
|
|||
Optional_Default_Class = typeof(Optional_WithDefault_Class);
|
||||
}
|
||||
|
||||
protected override InjectionMember GetMemberByName()
|
||||
protected override InjectionMember Get_ByName_Member(Type type, string name)
|
||||
=> new InjectionProperty("Property");
|
||||
|
||||
protected override InjectionMember GetInjectionMethodBase(object argument)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
protected override InjectionMember GetResolvedMember(Type type, string name)
|
||||
protected override InjectionMember Get_Resolved_Member(Type type, string name)
|
||||
=> new InjectionProperty("Property", new ResolvedParameter(type, name));
|
||||
|
||||
protected override InjectionMember GetOptionalMember(Type type, string name)
|
||||
protected override InjectionMember Get_Optional_Member(Type type, string name)
|
||||
=> new InjectionProperty("Property", new OptionalParameter(type, name));
|
||||
|
||||
protected override InjectionMember Get_Generic_Member(Type _, string name)
|
||||
=> new InjectionProperty("Property", new GenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember Get_GenericOptional_Member(Type type, string name)
|
||||
=> new InjectionProperty("Property", new OptionalGenericParameter("T", name));
|
||||
|
||||
protected override InjectionMember GetInjectionMember(object argument)
|
||||
=> new InjectionProperty("Property", argument);
|
||||
}
|
|
@ -22,9 +22,6 @@ namespace Specification.Pattern
|
|||
// Properties do not support parameters
|
||||
public override void Implicit_Parameters(string name) { }
|
||||
public override void Annotated_Parameters(string target) { }
|
||||
public override void Injected_ByName_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_Implicitly_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_ByResolving_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_ByOptional_Parameter(string target, Type dependency) { }
|
||||
public override void Injected_Parameters(string target, string method) { }
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче