public void LoadRegistersServicesUsingIServiceLoaderService() { CompositionContainer mockContainer = new TestableRootCompositionContainer(); MockServiceLoaderService serviceLoaderService = new MockServiceLoaderService(); mockContainer.Services.Add<IServiceLoaderService>(serviceLoaderService); ModuleLoaderService loader = new ModuleLoaderService(); DependantModuleInfo moduleInfo = new DependantModuleInfo("TestModule", generatedAssemblies["TestModule"].FullName, "~/TestModule"); moduleInfo.Services = new ServiceInfo[1] {new ServiceInfo(typeof (IMockService), typeof (MockService), ServiceScope.Global)}; loader.Load(mockContainer, moduleInfo); Assert.IsNotNull(serviceLoaderService.UsedServices); Assert.AreEqual(1, serviceLoaderService.UsedServices.Length); Assert.AreEqual(typeof (IMockService), serviceLoaderService.UsedServices[0].RegisterAs); Assert.IsNotNull(serviceLoaderService.UsedCompositionContainer); Assert.AreEqual(mockContainer.Containers["TestModule"], serviceLoaderService.UsedCompositionContainer); }
public void NullCompositionContainerThrows() { ModuleLoaderService loader = new ModuleLoaderService(); loader.Load(null, new MockModuleInfo()); }
public void LoadCreatesNewContainerForModule() { CompositionContainer mockContainer = new TestableRootCompositionContainer(); ModuleLoaderService loader = new ModuleLoaderService(); loader.Load(mockContainer, new ModuleInfo("TestModuleName", generatedAssemblies["TestModule"].FullName, "~/TestModule")); CompositionContainer moduleContainer = mockContainer.Containers["TestModuleName"]; Assert.IsNotNull(moduleContainer); }
public void LoadCallsLoadOnModuleInitializer() { CompositionContainer mockContainer = new TestableRootCompositionContainer(); ModuleLoaderService loader = new ModuleLoaderService(); loader.Load(mockContainer, new ModuleInfo("TestModule", generatedAssemblies["TestModule"].FullName, "~/TestModule")); bool loadCalled = (bool) generatedAssemblies["TestModule"].GetType("TestModule.TestModuleInitializer").GetField("LoadCalled").GetValue(null); Assert.IsTrue(loadCalled); }
public void InitializationExceptionsAreWrapped() { CompositionContainer mockContainer = new TestableRootCompositionContainer(); ModuleLoaderService loader = new ModuleLoaderService(); try { loader.Load(mockContainer, new ModuleInfo("ModuleThrowingException", generatedAssemblies["ModuleThrowingException"].FullName, "~/ModuleThrowingException")); Assert.Fail("ModuleLoadException was not thrown"); } catch (Exception ex) { if (!(ex is ModuleLoadException)) Assert.Fail("Exception is not of type ModuleLoadException"); if (!(((ModuleLoadException) ex).InnerException is NotImplementedException)) Assert.Fail("The actual inner exception was not wrapped correctly"); } }
public void FindModuleInitializerReturnsNullIfnotExists() { CompositionContainer mockContainer = new TestableRootCompositionContainer(); ModuleLoaderService loader = new ModuleLoaderService(); loader.Load(mockContainer, new ModuleInfo("TestModuleName", generatedAssemblies["TestModule"].FullName, "~/TestModule")); IModuleInitializer initializer = loader.FindInitializer("InexistantName"); Assert.IsNull(initializer); }
public void FindModuleInitializerReturnsCorrectInstance() { CompositionContainer mockContainer = new TestableRootCompositionContainer(); ModuleLoaderService loader = new ModuleLoaderService(); loader.Load(mockContainer, new ModuleInfo("TestModuleName", generatedAssemblies["TestModule"].FullName, "~/TestModule")); IModuleInitializer initializer = loader.FindInitializer("TestModuleName"); Assert.IsNotNull(initializer); Assert.AreEqual("TestModule.TestModuleInitializer", initializer.GetType().FullName); }