Example #1
0
        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");
                }
            }
        }
Example #2
0
        public void ChildContainerHasParent()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            Assert.AreSame(parent, child.Parent);
        }
Example #3
0
        public void ConfigureModulesUsesModuleEnumeratorAndModuleLoaderService()
        {
            TestableWebClientApplication     app       = new TestableWebClientApplication();
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            app.SetTestRootCompositionContainer(container);
            MockModuleEnumerator moduleEnumerator = new MockModuleEnumerator();

            ModuleInfo moduleInfo = new ModuleInfo("TestModuleName", string.Empty, string.Empty);

            moduleEnumerator.ModulesData.Add(moduleInfo);
            container.Services.Add(typeof(IModuleEnumerator), moduleEnumerator);

            MockModuleLoaderService moduleLoader = new MockModuleLoaderService();

            container.Services.Add(typeof(IModuleLoaderService), moduleLoader);

            MockModuleConfigurationLocatorService configurationLocator = new MockModuleConfigurationLocatorService();

            container.Services.Add(typeof(IModuleConfigurationLocatorService), configurationLocator);

            app.TestConfigureModules();

            Assert.AreEqual("TestModuleName", configurationLocator.ModuleName);
            Assert.AreEqual("TestModuleName", moduleLoader.ModuleName);
        }
Example #4
0
        public void AspxPagesAreNotAddedToLifetimeContainer()
        {
            TestableWebClientApplication application = new TestableWebClientApplication();
            MockHttpContext mockContext = new MockHttpContext();
            MockPage        mockPage    = new MockPage();

            mockContext.Request             = new HttpRequest("page.aspx", "http://application/page.aspx", null);
            mockContext.Handler             = mockPage;
            mockContext.ApplicationInstance = application;
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            application.ModuleContainer = container;
            application.SetTestCurrentContext(mockContext);

            application.TestRun();

            int lifetimeObjects = container.Locator.Count;

            //application.TestPreRequestHandlerExecute(mockContext);
            mockPage.CallOnInit();

            Assert.IsNotNull(mockPage.Presenter);
            Assert.IsNull(container.Locator.Get <MockPresenter>());
            Assert.IsNull(container.Locator.Get <MockPage>());

            //application.TestPostRequestHandlerExecute(mockContext);

            Assert.AreEqual(lifetimeObjects, container.Locator.Count);
        }
Example #5
0
        public void RequestingTypeMappingForUnmappedTypeReturnsRequestedType()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            Type mappedType = root.GetMappedType <Foo>();

            Assert.AreEqual(typeof(Foo), mappedType);
        }
Example #6
0
        public void ChildContainerCanAccessToRootContainer()
        {
            TestableRootCompositionContainer root       = new TestableRootCompositionContainer();
            CompositionContainer             child      = root.Containers.AddNew <CompositionContainer>();
            CompositionContainer             innerChild = child.Containers.AddNew <CompositionContainer>();

            Assert.AreEqual(root, innerChild.RootContainer);
        }
Example #7
0
        public void TerminatingCompositionContainerCausesItToBeRemovedFromParent()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            Assert.AreEqual(1, parent.Containers.Count);
            child.Dispose();
            Assert.AreEqual(0, parent.Containers.Count);
        }
Example #8
0
        public void RequestingTypeMappingOnChildReadsFromParent()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            parent.RegisterTypeMapping <IFoo, Foo>();

            Assert.AreEqual(typeof(Foo), child.GetMappedType <IFoo>());
        }
Example #9
0
        public void TestServicesAreTornDownWhenContainerIsDisposed()
        {
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            MockService svc = container.Services.AddNew <MockService>();

            container.Dispose();

            Assert.IsTrue(svc.OnTearingDownCalled);
        }
Example #10
0
        public void CanRegisterTypeMappingOnRootContainer()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping <IFoo, Foo>();

            Type mappedType = root.GetMappedType <IFoo>();

            Assert.AreEqual(typeof(Foo), mappedType);
        }
Example #11
0
        public void CanRegisterMultipleTypeMappings()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping <IFoo, Foo>();
            root.RegisterTypeMapping <IBar, Bar>();

            Assert.AreEqual(typeof(Bar), root.GetMappedType <IBar>());
            Assert.AreEqual(typeof(Foo), root.GetMappedType <IFoo>());
        }
Example #12
0
        public void CanRegisterTypeMappingViaTypeObjects()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping(typeof(IFoo), typeof(Foo));

            Type mappedType = root.GetMappedType(typeof(IFoo));

            Assert.AreEqual(typeof(Foo), mappedType);
        }
