using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.Unity;
using ResolvingWithPolicyInjection.DemoClasses;
namespace ResolvingWithPolicyInjection.Tests
{
[TestClass]
public class UnityContainerExtensionMethodsTest
{
[TestMethod]
public void should_resolve_ITestInterface_to_policy_enabled_TestConcreteImplementation_explicit()
{
var container = new UnityContainer();
container.RegisterType<ITestInterface, TestConcreteImplementation>();
var resolvedWithPolicyInjection = container.ResolveWithPolicyInjection<ITestInterface>();
Assert.IsNotNull(resolvedWithPolicyInjection);
Assert.AreEqual("TEST", resolvedWithPolicyInjection.ReturnTest());
}
[TestMethod]
public void should_resolve_ITestInterface_to_policy_enabled_TestConcreteImplementation_implicitly()
{
var container = new UnityContainer();
container.RegisterTypeWithPolicyInjection<ITestInterface, TestConcreteImplementation>();
var resolved = container.Resolve<DependentConcreteImplementation>();
Assert.IsNotNull(resolved);
Assert.AreEqual("TEST", resolved.KörBeroende());
}
}
}
namespace ResolvingWithPolicyInjection.DemoClasses
{
public class DependentConcreteImplementation
{
private readonly ITestInterface _beroende;
public DependentConcreteImplementation([Dependency]ITestInterface dependency)
{
_beroende = dependency;
}
public string KörBeroende()
{
return _beroende.ReturnTest();
}
}
public interface ITestInterface
{
string ReturnTest();
}
public class TestConcreteImplementation : ITestInterface
{
public string ReturnTest()
{
return "TEST";
}
}
}