test: Refactoring and adding more tests
This commit is contained in:
Родитель
6e9ab70dd3
Коммит
2b99c9686b
|
@ -0,0 +1,62 @@
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity;
|
||||||
|
using Unity.Injection;
|
||||||
|
|
||||||
|
namespace Injection.Extensions
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class RegistrationTests
|
||||||
|
{
|
||||||
|
[DataTestMethod]
|
||||||
|
[DynamicData(nameof(GetInjectArrayVariants), DynamicDataSourceType.Method)]
|
||||||
|
public void InjectArrayTests(object instance)
|
||||||
|
{
|
||||||
|
// Validate
|
||||||
|
Assert.IsInstanceOfType(instance, typeof(ResolvedArrayParameter));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetInjectArrayVariants()
|
||||||
|
{
|
||||||
|
yield return new object[] { Inject.Array(typeof(string)) };
|
||||||
|
yield return new object[] { Inject.Array(typeof(string), string.Empty) };
|
||||||
|
yield return new object[] { Inject.Array<string>(string.Empty) };
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Issue 146
|
||||||
|
//[DataTestMethod]
|
||||||
|
//[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
//[DynamicData(nameof(GetInjectArrayInvalidVariants), DynamicDataSourceType.Method)]
|
||||||
|
//public void InjectArrayValidationTests()
|
||||||
|
//{
|
||||||
|
// _ = Inject.Array(null);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public static IEnumerable<object[]> GetInjectArrayInvalidVariants()
|
||||||
|
//{
|
||||||
|
// // TODO: Issue #146 yield return new object[] { Inject.Array(null) };
|
||||||
|
// yield return new object[] { Inject.Array(typeof(string), string.Empty) };
|
||||||
|
//}
|
||||||
|
|
||||||
|
//[DataTestMethod]
|
||||||
|
//[DynamicData(nameof(GetInjectParameterVariants), DynamicDataSourceType.Method)]
|
||||||
|
//public void InjectParameterTests(object instance)
|
||||||
|
//{
|
||||||
|
// // Validate
|
||||||
|
// Assert.IsInstanceOfType(instance, typeof(ParameterBase));
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public static IEnumerable<object[]> GetInjectParameterVariants()
|
||||||
|
//{
|
||||||
|
// yield return new object[] { Inject.Parameter(new object()) };
|
||||||
|
//}
|
||||||
|
|
||||||
|
//[TestMethod]
|
||||||
|
//public void InjectFieldTests()
|
||||||
|
//{ }
|
||||||
|
|
||||||
|
//[TestMethod]
|
||||||
|
//public void InjectPropertyTests()
|
||||||
|
//{ }
|
||||||
|
}
|
||||||
|
}
|
|
@ -97,7 +97,6 @@ namespace Injection.Members
|
||||||
Assert.AreNotEqual(0, hash);
|
Assert.AreNotEqual(0, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DynamicData(nameof(GetNotInitializedMembers), DynamicDataSourceType.Method)]
|
[DynamicData(nameof(GetNotInitializedMembers), DynamicDataSourceType.Method)]
|
||||||
public virtual void ToStringTest(InjectionMember member, MemberInfo _)
|
public virtual void ToStringTest(InjectionMember member, MemberInfo _)
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace Resolution.Overrides
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
public static object OverrideValue { get; } = new object();
|
public static object OverrideValue { get; } = new object();
|
||||||
public static object ValueOverride { get; } = new TestResolverOverride();
|
public static object ValueOverride { get; } = new TestResolver();
|
||||||
|
public static object FactoryOverride { get; } = new TestResolverFactory();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -130,23 +131,39 @@ namespace Resolution.Overrides
|
||||||
|
|
||||||
public static IEnumerable<object[]> GetOverriddenResolvers()
|
public static IEnumerable<object[]> GetOverriddenResolvers()
|
||||||
{
|
{
|
||||||
|
|
||||||
yield return new object[] { new FieldOverride(string.Empty, ValueOverride) };
|
yield return new object[] { new FieldOverride(string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new FieldOverride(string.Empty, FactoryOverride) };
|
||||||
|
|
||||||
yield return new object[] { new PropertyOverride(string.Empty, ValueOverride) };
|
yield return new object[] { new PropertyOverride(string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new PropertyOverride(string.Empty, FactoryOverride) };
|
||||||
|
|
||||||
yield return new object[] { new DependencyOverride(typeof(object), ValueOverride) };
|
yield return new object[] { new DependencyOverride(typeof(object), ValueOverride) };
|
||||||
yield return new object[] { new DependencyOverride(string.Empty, ValueOverride) };
|
yield return new object[] { new DependencyOverride(string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new DependencyOverride(typeof(object), FactoryOverride) };
|
||||||
|
yield return new object[] { new DependencyOverride(string.Empty, FactoryOverride) };
|
||||||
yield return new object[] { new DependencyOverride(typeof(object), string.Empty, ValueOverride) };
|
yield return new object[] { new DependencyOverride(typeof(object), string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new DependencyOverride(typeof(object), string.Empty, FactoryOverride) };
|
||||||
yield return new object[] { new DependencyOverride(typeof(ResolverOverride), typeof(object), string.Empty, ValueOverride) };
|
yield return new object[] { new DependencyOverride(typeof(ResolverOverride), typeof(object), string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new DependencyOverride(typeof(ResolverOverride), typeof(object), string.Empty, FactoryOverride) };
|
||||||
|
|
||||||
yield return new object[] { new ParameterOverride(string.Empty, ValueOverride) };
|
yield return new object[] { new ParameterOverride(string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new ParameterOverride(string.Empty, FactoryOverride) };
|
||||||
yield return new object[] { new ParameterOverride(typeof(object), ValueOverride) };
|
yield return new object[] { new ParameterOverride(typeof(object), ValueOverride) };
|
||||||
|
yield return new object[] { new ParameterOverride(typeof(object), FactoryOverride) };
|
||||||
yield return new object[] { new ParameterOverride(typeof(object), string.Empty, ValueOverride) };
|
yield return new object[] { new ParameterOverride(typeof(object), string.Empty, ValueOverride) };
|
||||||
|
yield return new object[] { new ParameterOverride(typeof(object), string.Empty, FactoryOverride) };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestResolverOverride : IResolve
|
public class TestResolverFactory : IResolverFactory<Type>
|
||||||
|
{
|
||||||
|
public ResolveDelegate<TContext> GetResolver<TContext>(Type info) where TContext : IResolveContext
|
||||||
|
{
|
||||||
|
return (ref TContext context) => context;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestResolver : IResolve
|
||||||
{
|
{
|
||||||
public object Resolve<TContext>(ref TContext context)
|
public object Resolve<TContext>(ref TContext context)
|
||||||
where TContext : IResolveContext
|
where TContext : IResolveContext
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System.Reflection;
|
||||||
|
using Unity;
|
||||||
|
using Unity.Lifetime;
|
||||||
|
|
||||||
|
namespace Lifetime.Extensions
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class RegistrationTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void FactoryLifetimeTest()
|
||||||
|
{
|
||||||
|
var members = typeof(FactoryLifetime).GetProperties(BindingFlags.Public | BindingFlags.Static);
|
||||||
|
foreach (var property in members)
|
||||||
|
{
|
||||||
|
var manager = property.GetValue(null);
|
||||||
|
|
||||||
|
Assert.IsInstanceOfType(manager, typeof(IFactoryLifetimeManager));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InstanceLifetimeTest()
|
||||||
|
{
|
||||||
|
var members = typeof(InstanceLifetime).GetProperties(BindingFlags.Public | BindingFlags.Static);
|
||||||
|
foreach (var property in members)
|
||||||
|
{
|
||||||
|
var manager = property.GetValue(null);
|
||||||
|
|
||||||
|
Assert.IsInstanceOfType(manager, typeof(IInstanceLifetimeManager));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TypeLifetimeTest()
|
||||||
|
{
|
||||||
|
var members = typeof(TypeLifetime).GetProperties(BindingFlags.Public | BindingFlags.Static);
|
||||||
|
foreach (var property in members)
|
||||||
|
{
|
||||||
|
var manager = property.GetValue(null);
|
||||||
|
|
||||||
|
Assert.IsInstanceOfType(manager, typeof(ITypeLifetimeManager));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче