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 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 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"); }
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 SetUp() { Svc.Reset(); }
public void AddService1_ServiceType_Exists () { ServiceContainer sc = new ServiceContainer (); Svc serviceInstance1 = new Svc (); Svc serviceInstance2 = new Svc (); sc.AddService (typeof (Svc), serviceInstance1); Assert.AreSame (serviceInstance1, sc.GetService (typeof (Svc)), "#A"); try { sc.AddService (typeof (Svc), serviceInstance1); 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"); } try { sc.AddService (typeof (Svc), serviceInstance2); Assert.Fail ("#C1"); } catch (ArgumentException ex) { // The service MonoTests.System.ComponentModel.Design.Svc // already exists in the service container Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2"); Assert.IsNull (ex.InnerException, "#C3"); Assert.IsNotNull (ex.Message, "#C4"); Assert.IsTrue (ex.Message.IndexOf (typeof (Svc).FullName) != -1, "#C5"); Assert.AreEqual ("serviceType", ex.ParamName, "#C6"); } }