test: Adding more tests for Injection Parameters
This commit is contained in:
Родитель
f5977a862d
Коммит
18508876ca
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Unity.Injection
|
namespace Unity.Injection
|
||||||
|
@ -8,7 +7,6 @@ namespace Unity.Injection
|
||||||
/// A base class for implementing <see cref="ParameterValue"/> classes
|
/// A base class for implementing <see cref="ParameterValue"/> classes
|
||||||
/// that deal in explicit types.
|
/// that deal in explicit types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DebuggerDisplay("Parameter: {ParameterType?.Name ?? \"Any Type\"}")]
|
|
||||||
public abstract class ParameterBase : ParameterValue
|
public abstract class ParameterBase : ParameterValue
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
namespace Unity.Injection
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Unity.Injection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A <see cref="ParameterValue"/> that lets you specify that
|
/// A <see cref="ParameterValue"/> that lets you specify that
|
||||||
/// an instance of a generic type parameter should be resolved.
|
/// an instance of a generic type parameter should be resolved.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerDisplay("GenericParameter: Type={ParameterTypeName}")]
|
||||||
public class GenericParameter : GenericBase
|
public class GenericParameter : GenericBase
|
||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
@ -28,5 +31,15 @@
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Overrides
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"GenericParameter: Type={ParameterTypeName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Unity.Resolution;
|
using Unity.Resolution;
|
||||||
|
@ -10,6 +11,7 @@ namespace Unity.Injection
|
||||||
/// an array containing the registered instances of a generic type parameter
|
/// an array containing the registered instances of a generic type parameter
|
||||||
/// should be resolved.
|
/// should be resolved.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerDisplay("GenericResolvedArrayParameter: Type={ParameterTypeName}")]
|
||||||
public class GenericResolvedArrayParameter : GenericBase
|
public class GenericResolvedArrayParameter : GenericBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
@ -88,6 +90,11 @@ namespace Unity.Injection
|
||||||
return (ref TContext context) => resolverMethod.Invoke(ref context, values);
|
return (ref TContext context) => resolverMethod.Invoke(ref context, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"GenericResolvedArrayParameter: Type={ParameterTypeName}";
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using Unity.Resolution;
|
using Unity.Resolution;
|
||||||
|
|
||||||
namespace Unity.Injection
|
namespace Unity.Injection
|
||||||
|
@ -8,6 +9,7 @@ namespace Unity.Injection
|
||||||
/// the required <see cref="IResolve"/>
|
/// the required <see cref="IResolve"/>
|
||||||
/// when the container is configured.
|
/// when the container is configured.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerDisplay("InjectionParameter: Type={ParameterType.Name ?? \"Any\"} Value={_value ?? \"null\"}")]
|
||||||
public class InjectionParameter : ParameterBase, IResolve
|
public class InjectionParameter : ParameterBase, IResolve
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
@ -55,6 +57,16 @@ namespace Unity.Injection
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Overrides
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"InjectionParameter: Type={ParameterType.Name} Value={_value ?? "null"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Unity.Exceptions;
|
using Unity.Exceptions;
|
||||||
using Unity.Resolution;
|
using Unity.Resolution;
|
||||||
|
@ -10,6 +11,7 @@ namespace Unity.Injection
|
||||||
/// <see cref="IUnityContainer.RegisterType"/> to configure a
|
/// <see cref="IUnityContainer.RegisterType"/> to configure a
|
||||||
/// parameter or property as an optional dependency.
|
/// parameter or property as an optional dependency.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerDisplay("OptionalParameter: Type={ParameterType?.Name ?? \"Any\"} Name={_name ?? \"null\"}")]
|
||||||
public class OptionalParameter : ParameterBase,
|
public class OptionalParameter : ParameterBase,
|
||||||
IResolverFactory<Type>,
|
IResolverFactory<Type>,
|
||||||
IResolverFactory<ParameterInfo>
|
IResolverFactory<ParameterInfo>
|
||||||
|
@ -126,6 +128,16 @@ namespace Unity.Injection
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Overrides
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"OptionalParameter: Type={ParameterType?.Name ?? "Any"} Name={_name ?? "null"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Unity.Resolution;
|
using Unity.Resolution;
|
||||||
|
@ -10,6 +11,7 @@ namespace Unity.Injection
|
||||||
/// resolver object that resolves all the named instances or the
|
/// resolver object that resolves all the named instances or the
|
||||||
/// type registered in a container.
|
/// type registered in a container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerDisplay("ResolvedArrayParameter: Type={ParameterType.Name}")]
|
||||||
public class ResolvedArrayParameter : ParameterBase,
|
public class ResolvedArrayParameter : ParameterBase,
|
||||||
IResolverFactory<Type>,
|
IResolverFactory<Type>,
|
||||||
IResolverFactory<ParameterInfo>
|
IResolverFactory<ParameterInfo>
|
||||||
|
@ -136,6 +138,16 @@ namespace Unity.Injection
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Overrides
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"ResolvedArrayParameter: Type={ParameterType.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Implementation
|
#region Implementation
|
||||||
|
|
||||||
private static object DoResolve<TContext, TElement>(ref TContext context, object[] values)
|
private static object DoResolve<TContext, TElement>(ref TContext context, object[] values)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Unity.Resolution;
|
using Unity.Resolution;
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ namespace Unity.Injection
|
||||||
/// resolver object that resolves the parameter via the
|
/// resolver object that resolves the parameter via the
|
||||||
/// container.
|
/// container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DebuggerDisplay("ResolvedParameter: Type={ParameterType?.Name ?? \"Any\"} Name={_name ?? \"null\"}")]
|
||||||
public class ResolvedParameter : ParameterBase,
|
public class ResolvedParameter : ParameterBase,
|
||||||
IResolverFactory<Type>,
|
IResolverFactory<Type>,
|
||||||
IResolverFactory<ParameterInfo>
|
IResolverFactory<ParameterInfo>
|
||||||
|
@ -105,6 +107,16 @@ namespace Unity.Injection
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Overrides
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"ResolvedParameter: Type={ParameterType?.Name ?? "Any"} Name={_name ?? "null"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -0,0 +1,152 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Unity.Injection;
|
||||||
|
|
||||||
|
namespace Injection.Parameters
|
||||||
|
{
|
||||||
|
public class ParameterBaseData
|
||||||
|
{
|
||||||
|
#region Test Data
|
||||||
|
|
||||||
|
private static ParameterInfo ParamInfo =
|
||||||
|
typeof(ParameterValueTests).GetMethod(nameof(GenericBaseTestMethod))
|
||||||
|
.GetParameters()
|
||||||
|
.First();
|
||||||
|
|
||||||
|
private static ParameterInfo ArrayInfo =
|
||||||
|
typeof(ParameterValueTests).GetMethod(nameof(GenericBaseTestMethod))
|
||||||
|
.GetParameters()
|
||||||
|
.Last();
|
||||||
|
|
||||||
|
private static ParameterInfo AddInfo =
|
||||||
|
typeof(List<>).GetMethod("Add")
|
||||||
|
.GetParameters()
|
||||||
|
.First();
|
||||||
|
|
||||||
|
private static ParameterInfo AddStringInfo =
|
||||||
|
typeof(List<string>).GetMethod("Add")
|
||||||
|
.GetParameters()
|
||||||
|
.First();
|
||||||
|
|
||||||
|
public void GenericBaseTestMethod<TName, TArray>(TName value, TArray[] array) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetEqualsAnyTypeData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new OptionalParameter(), };
|
||||||
|
yield return new object[] { new OptionalParameter(string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedParameter() };
|
||||||
|
yield return new object[] { new ResolvedParameter(string.Empty) };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetEqualsValueTypeData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new InjectionParameter(0) };
|
||||||
|
yield return new object[] { new InjectionParameter(typeof(int), 0) };
|
||||||
|
yield return new object[] { new InjectionParameter<int>(0) };
|
||||||
|
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(int)) };
|
||||||
|
yield return new object[] { new OptionalParameter<int>() };
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(int), string.Empty) };
|
||||||
|
yield return new object[] { new OptionalParameter<int>(string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(int)) };
|
||||||
|
yield return new object[] { new ResolvedParameter<int>() };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(int), string.Empty) };
|
||||||
|
yield return new object[] { new ResolvedParameter<int>(string.Empty) };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetEqualsArrayTypeData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(string[])) };
|
||||||
|
yield return new object[] { new OptionalParameter<string[]>() };
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(string[]), string.Empty) };
|
||||||
|
yield return new object[] { new OptionalParameter<string[]>(string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(string[])) };
|
||||||
|
yield return new object[] { new ResolvedParameter<string[]>() };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(string[]), string.Empty) };
|
||||||
|
yield return new object[] { new ResolvedParameter<string[]>(string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string)) };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter<string>() };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), "string") };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), "string") };
|
||||||
|
|
||||||
|
yield return new object[] { new InjectionParameter(new string[0]) };
|
||||||
|
yield return new object[] { new InjectionParameter(typeof(string[]), new string[0]) };
|
||||||
|
yield return new object[] { new InjectionParameter<string[]>(new string[0]) };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetEqualsGenericTypeData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new InjectionParameter(typeof(List<>), 0) };
|
||||||
|
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(List<>)) };
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(List<>), string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(List<>)) };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(List<>), string.Empty) };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetEqualsGenericArrayTypeData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new InjectionParameter(typeof(List<>), 0) };
|
||||||
|
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(List<>)) };
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(List<>), string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(List<>)) };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(List<>), string.Empty) };
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(List<>)) };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(List<>), 0) };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(List<>), typeof(int), 0) };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetEqualsBaseTypeData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new InjectionParameter(0) };
|
||||||
|
yield return new object[] { new InjectionParameter(typeof(int), 0) };
|
||||||
|
yield return new object[] { new InjectionParameter<string[]>(new string[0]) };
|
||||||
|
|
||||||
|
yield return new object[] { new OptionalParameter(), };
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(int)) };
|
||||||
|
yield return new object[] { new OptionalParameter<int>() };
|
||||||
|
yield return new object[] { new OptionalParameter(string.Empty) };
|
||||||
|
yield return new object[] { new OptionalParameter(typeof(int), string.Empty) };
|
||||||
|
yield return new object[] { new OptionalParameter<int>(string.Empty) };
|
||||||
|
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedParameter() };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(int)) };
|
||||||
|
yield return new object[] { new ResolvedParameter<int>() };
|
||||||
|
yield return new object[] { new ResolvedParameter(string.Empty) };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(int), string.Empty) };
|
||||||
|
yield return new object[] { new ResolvedParameter<int>(string.Empty) };
|
||||||
|
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedArrayParameter<int>() };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(int)) };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(int), 0) };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(int), typeof(int), 0) };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,12 @@
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using Unity.Injection;
|
using Unity.Injection;
|
||||||
|
|
||||||
namespace Injection.Parameters
|
namespace Injection.Parameters
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public abstract class ParameterBaseTests
|
public class ParameterBaseTests
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public virtual void ParameterTypeTest()
|
public virtual void ParameterTypeTest()
|
||||||
|
@ -18,9 +16,51 @@ namespace Injection.Parameters
|
||||||
|
|
||||||
#region IEquatable
|
#region IEquatable
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public virtual void EqualsTest()
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(ParameterBaseData.GetEqualsAnyTypeData), typeof(ParameterBaseData), DynamicDataSourceType.Method)]
|
||||||
|
public virtual void EqualsAnyTypeTest(ParameterValue parameter)
|
||||||
{
|
{
|
||||||
|
// Validate
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(int)));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(object)));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(string)));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(List<>)));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(List<string>)));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(string[])));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(object[])));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(int[])));
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(ParameterBaseData.GetEqualsValueTypeData), typeof(ParameterBaseData), DynamicDataSourceType.Method)]
|
||||||
|
public virtual void EqualsValueTypeTest(ParameterValue parameter)
|
||||||
|
{
|
||||||
|
// Validate
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(int)));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(object)));
|
||||||
|
Assert.IsFalse(parameter.Equals(typeof(string)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(ParameterBaseData.GetEqualsArrayTypeData), typeof(ParameterBaseData), DynamicDataSourceType.Method)]
|
||||||
|
public virtual void EqualsArrayTypeTest(ParameterValue parameter)
|
||||||
|
{
|
||||||
|
// Validate
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(string[])));
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(object[])));
|
||||||
|
Assert.IsFalse(parameter.Equals(typeof(int)));
|
||||||
|
Assert.IsFalse(parameter.Equals(typeof(int[])));
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(ParameterBaseData.GetEqualsGenericTypeData), typeof(ParameterBaseData), DynamicDataSourceType.Method)]
|
||||||
|
public virtual void EqualsGenericTypeTest(ParameterValue parameter)
|
||||||
|
{
|
||||||
|
// Validate
|
||||||
|
Assert.IsTrue(parameter.Equals(typeof(List<>)));
|
||||||
|
Assert.IsFalse(parameter.Equals(typeof(IEnumerable<>)));
|
||||||
|
Assert.IsFalse(parameter.Equals(typeof(List<string>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
|
using Unity.Injection;
|
||||||
|
|
||||||
|
namespace Injection.Parameters
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ParameterValidationTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void InjectionParameterCtorTest()
|
||||||
|
{
|
||||||
|
new InjectionParameter(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Issue https://github.com/unitycontainer/abstractions/issues/146
|
||||||
|
[Ignore]
|
||||||
|
[TestMethod]
|
||||||
|
public void ResolvedArrayParameterCtorTest()
|
||||||
|
{
|
||||||
|
new ResolvedArrayParameter(null, typeof(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void ResolvedArrayParameterElementTest()
|
||||||
|
{
|
||||||
|
new ResolvedArrayParameter(typeof(string), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,17 @@ namespace Injection.Parameters
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(GetToStringData), DynamicDataSourceType.Method)]
|
||||||
|
public void ToStringTest(ParameterValue parameter)
|
||||||
|
{
|
||||||
|
var name = parameter.GetType().Name;
|
||||||
|
|
||||||
|
Assert.IsTrue(parameter.ToString().StartsWith(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(GetEqualsData), DynamicDataSourceType.Method)]
|
[DynamicData(nameof(GetEqualsData), DynamicDataSourceType.Method)]
|
||||||
public virtual void EqualsTest(ParameterValue parameter, Type type, bool result)
|
public virtual void EqualsTest(ParameterValue parameter, Type type, bool result)
|
||||||
|
@ -44,84 +55,94 @@ namespace Injection.Parameters
|
||||||
Assert.AreEqual(result, parameter.Equals(type));
|
Assert.AreEqual(result, parameter.Equals(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetType<T>
|
#region Test Data
|
||||||
{
|
public static IEnumerable<object[]> GetToStringData()
|
||||||
|
{
|
||||||
|
yield return new object[] { new InjectionParameter(string.Empty) };
|
||||||
|
yield return new object[] { new InjectionParameter(typeof(string), null) };
|
||||||
|
yield return new object[] { new OptionalParameter() };
|
||||||
|
yield return new object[] { new ResolvedParameter() };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string)) };
|
||||||
|
yield return new object[] { new GenericParameter("T[]") };
|
||||||
|
yield return new object[] { new GenericResolvedArrayParameter("T[]") };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> GetEqualsData()
|
public static IEnumerable<object[]> GetEqualsData()
|
||||||
{
|
{
|
||||||
|
|
||||||
yield return new object[] { new InjectionParameter(typeof(List<string>), string.Empty), typeof(List<>), false };
|
yield return new object[] { new InjectionParameter(typeof(List<string>), string.Empty), typeof(List<>), false };
|
||||||
yield return new object[] { new InjectionParameter(typeof(List<string>), string.Empty), typeof(List<string>), true };
|
yield return new object[] { new InjectionParameter(typeof(List<string>), string.Empty), typeof(List<string>), true };
|
||||||
yield return new object[] { new InjectionParameter(typeof(List<>), string.Empty), typeof(List<string>), false };
|
yield return new object[] { new InjectionParameter(typeof(List<>), string.Empty), typeof(List<string>), false };
|
||||||
yield return new object[] { new InjectionParameter(typeof(List<>), string.Empty), typeof(List<>), true };
|
yield return new object[] { new InjectionParameter(typeof(List<>), string.Empty), typeof(List<>), true };
|
||||||
yield return new object[] { new InjectionParameter(AddInfo.ParameterType, string.Empty), AddInfo.ParameterType, true };
|
yield return new object[] { new InjectionParameter(AddInfo.ParameterType, string.Empty), AddInfo.ParameterType, true };
|
||||||
yield return new object[] { new InjectionParameter(AddInfo.ParameterType, string.Empty), AddStringInfo.ParameterType, false };
|
yield return new object[] { new InjectionParameter(AddInfo.ParameterType, string.Empty), AddStringInfo.ParameterType, false };
|
||||||
yield return new object[] { new InjectionParameter(string.Empty), typeof(string), true };
|
yield return new object[] { new InjectionParameter(string.Empty), typeof(string), true };
|
||||||
yield return new object[] { new InjectionParameter(typeof(string), string.Empty), typeof(string), true };
|
yield return new object[] { new InjectionParameter(typeof(string), string.Empty), typeof(string), true };
|
||||||
yield return new object[] { new InjectionParameter(string.Empty), ParamInfo.ParameterType, false };
|
yield return new object[] { new InjectionParameter(string.Empty), ParamInfo.ParameterType, false };
|
||||||
yield return new object[] { new InjectionParameter(typeof(string), string.Empty), ParamInfo.ParameterType, false };
|
yield return new object[] { new InjectionParameter(typeof(string), string.Empty), ParamInfo.ParameterType, false };
|
||||||
yield return new object[] { new InjectionParameter(ParamInfo.ParameterType, string.Empty), ParamInfo.ParameterType, true };
|
yield return new object[] { new InjectionParameter(ParamInfo.ParameterType, string.Empty), ParamInfo.ParameterType, true };
|
||||||
|
|
||||||
|
|
||||||
yield return new object[] { new OptionalParameter(), typeof(string), true };
|
yield return new object[] { new OptionalParameter(), typeof(string), true };
|
||||||
yield return new object[] { new OptionalParameter(), typeof(object), true };
|
yield return new object[] { new OptionalParameter(), typeof(object), true };
|
||||||
yield return new object[] { new OptionalParameter(), typeof(double), true };
|
yield return new object[] { new OptionalParameter(), typeof(double), true };
|
||||||
yield return new object[] { new OptionalParameter(typeof(string)), typeof(string), true };
|
yield return new object[] { new OptionalParameter(typeof(string)), typeof(string), true };
|
||||||
yield return new object[] { new OptionalParameter(typeof(string)), typeof(object), true };
|
yield return new object[] { new OptionalParameter(typeof(string)), typeof(object), true };
|
||||||
yield return new object[] { new OptionalParameter(typeof(string)), typeof(double), false };
|
yield return new object[] { new OptionalParameter(typeof(string)), typeof(double), false };
|
||||||
yield return new object[] { new OptionalParameter(string.Empty), typeof(string), true };
|
yield return new object[] { new OptionalParameter(string.Empty), typeof(string), true };
|
||||||
yield return new object[] { new OptionalParameter(string.Empty), typeof(object), true };
|
yield return new object[] { new OptionalParameter(string.Empty), typeof(object), true };
|
||||||
yield return new object[] { new OptionalParameter(string.Empty), typeof(double), true };
|
yield return new object[] { new OptionalParameter(string.Empty), typeof(double), true };
|
||||||
yield return new object[] { new OptionalParameter(typeof(string), string.Empty), typeof(string), true };
|
yield return new object[] { new OptionalParameter(typeof(string), string.Empty), typeof(string), true };
|
||||||
yield return new object[] { new OptionalParameter(typeof(string), string.Empty), typeof(object), true };
|
yield return new object[] { new OptionalParameter(typeof(string), string.Empty), typeof(object), true };
|
||||||
yield return new object[] { new OptionalParameter(typeof(string), string.Empty), typeof(double), false };
|
yield return new object[] { new OptionalParameter(typeof(string), string.Empty), typeof(double), false };
|
||||||
|
|
||||||
|
|
||||||
yield return new object[] { new ResolvedParameter(), typeof(string), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(), typeof(object), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(), typeof(double), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(typeof(string)), typeof(string), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(typeof(string)), typeof(object), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(typeof(string)), typeof(double), false };
|
|
||||||
yield return new object[] { new ResolvedParameter(string.Empty), typeof(string), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(string.Empty), typeof(double), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(typeof(string), string.Empty), typeof(string), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(typeof(string), string.Empty), typeof(object), true };
|
|
||||||
yield return new object[] { new ResolvedParameter(typeof(string), string.Empty), typeof(double), false };
|
|
||||||
|
|
||||||
|
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string)), typeof(string[]), true };
|
yield return new object[] { new ResolvedParameter(), typeof(string), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string)), typeof(object[]), true };
|
yield return new object[] { new ResolvedParameter(), typeof(object), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string)), typeof(double[]), false };
|
yield return new object[] { new ResolvedParameter(), typeof(double), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string), string.Empty), typeof(string[]), true };
|
yield return new object[] { new ResolvedParameter(typeof(string)), typeof(string), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string), string.Empty), typeof(object[]), true };
|
yield return new object[] { new ResolvedParameter(typeof(string)), typeof(object), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string), string.Empty), typeof(double[]), false };
|
yield return new object[] { new ResolvedParameter(typeof(string)), typeof(double), false };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), string.Empty), typeof(string[]), true };
|
yield return new object[] { new ResolvedParameter(string.Empty), typeof(string), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), string.Empty), typeof(object[]), true };
|
yield return new object[] { new ResolvedParameter(string.Empty), typeof(double), true };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(string), string.Empty), typeof(string), true };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(string), string.Empty), typeof(object), true };
|
||||||
|
yield return new object[] { new ResolvedParameter(typeof(string), string.Empty), typeof(double), false };
|
||||||
|
|
||||||
|
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string)), typeof(string[]), true };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string)), typeof(object[]), true };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string)), typeof(double[]), false };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), string.Empty), typeof(string[]), true };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), string.Empty), typeof(object[]), true };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), string.Empty), typeof(double[]), false };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), string.Empty), typeof(string[]), true };
|
||||||
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), string.Empty), typeof(object[]), true };
|
||||||
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), string.Empty), typeof(double[]), false };
|
yield return new object[] { new ResolvedArrayParameter(typeof(string), typeof(string), string.Empty), typeof(double[]), false };
|
||||||
|
|
||||||
|
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), ParamInfo.ParameterType, true };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), ParamInfo.ParameterType, true };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), ParamInfo.ParameterType, true };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), ParamInfo.ParameterType, true };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), ParamInfo.ParameterType, true };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), ParamInfo.ParameterType, true };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), ParamInfo.ParameterType, true };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), ParamInfo.ParameterType, true };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), ArrayInfo.ParameterType, false };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), ArrayInfo.ParameterType, false };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), ArrayInfo.ParameterType, false };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), ArrayInfo.ParameterType, false };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), typeof(string), false };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name), typeof(string), false };
|
||||||
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), typeof(string), false };
|
yield return new object[] { new GenericParameter(ParamInfo.ParameterType.Name, string.Empty), typeof(string), false };
|
||||||
yield return new object[] { new GenericParameter("T[]"), AddInfo.ParameterType, false };
|
yield return new object[] { new GenericParameter("T[]"), AddInfo.ParameterType, false };
|
||||||
yield return new object[] { new GenericParameter("T[]"), AddInfo.ParameterType.MakeArrayType(), true };
|
yield return new object[] { new GenericParameter("T[]"), AddInfo.ParameterType.MakeArrayType(), true };
|
||||||
yield return new object[] { new GenericParameter("TArray[]"), ArrayInfo.ParameterType, true };
|
yield return new object[] { new GenericParameter("TArray[]"), ArrayInfo.ParameterType, true };
|
||||||
|
|
||||||
|
|
||||||
yield return new object[] { new GenericResolvedArrayParameter("T[]"), typeof(List<string>[]), false };
|
yield return new object[] { new GenericResolvedArrayParameter("T[]"), typeof(List<string>[]), false };
|
||||||
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name), ArrayInfo.ParameterType, true };
|
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name), ArrayInfo.ParameterType, true };
|
||||||
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name, string.Empty), ArrayInfo.ParameterType, true };
|
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name, string.Empty), ArrayInfo.ParameterType, true };
|
||||||
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name), typeof(string), false };
|
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name), typeof(string), false };
|
||||||
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name, string.Empty), typeof(string), false };
|
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name, string.Empty), typeof(string), false };
|
||||||
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name), ParamInfo.ParameterType, false };
|
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name), ParamInfo.ParameterType, false };
|
||||||
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name, string.Empty), ParamInfo.ParameterType, false };
|
yield return new object[] { new GenericResolvedArrayParameter(ArrayInfo.ParameterType.Name, string.Empty), ParamInfo.ParameterType, false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче