I'm having a difficult time registering my types for Unity 2 in my unit tests.
Here's a snippet of the class under test:
public class SomeService : ISomeService
{
private int SomeVar { get; set; }
[Dependency]
public ISessionManager SessionManager { get; set; }
public SomeService()
{
SomeVar = SessionManager.Get<int>("SomeVar");
}
}
Here's what I have in my MSTest ClassInitialize method:
private static ISomeService _someService;
private static IUnityContainer _unityContainer;
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
var mockSessionManager = new Mock<ISessionManager>();
mockSessionManager.Setup(foo => foo.Get<int>(It.IsAny<string>())).Returns(1);
_unityContainer = new UnityContainer()
.RegisterInstance(mockSessionManager.Object)
.RegisterType<ISomeService, SomeService>(
new InjectionProperty("SessionManager"));
_someService = _unityContainer.Resolve<IAdditionalCoveragesService>();
}
For every test method that I have, when I debug and step into the constructor of SomeService, it says that SessionManager is null. What am I doing in wrong in trying to register my types in Unity?
Note - I am using Moq to set up a mock session manager that should be injected into SomeService.
Thanks!!!