Example #13
0
        public void ChildContainersCanOverrideParentTypeMapping()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            parent.RegisterTypeMapping <IFoo, Foo>();
            child.RegisterTypeMapping <IFoo, Foo2>();

            Assert.AreEqual(typeof(Foo), parent.GetMappedType <IFoo>());
            Assert.AreEqual(typeof(Foo2), child.GetMappedType <IFoo>());
        }
Example #14
0
        public void AddRequiredServicesAddsVirtualPathUtilityService()
        {
            TestableWebClientApplication     app       = new TestableWebClientApplication();
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            app.SetTestRootCompositionContainer(container);

            app.TestAddRequiredServices();

            container.Services.Contains <VirtualPathUtilityService>();
        }
Example #15
0
        public void AddRequiredServicesAddsAuthorizationRulesService()
        {
            TestableWebClientApplication     app       = new TestableWebClientApplication();
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            app.SetTestRootCompositionContainer(container);

            app.TestAddRequiredServices();

            container.Services.Contains <AuthorizationRulesService>();
        }
Example #16
0
        public void DisposingContainerCausesContainedObjectsToBeTornDown()
        {
            TestableRootCompositionContainer cc       = new TestableRootCompositionContainer();
            MockTearDownStrategy             strategy = new MockTearDownStrategy();

            cc.Builder.Strategies.Add(strategy, WCSFBuilderStage.PreCreation);

            cc.Dispose();

            Assert.IsTrue(strategy.TearDownCalled);
        }
Example #17
0
        public void AddRequiredServicesAddsWebConfigModuleInfoStore()
        {
            TestableWebClientApplication     app       = new TestableWebClientApplication();
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            app.SetTestRootCompositionContainer(container);

            app.TestAddRequiredServices();

            container.Services.Contains <WebConfigModuleInfoStore>();
        }
Example #18
0
        public void ChildContainerAreDisposedWithParent()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            MockService svc = child.Services.AddNew <MockService>();

            parent.Dispose();

            Assert.IsTrue(svc.OnTearingDownCalled);
        }
Example #19
0
        public void AddRequiredServicesAddsModuleContainerLocatorService()
        {
            TestableWebClientApplication     app       = new TestableWebClientApplication();
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            app.SetTestRootCompositionContainer(container);

            app.TestAddRequiredServices();

            container.Services.Contains <ModuleContainerLocatorService>();
        }
        public void RegisteredModuleServiceInstanceGetsAddedToModuleServicesCollection()
        {
            CompositionContainer rootContainer  = new TestableRootCompositionContainer();
            CompositionContainer childContainer = rootContainer.Containers.AddNew <CompositionContainer>();
            ServiceInfo          info           = new ServiceInfo(typeof(IMockService), typeof(MockService), ServiceScope.Module);
            ServiceLoaderService serviceLoader  = new ServiceLoaderService();

            serviceLoader.Load(childContainer, info);

            Assert.IsTrue(childContainer.Services.Contains(typeof(IMockService)));
            Assert.AreEqual(typeof(MockService), childContainer.Services.Get <IMockService>(true).GetType());
        }
Example #21
0
        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);
        }
Example #22
0
        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);
        }
Example #23
0
        public void GetContainerReturnsRootContainerIfNoModules()
        {
            TestableRootCompositionContainer rootContainer = new TestableRootCompositionContainer();

            rootContainer.Services.AddNew <MockEnumeratorService, IModuleEnumerator>();
            ModuleContainerLocatorService service = rootContainer.Services.AddNew <ModuleContainerLocatorService>();

            CompositionContainer result  = service.GetContainer("~/SubFolder/Page.aspx");
            CompositionContainer result2 = service.GetContainer("~/Page.aspx");

            Assert.AreSame(rootContainer, result);
            Assert.AreSame(result, result2);
        }
Example #24
0
        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);
        }
        public void LoadRegistersTypeMappingForController()
        {
            TestableRootCompositionContainer parentContainer   = new TestableRootCompositionContainer();
            TestableRootCompositionContainer container         = parentContainer.Containers.AddNew <TestableRootCompositionContainer>("TEST");
            TestableModuleInitializer        moduleInitializer = new TestableModuleInitializer();

            container.Services.Add <IHttpContextLocatorService>(new MockHttpContextLocatorService());
            container.Services.Add <ISiteMapBuilderService>(new MockSiteMapBuilderService());

            moduleInitializer.Load(container);

            Assert.AreEqual(typeof(OrdersController), container.GetMappedType(typeof(IOrdersController)));
        }
