public void MyGenericServiceProviderString() { var myProvider = new MyGenericServiceProvider <string>(); var myList = myProvider.GetService <IMyGenericListService <string> >(); myList.Append("a"); myList.Append("b"); myList.Append("cde"); Assert.AreEqual("a;b;cde;", myList.ToString()); }
public void MyGenericServiceProviderInt() { var myProvider = new MyGenericServiceProvider <int>(); var myList = myProvider.GetService <IMyGenericListService <int> >(); myList.Append(1); myList.Append(2); myList.Append(3); Assert.AreEqual("1;2;3;", myList.ToString()); }
public void MyServiceContainerGetFirstServiceGeneric() { ServiceContainer parentServiceContainer = new ServiceContainer(); ServiceContainer serviceContainer = new ServiceContainer(parentServiceContainer); ServiceContainer serviceSubContainer = new ServiceContainer(); parentServiceContainer.AddService(new MyGenericServiceProvider <int>()); parentServiceContainer.AddService(new MyGenericServiceProvider <int>()); parentServiceContainer.AddService(new MyGenericServiceProvider <double>()); parentServiceContainer.AddService(new MyAddService()); serviceContainer.AddService(new MyReverseGenericServiceProvider <int>()); serviceContainer.AddService(new MyGenericServiceProvider <int>()); serviceContainer.AddService(new MyGenericServiceProvider <string>()); serviceContainer.AddService(serviceSubContainer); serviceSubContainer.AddService(new MyReverseGenericServiceProvider <int>()); serviceSubContainer.AddService(new MyReverseGenericServiceProvider <long>()); serviceSubContainer.AddService(new MyGenericService2Provider <string, int>()); serviceSubContainer.AddService(new MyGenericService2Provider <string, float>()); IMyGenericListService <int> service1 = serviceContainer.GetService <IMyGenericListService <int> >(); Assert.IsNotNull(service1); IMyGenericListService <double> service2 = serviceContainer.GetService <IMyGenericListService <double> >(); Assert.IsNotNull(service2); IMyAddService service3 = serviceContainer.GetService <IMyAddService>(); Assert.IsNotNull(service3); MyGenericServiceProvider <string> service4 = serviceContainer.GetService <MyGenericServiceProvider <string> >(); Assert.IsNotNull(service4); MyReverseGenericServiceProvider <long> service5 = serviceContainer.GetService <MyReverseGenericServiceProvider <long> >(); Assert.IsNotNull(service5); MyGenericService2Provider <string, int> service6 = serviceContainer.GetService <MyGenericService2Provider <string, int> >(); Assert.IsNotNull(service6); IMyGenericListService <float> service7 = serviceContainer.GetService <IMyGenericListService <float> >(); Assert.IsNull(service7); MyGenericService2Provider <string, string> service8 = serviceContainer.GetService <MyGenericService2Provider <string, string> >(); Assert.IsNull(service8); IMySubService service9 = serviceContainer.GetService <IMySubService>(); Assert.IsNull(service9); }