[Ignore] //This feature is not implemented yet. public void RegisterInstanceScopedTest() //todo: tests with opened generics types { var anyInstance = new MockDisposableClass(); using (var ioc = new Container()) { ioc.As<ITestDisposable>().Use(anyInstance,true,ThreadScope.Instance); //just for current thread Task.Factory.StartNew(() => { var myInstance = ioc.GetService<ITestDisposable>(); Assert.IsNull(myInstance); //should be null, because this is another thread }).Wait(); } }
public void RegisterInstanceNotExternallyOwnedTest() //todo: tests with opened generics types { var anyInstance = new MockDisposableClass(); using (var ioc = new Container()) { ioc.As<ITestDisposable>().Use(anyInstance, externallyOwned: false); ioc.GetService<ITestDisposable>();//creating isntance } Assert.AreEqual(true, anyInstance.Disposed);//instance is not externally owned -> dispose has been called }
public void RegisterInstanceTest() //todo: tests with opened generics types { var anyInstance = new MockDisposableClass(); using (var ioc = new Container()) { ioc.As<ITestDisposable>().Use(anyInstance); var myInstance = ioc.GetService<ITestDisposable>(); //creating isntance Assert.AreSame(anyInstance,myInstance); //should be some instance } }