public void ValidationContext_Exposes_Services_Through_Callbacks_In_Parent_Container() { MyServiceContainer container = new MyServiceContainer(); container.AddService(typeof(MyTestService), new System.ComponentModel.Design.ServiceCreatorCallback((c, t) => { return(new MyTestService()); })); ValidationContext context = new ValidationContext(this, container, null); Assert.IsInstanceOfType(context.GetService(typeof(MyTestService)), typeof(MyTestService)); }
public void ValidationContext_Allows_Services_To_Explicitly_Promote_To_Parent() { MyServiceContainer container = new MyServiceContainer(); ValidationContext context = new ValidationContext(this, container, null); MyTestService service = new MyTestService(); context.ServiceContainer.AddService(service.GetType(), service, true); // Explicit promotion Assert.AreSame(service, container.GetService(service.GetType())); }
public void ValidationContext_Allows_Services_To_Not_Promote_To_Parent_Container() { MyServiceContainer container = new MyServiceContainer(); ValidationContext context = new ValidationContext(this, container, null); MyTestService service = new MyTestService(); context.ServiceContainer.AddService(service.GetType(), service, false); Assert.IsNull(container.GetService(service.GetType())); }
public void ValidationContext_Can_Accept_Container_And_Return_Service_From_GetService() { MyServiceContainer container = new MyServiceContainer(); MyTestService service = new MyTestService(); container.AddService(service.GetType(), service); ValidationContext context = new ValidationContext(this, container, null); Assert.AreSame(service, context.GetService(service.GetType())); }
public void ValidationContext_Can_Remove_Service_From_Parent_Container_Implicitly() { MyServiceContainer container = new MyServiceContainer(); container.AddService(typeof(MyTestService), new MyTestService()); ValidationContext context = new ValidationContext(this, container, null); Assert.IsInstanceOfType(context.GetService(typeof(MyTestService)), typeof(MyTestService)); context.ServiceContainer.RemoveService(typeof(MyTestService)); // Implicit promotion Assert.IsNull(context.GetService(typeof(MyTestService))); }
public void ValidationContext_Remove_Service_Can_Not_Affect_Parent() { MyServiceContainer container = new MyServiceContainer(); container.AddService(typeof(MyTestService), new MyTestService()); ValidationContext context = new ValidationContext(this, container, null); Assert.IsInstanceOfType(context.GetService(typeof(MyTestService)), typeof(MyTestService)); context.ServiceContainer.RemoveService(typeof(MyTestService), false); Assert.IsInstanceOfType(context.GetService(typeof(MyTestService)), typeof(MyTestService)); }
public void ValidationContext_Exposes_Services_Through_Callbacks_In_Parent_Container() { MyServiceContainer container = new MyServiceContainer(); container.AddService(typeof(MyTestService), new System.ComponentModel.Design.ServiceCreatorCallback((c, t) => { return new MyTestService(); })); ValidationContext context = new ValidationContext(this, container, null); Assert.IsInstanceOfType(context.GetService(typeof(MyTestService)), typeof(MyTestService)); }