public void GeneralTest1 () { ServiceContainer sc = new ServiceContainer (); sc.AddService (typeof (Svc), new Svc()); Svc service1 = sc.GetService (typeof (Svc)) as Svc; AssertNotNull ("GT1#01", service1); AssertEquals ("GT1#02", service1, sc.GetService (typeof (Svc))); AssertNull ("GT1#04", sc.GetService (typeof (NotInSvc))); }
public void TestServiceCreator () { ServiceContainer sc = new ServiceContainer (); sc.AddService(typeof(Svc), new ServiceCreatorCallback(Svc.ServiceCreator)); AssertNull ("TSC#01", sc.GetService (typeof(NotInSvc))); Svc service1 = sc.GetService (typeof(Svc)) as Svc; AssertNotNull ("TSC#02", service1); AssertEquals ("TSC#03", Svc.TotalObjectsCreatedByCallback, 1); Svc service2 = sc.GetService (typeof(Svc)) as Svc; AssertEquals ("TSC#04", service2, service1); AssertEquals ("TSC#05", Svc.TotalObjectsCreatedByCallback, 1); }
private static ITransformationContextProvider CreateTransformationContextProvider() { using (var container = new ServiceContainer()) { TransformationContextProvider.Register(container); return (ITransformationContextProvider)container.GetService(typeof(ITransformationContextProvider)); } }
public void AddService1 () { object service; ServiceContainer parent; ServiceContainer sc; object serviceInstance1 = new ArrayList (); object serviceInstance2 = new Hashtable (); object callback1 = new ServiceCreatorCallback ( Svc.ServiceCreator); sc = new ServiceContainer (); sc.AddService (typeof (ICollection), serviceInstance1); sc.AddService (typeof (IEnumerable), serviceInstance2); sc.AddService (typeof (Svc), callback1); service = sc.GetService (typeof (ICollection)); Assert.IsNotNull (service, "#A1"); Assert.AreSame (serviceInstance1, service, "#A2"); service = sc.GetService (typeof (IEnumerable)); Assert.IsNotNull (service, "#B1"); Assert.AreSame (serviceInstance2, service, "#B2"); service = sc.GetService (typeof (ArrayList)); Assert.IsNull (service, "#C1"); service = sc.GetService (typeof (ICloneable)); Assert.IsNull (service, "#D1"); Assert.AreEqual (0, Svc.TotalObjectsCreatedByCallback, "#E1"); service = sc.GetService (typeof (Svc)); Assert.IsNotNull (service, "#E2"); Assert.IsTrue (service is Svc, "#E3"); Assert.AreEqual (1, Svc.TotalObjectsCreatedByCallback, "#E4"); Assert.AreSame (service, sc.GetService (typeof (Svc)), "#E5"); Assert.AreEqual (1, Svc.TotalObjectsCreatedByCallback, "#E6"); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (typeof (ICollection), serviceInstance1); Assert.AreSame (serviceInstance1, sc.GetService (typeof (ICollection)), "#F1"); Assert.IsNull (parent.GetService (typeof (ICollection)), "#F2"); }
public void TestServiceCreator () { ServiceContainer sc = new ServiceContainer (); sc.AddService (typeof(Svc), new ServiceCreatorCallback (Svc.ServiceCreator)); Assert.IsNull (sc.GetService (typeof (NotInSvc)), "#A"); Svc service1 = sc.GetService (typeof (Svc)) as Svc; Assert.IsNotNull (service1, "#B1"); Assert.AreEqual (1, Svc.TotalObjectsCreatedByCallback, "#B2"); Svc service2 = sc.GetService (typeof (Svc)) as Svc; Assert.AreEqual (service1, service2, "#C1"); Assert.AreEqual (1, Svc.TotalObjectsCreatedByCallback, "#C2"); }
public void GetService_DefaultServices () { ServiceContainer sc1 = new ServiceContainer (); Assert.AreSame (sc1, sc1.GetService (typeof (IServiceContainer)), "#A1"); Assert.AreSame (sc1, sc1.GetService (typeof(ServiceContainer)), "#A2"); ServiceContainer sc2 = new ServiceContainer (); sc1.AddService (typeof (IServiceContainer), sc2); sc1.AddService (typeof (ServiceContainer), sc2); Assert.AreSame (sc1, sc1.GetService (typeof (IServiceContainer)), "#B1"); Assert.AreSame (sc1, sc1.GetService (typeof(ServiceContainer)), "#B2"); }
public void GeneralTest2 () { ServiceContainer sc = new ServiceContainer (); sc.AddService (typeof (Svc), new Svc ()); Svc service1 = sc.GetService (typeof (Svc)) as Svc; Assert.IsNotNull (service1, "#A"); Assert.AreEqual (service1, sc.GetService (typeof (Svc)), "#2"); try { sc.AddService (typeof (Svc), new Svc ()); Assert.Fail ("#B1"); } catch (ArgumentException ex) { // The service MonoTests.System.ComponentModel.Design.Svc // already exists in the service container Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2"); Assert.IsNull (ex.InnerException, "#B3"); Assert.IsNotNull (ex.Message, "#B4"); Assert.IsTrue (ex.Message.IndexOf (typeof (Svc).FullName) != -1, "#B5"); Assert.AreEqual ("serviceType", ex.ParamName, "#B6"); } }
public void GeneralTest1 () { ServiceContainer sc = new ServiceContainer (); sc.AddService (typeof (Svc), new Svc ()); Svc service1 = sc.GetService (typeof (Svc)) as Svc; Assert.IsNotNull (service1, "#1"); Assert.AreEqual (service1, sc.GetService (typeof (Svc)), "#2"); Assert.IsNull (sc.GetService (typeof (NotInSvc)), "#3"); }
[Test] // AddService (Type, Object, Boolean) public void AddService3 () { ServiceContainer sc; ServiceContainer parent = new ServiceContainer (); ArrayList serviceInstance1 = new ArrayList (); ArrayList serviceInstance2 = new ArrayList (); Type serviceType1 = typeof (IList); Type serviceType2 = typeof (IEnumerable); sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType2, serviceInstance2, false); Assert.AreSame (serviceInstance1, parent.GetService (serviceType1), "#A1"); Assert.IsNull (parent.GetService (serviceType2), "#A2"); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#A3"); Assert.AreSame (serviceInstance2, sc.GetService (serviceType2), "#A4"); sc = new ServiceContainer (); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType2, serviceInstance2, false); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#B1"); Assert.AreSame (serviceInstance2, sc.GetService (serviceType2), "#B2"); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType1, serviceInstance2, false); Assert.AreSame (serviceInstance2, sc.GetService (serviceType1), "#C1"); Assert.AreSame (serviceInstance1, parent.GetService (serviceType1), "#C2"); }
public void BasicTest() { Class1 class1 = new Class1(); Class2 class2 = new Class2(); ServiceContainer container = new ServiceContainer(); container.AddService(typeof(IInterface1), class1); container.AddService(typeof(IInterface2), class2); Assert.AreSame(class1, container.GetService(typeof(IInterface1))); Assert.AreSame(class2, container.GetService(typeof(IInterface2))); Assert.IsNull(container.GetService(typeof(IInterface3))); }
public void MockObjectsMayBePlacedIntoServiceContainers() { var container = new ServiceContainer(); var mockedType = Mockery.NewInstanceOfRole(typeof (IMockedType)) as IMockedType; container.AddService(typeof (IMockedType), mockedType); Assert.AreSame(mockedType, container.GetService(typeof (IMockedType))); }
public void ParentService () { ServiceContainer scParent = new ServiceContainer (); ServiceContainer sc = new ServiceContainer (scParent); scParent.AddService(typeof(Svc), new Svc ()); Svc service1 = sc.GetService (typeof (Svc)) as Svc; Assert.IsNotNull (service1, "#1"); }
public void NestedContainers() { Class1 class1 = new Class1(); Class2 class2 = new Class2(); Class3 class3 = new Class3(); Class1 class1a = new Class1(); ServiceContainer parentContainer = new ServiceContainer(); parentContainer.AddService(typeof(IInterface1), class1); ServiceContainer childContainer = new ServiceContainer(parentContainer); childContainer.AddService(typeof(IInterface2), class2); // child container returns what it contains and what its parent contains Assert.AreSame(class1, childContainer.GetService(typeof(IInterface1))); Assert.AreSame(class2, childContainer.GetService(typeof(IInterface2))); Assert.IsNull(childContainer.GetService(typeof(IInterface3))); // parent container only returns what it contains Assert.IsNull(parentContainer.GetService(typeof(IInterface2))); // add a service to the parent, and it becomes available to the child parentContainer.AddService(typeof(IInterface3), class3); Assert.AreSame(class3, childContainer.GetService(typeof(IInterface3))); Assert.AreSame(class3, parentContainer.GetService(typeof(IInterface3))); // remove a service from the parent, and it is no longer available to the child parentContainer.RemoveService(typeof(IInterface3)); Assert.IsNull(childContainer.GetService(typeof(IInterface3))); Assert.IsNull(parentContainer.GetService(typeof(IInterface3))); // remove a service from the child container but not the parent container childContainer.RemoveService(typeof(IInterface1)); Assert.AreSame(class1, childContainer.GetService(typeof(IInterface1))); Assert.AreSame(class1, parentContainer.GetService(typeof(IInterface1))); // add an implementation to the child container and it overrides the parent container childContainer.AddService(typeof(IInterface1), class1a); Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1))); Assert.AreSame(class1, parentContainer.GetService(typeof(IInterface1))); // remove implementation from the child container, and the implementation in the parent // container is used again in the child container childContainer.RemoveService(typeof(IInterface1)); Assert.AreSame(class1, childContainer.GetService(typeof(IInterface1))); Assert.AreSame(class1, parentContainer.GetService(typeof(IInterface1))); // remove implementation in the child container using promotion childContainer.RemoveService(typeof(IInterface1), true); Assert.IsNull(childContainer.GetService(typeof(IInterface1))); Assert.IsNull(parentContainer.GetService(typeof(IInterface1))); // add implementation to both parent and child container, and then remove from child using // promotion, the implementation left in the child will remain parentContainer.AddService(typeof(IInterface1), class1); childContainer.AddService(typeof(IInterface1), class1a); childContainer.RemoveService(typeof(IInterface1), true); Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1))); Assert.IsNull(parentContainer.GetService(typeof(IInterface1))); // remove using promotion again and the implementation remains in the child childContainer.RemoveService(typeof(IInterface1), true); Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1))); Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1))); Assert.IsNull(parentContainer.GetService(typeof(IInterface1))); // remove without promotion and the instance is gone in the child childContainer.RemoveService(typeof(IInterface1), false); Assert.IsNull(childContainer.GetService(typeof(IInterface1))); Assert.IsNull(parentContainer.GetService(typeof(IInterface1))); }
public void GetService_DefaultServices () { ServiceContainer sc1 = new ServiceContainer (); Assert.AreSame (sc1, sc1.GetService (typeof (IServiceContainer)), "#A1"); #if NET_2_0 Assert.AreSame (sc1, sc1.GetService (typeof(ServiceContainer)), "#A2"); #else Assert.IsNull (sc1.GetService (typeof (ServiceContainer)), "#A2"); #endif ServiceContainer sc2 = new ServiceContainer (); sc1.AddService (typeof (IServiceContainer), sc2); sc1.AddService (typeof (ServiceContainer), sc2); Assert.AreSame (sc1, sc1.GetService (typeof (IServiceContainer)), "#B1"); #if NET_2_0 Assert.AreSame (sc1, sc1.GetService (typeof(ServiceContainer)), "#B2"); #else Assert.AreSame (sc2, sc1.GetService (typeof (ServiceContainer)), "#B2"); #endif }
private void Initialize() { IDesignerHost host; Form form; IRootDesigner rootDesigner; Control view; // Initialise service container and designer host serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(INameCreationService), new NameCreationService()); serviceContainer.AddService(typeof(IUIService), new UIService(this)); host = new DesignerHost(serviceContainer); // Add toolbox service serviceContainer.AddService(typeof(IToolboxService), lstToolbox); lstToolbox.designPanel = pnlViewHost; PopulateToolbox(lstToolbox); // Add menu command service menuService = new MenuCommandService(); serviceContainer.AddService(typeof(IMenuCommandService), menuService); // Start the designer host off with a Form to design form = (Form)host.CreateComponent(typeof(Form)); form.TopLevel = false; form.Text = "Form1"; // Get the root designer for the form and add its design view to this form rootDesigner = (IRootDesigner)host.GetDesigner(form); view = (Control)rootDesigner.GetView(ViewTechnology.WindowsForms); view.Dock = DockStyle.Fill; pnlViewHost.Controls.Add(view); // Subscribe to the selectionchanged event and activate the designer ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService)); s.SelectionChanged += new EventHandler(OnSelectionChanged); host.Activate(); }
public void ServiceProviderConstructor() { ServiceContainer container = new ServiceContainer(); ServiceContainerUtil.AddService(container, typeof(IInterface3), typeof(Class3b)); ServiceContainerUtil.AddService(container, typeof(IInterface1), typeof(Class1)); Assert.IsNotNull(container.GetService(typeof(IInterface3))); }
public void CustomAddService() { ServiceContainer container = new ServiceContainer(); ServiceContainerUtil.AddService(container, typeof(IInterface1), typeof(Class1)); ServiceContainerUtil.AddService(container, typeof(IInterface2), typeof(Class2)); IInterface1 i1 = (IInterface1)container.GetService(typeof(IInterface1)); Assert.IsNotNull(i1); IInterface2 i2 = (IInterface2)container.GetService(typeof(IInterface2)); Assert.IsNotNull(i2); IInterface3 i3 = (IInterface3)container.GetService(typeof(IInterface3)); Assert.IsNull(i3); IInterface1 i1a = (IInterface1)container.GetService(typeof(IInterface1)); Assert.AreSame(i1, i1a); IInterface2 i2a = (IInterface2)container.GetService(typeof(IInterface2)); Assert.AreSame(i2, i2a); }
[Test] // RemoveService (Type) public void RemoveService1 () { ServiceContainer sc; ServiceContainer parent; ArrayList serviceInstance1 = new ArrayList (); ArrayList serviceInstance2 = new ArrayList (); Type serviceType1 = typeof (IList); Type serviceType2 = typeof (IEnumerable); parent = null; sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1); sc.AddService (serviceType2, serviceInstance2); sc.RemoveService (typeof (DateTime)); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#A1"); Assert.AreSame (serviceInstance2, sc.GetService (serviceType2), "#A2"); sc.RemoveService (serviceType2); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#B1"); Assert.IsNull (sc.GetService (serviceType2), "#B2"); sc.RemoveService (serviceType1); Assert.IsNull (sc.GetService (serviceType1), "#C1"); Assert.IsNull (sc.GetService (serviceType2), "#C2"); sc.AddService (serviceType1, serviceInstance1); sc.AddService (serviceType2, serviceInstance2); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#D1"); Assert.AreSame (serviceInstance2, sc.GetService (serviceType2), "#D2"); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType2, serviceInstance2, false); sc.RemoveService (serviceType1); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#E1"); Assert.AreSame (serviceInstance2, sc.GetService (serviceType2), "#E2"); sc.RemoveService (serviceType2); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#F1"); Assert.IsNull (sc.GetService (serviceType2), "#F2"); parent.RemoveService (serviceType1); Assert.IsNull (sc.GetService (serviceType1), "#G1"); Assert.IsNull (sc.GetService (serviceType2), "#G2"); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType1, serviceInstance2, false); sc.RemoveService (serviceType1); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#H1"); Assert.AreSame (serviceInstance1, parent.GetService (serviceType1), "#H2"); sc.RemoveService (serviceType1); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#I1"); Assert.AreSame (serviceInstance1, parent.GetService (serviceType1), "#I2"); parent.RemoveService (serviceType1); Assert.IsNull (sc.GetService (serviceType1), "#J1"); Assert.IsNull (parent.GetService (serviceType1), "#J2"); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType1, serviceInstance2, false); parent.RemoveService (serviceType1); Assert.AreSame (serviceInstance2, sc.GetService (serviceType1), "#K1"); Assert.IsNull (parent.GetService (serviceType1), "#K2"); }
public void TestParentService () { ServiceContainer scParent = new ServiceContainer(); ServiceContainer sc = new ServiceContainer(scParent); scParent.AddService(typeof(Svc), new Svc()); Svc service1 = sc.GetService (typeof(Svc)) as Svc; AssertNotNull ("TPS#01", service1); }
[Test] // RemoveService (Type, Boolean) public void RemoveService2_Disposed () { ServiceContainer sc; ServiceContainer parent; ArrayList serviceInstance1 = new ArrayList (); ArrayList serviceInstance2 = new ArrayList (); Type serviceType1 = typeof (IList); Type serviceType2 = typeof (IEnumerable); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (serviceType1, serviceInstance1, true); sc.AddService (serviceType2, serviceInstance2, false); sc.Dispose (); sc.RemoveService (serviceType1, false); sc.RemoveService (serviceType2, false); Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#A1"); Assert.IsNull (sc.GetService (serviceType2), "#A2"); sc.RemoveService (serviceType1, true); sc.RemoveService (serviceType2, true); Assert.IsNull (sc.GetService (serviceType1), "#B1"); Assert.IsNull (sc.GetService (serviceType2), "#B2"); }
public void AddService1_Disposed () { object service; ServiceContainer sc; object serviceInstance1 = new ArrayList (); object serviceInstance2 = new Hashtable (); sc = new ServiceContainer (); sc.AddService (typeof (ICollection), serviceInstance1); service = sc.GetService (typeof (ICollection)); Assert.IsNotNull (service, "#A1"); Assert.AreSame (serviceInstance1, service, "#A2"); sc.Dispose (); service = sc.GetService (typeof (ICollection)); Assert.IsNull (service, "#B"); sc.AddService (typeof (ICollection), serviceInstance2); service = sc.GetService (typeof (ICollection)); Assert.IsNotNull (service, "#C1"); Assert.AreSame (serviceInstance2, service, "#C2"); }
public Toolbox(ServiceContainer parentServices) { this.parentServices = parentServices; //we need this service, so create it if not present toolboxService = parentServices.GetService (typeof (IToolboxService)) as ToolboxService; if (toolboxService == null) { toolboxService = new ToolboxService (); parentServices.AddService (typeof (IToolboxService), toolboxService); } #region Toolbar toolbar = new Toolbar (); toolbar.ToolbarStyle = ToolbarStyle.Icons; toolbar.IconSize = IconSize.SmallToolbar; base.PackStart (toolbar, false, false, 0); filterToggleButton = new ToggleToolButton (); filterToggleButton.IconWidget = new Image (Stock.MissingImage, IconSize.SmallToolbar); filterToggleButton.Toggled += new EventHandler (toggleFiltering); toolbar.Insert (filterToggleButton, 0); catToggleButton = new ToggleToolButton (); catToggleButton.IconWidget = new Image (Stock.MissingImage, IconSize.SmallToolbar); catToggleButton.Toggled += new EventHandler (toggleCategorisation); toolbar.Insert (catToggleButton, 1); SeparatorToolItem sep = new SeparatorToolItem(); toolbar.Insert (sep, 2); filterEntry = new Entry(); filterEntry.WidthRequest = 150; filterEntry.Changed += new EventHandler (filterTextChanged); #endregion scrolledWindow = new ScrolledWindow (); base.PackEnd (scrolledWindow, true, true, 0); //Initialise model store = new ToolboxStore (); //initialise view nodeView = new NodeView (store); nodeView.Selection.Mode = SelectionMode.Single; nodeView.HeadersVisible = false; //cell renderers CellRendererPixbuf pixbufRenderer = new CellRendererPixbuf (); CellRendererText textRenderer = new CellRendererText (); textRenderer.Ellipsize = Pango.EllipsizeMode.End; //Main column with text, icons TreeViewColumn col = new TreeViewColumn (); col.PackStart (pixbufRenderer, false); col.SetAttributes (pixbufRenderer, "pixbuf", ToolboxStore.Columns.Icon, "visible", ToolboxStore.Columns.IconVisible, "cell-background-gdk", ToolboxStore.Columns.BackgroundColour); col.PackEnd (textRenderer, true); col.SetAttributes (textRenderer, "text", ToolboxStore.Columns.Label, "weight", ToolboxStore.Columns.FontWeight, "cell-background-gdk", ToolboxStore.Columns.BackgroundColour); nodeView.AppendColumn (col); //Initialise self scrolledWindow.VscrollbarPolicy = PolicyType.Automatic; scrolledWindow.HscrollbarPolicy = PolicyType.Never; scrolledWindow.WidthRequest = 150; scrolledWindow.AddWithViewport (nodeView); //selection events nodeView.NodeSelection.Changed += OnSelectionChanged; nodeView.RowActivated += OnRowActivated; //update view when toolbox service updated toolboxService.ToolboxChanged += new EventHandler (tbsChanged); Refresh (); //track expanded state of nodes nodeView.RowCollapsed += new RowCollapsedHandler (whenRowCollapsed); nodeView.RowExpanded += new RowExpandedHandler (whenRowExpanded); //set initial state filterToggleButton.Active = false; catToggleButton.Active = true; }
[Test] // AddService (Type, ServiceCreatorCallback) public void AddService2_Disposed () { object service; ServiceContainer sc; object callback = new ServiceCreatorCallback ( Svc.ServiceCreator); sc = new ServiceContainer (); sc.AddService (typeof (Svc), callback); service = sc.GetService (typeof (Svc)); Assert.IsNotNull (service, "#A"); sc.Dispose (); service = sc.GetService (typeof (Svc)); Assert.IsNull (service, "#B"); sc.AddService (typeof (Svc), callback); service = sc.GetService (typeof (Svc)); Assert.IsNotNull (service, "#C"); }