Example #26
0
        public void BuildUpDefaultPropertyChooserSetPublicPropertiesOnGenericBaseClass()
        {
            MockBuilderContext ctx = BuildContext();
            TestableRootCompositionContainer compositionContainer = new TestableRootCompositionContainer();

            ctx.Locator.Add(new DependencyResolutionLocatorKey(typeof(CompositionContainer), null), compositionContainer);

            GenericChildMockObject mockInstance;

            mockInstance = (GenericChildMockObject)ctx.HeadOfChain.BuildUp(ctx, typeof(GenericChildMockObject), null, null);

            Assert.IsNotNull(mockInstance.CreateNewProperty);
        }
		public void CreateInstancenotInjectNonRequiredNotPresentServiceDependency()
		{
			PolicyList policies = new PolicyList();
			MockBuilderContext ctx = BuildContext(policies);
			TestableRootCompositionContainer compositionContainer = new TestableRootCompositionContainer();
			ctx.Locator.Add(new DependencyResolutionLocatorKey(typeof (CompositionContainer), null), compositionContainer);

			MockDependencyDependingObjectNotRequired mockInstance =
				(MockDependencyDependingObjectNotRequired)
				ctx.HeadOfChain.BuildUp(ctx, typeof (MockDependencyDependingObjectNotRequired), null, null);

			Assert.IsNotNull(mockInstance);
			Assert.IsNull(mockInstance.DependentObject);
		}
Example #28
0
        public void GetContainerReturnsRootContainerIfNoModulesFoundWithGivenVirtualPath()
        {
            TestableRootCompositionContainer rootContainer = new TestableRootCompositionContainer();

            rootContainer.Containers.AddNew <CompositionContainer>("Module1");
            MockEnumeratorService enumerator = rootContainer.Services.AddNew <MockEnumeratorService, IModuleEnumerator>();

            enumerator.ModuleInfos = new ModuleInfo[] { new ModuleInfo("Module1", "Module1.Assembly", "~/Module1") };
            ModuleContainerLocatorService service = rootContainer.Services.AddNew <ModuleContainerLocatorService>();

            CompositionContainer result = service.GetContainer("~/Page.aspx");

            Assert.AreSame(rootContainer, result);
        }
Example #29
0
        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);
        }
Example #30
0
        public void AddServiceOnlyIfMissing()
        {
            TestableWebClientApplication     app       = new TestableWebClientApplication();
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            Foo foo = app.TestAddServiceIfMissing <Foo, IFoo>(container);

            Assert.AreSame(foo, container.Services.Get <IFoo>());

            Foo foo2 = app.TestAddServiceIfMissing <Foo, IFoo>(container);

            Assert.AreNotSame(foo2, container.Services.Get <IFoo>());
            Assert.AreSame(foo, container.Services.Get <IFoo>());
        }
        public void LoadCallsAddGlobalServices()
        {
            TestableRootCompositionContainer parentContainer = new TestableRootCompositionContainer();
            TestableRootCompositionContainer container = parentContainer.Containers.AddNew<TestableRootCompositionContainer>("TEST");

            TestableModuleInitializer moduleInitializer = new TestableModuleInitializer();
            ISiteMapBuilderService siteMapBuilder = new MockSiteMapBuilderService();
            IHttpContextLocatorService contextLocator = new MockHttpContextLocatorService();
            container.Services.Add<IHttpContextLocatorService>(contextLocator);
            container.Services.Add<ISiteMapBuilderService>(siteMapBuilder);

            moduleInitializer.Load(container);

            Assert.IsTrue(moduleInitializer.AddGlobalServicesWasCalled);
        }
        public void LoadRegistersTypeMappingForController()
        {
            TestableRootCompositionContainer parentContainer = new TestableRootCompositionContainer();
            TestableRootCompositionContainer container = parentContainer.Containers.AddNew<TestableRootCompositionContainer>("TEST");
            TestableModuleInitializer moduleInitializer = new TestableModuleInitializer();
            container.Services.Add<IHttpContextLocatorService>(new MockHttpContextLocatorService());
            container.Services.Add<ISiteMapBuilderService>(new MockSiteMapBuilderService());

            moduleInitializer.Load(container);

            Assert.AreEqual(typeof(OrdersController), container.GetMappedType(typeof(IOrdersController)));
        }