public void TestStart() { IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup(); var app = setup.Start(appModule); Debug.WriteLine("AppStarted"); IComponentContainer componentContainer = app.GetAppContainer <IComponentContainer>(); Assert.IsNotNull(componentContainer); Debug.WriteLine("Creating : {0}", typeof(Class2)); Assert.IsNotNull(componentContainer.CreateComponent <Class2>()); Debug.WriteLine("Created : {0}", typeof(Class2)); Debug.WriteLine("Creating : {0}", typeof(Class2)); Class2 cls2 = componentContainer.CreateComponent <Class2>(); Debug.WriteLine("Created : {0}", typeof(Class2)); Debug.WriteLine("Injecting : {0}", typeof(Class2)); componentContainer.InjectProperties(cls2); Debug.WriteLine("Injected : {0}", typeof(Class2)); int i = app.Context.GetOrCreate <int>("Index", key => 0); Assert.AreEqual(2, i); Assert.IsNotNull(cls2.Class1); }
public void RegisterComponentWhenNoRegited() { IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup(); var app = setup.Start(appModule); var container = app.GetAppContainer <IComponentContainer>(); container.NoComponentRegisted += (sender, e) => { if (e.ServiceType == typeof(ITest)) { e.ComponentProvider = c => new Test(); } }; using (var scope = container.BeginScope("TEST")) { var t = scope.CreateComponent <ITest>(); Assert.IsNotNull(t); Assert.IsInstanceOfType(t, typeof(Test)); try { scope.CreateComponent <ITest2>(); Assert.Fail("!"); } catch (Exception) { } } }
public void Init() { Console.WriteLine("CommandBusTests.Init"); IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup(); var app = setup.Start(appModule); IComponentContainer componentContainer = app.GetAppContainer <IComponentContainer>(); ComponentContainer = componentContainer.BeginScope("TEST"); }
public void Test() { AppSetup appSetup = new AppSetup(); TestAppModule testAppModule = new TestAppModule(); var app = appSetup.Start(testAppModule); var container = app.GetAppContainer <IComponentContainer>(); using (var scope = container.BeginScope("test")) { var t = scope.CreateComponent <IService>(); Assert.IsInstanceOfType(t, typeof(ServiceRegistedInTestContainerBuilder)); } }
public void RemoveService() { IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup(); var app = setup.Start(appModule); IComponentContainer componentContainer = app.GetAppContainer <IComponentContainer>(); using (var scope = componentContainer.BeginScope("TEST")) { ICL1Service service = scope.CreateComponent <ICL1Service>(); Assert.AreEqual("TEST", service.GetName()); } }
public void GetServiceThatRegistedByTestAppModule() { IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup(); var app = setup.Start(appModule); IComponentContainer componentContainer = app.GetAppContainer <IComponentContainer>(); using (var scope = componentContainer.BeginScope("test")) { ServiceRegistedByAppModule service = scope.CreateComponent <ServiceRegistedByAppModule>(); Assert.IsNotNull(service); Assert.IsInstanceOfType(service, typeof(DefaultServiceRegistedByAppModule)); } }
public void TestConfigWithFileNotExists() { IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup("./abc.json"); var app = setup.Start(appModule); IComponentContainer componentContainer = app.GetAppContainer <IComponentContainer>(); using (var scope = componentContainer.BeginScope("test")) { TestConfig config1 = scope.CreateComponent <TestConfig>(); TestConfig config2 = scope.CreateComponent <TestConfig>(); Assert.AreEqual("Mode", config1.Mode); Assert.AreEqual(config1, config2); } }
public void DoNotTriggerNoComponentRegisted() { IAppModule appModule = new TestAppModule(); AppSetup setup = new AppSetup(); var app = setup.Start(appModule); var container = app.GetAppContainer <IComponentContainer>(); container.NoComponentRegisted += (sender, e) => { Assert.Fail(); }; using (var scope = container.BeginScope("TEST")) { var t = scope.CreateComponent <ILifetimeScope>(); } }