Exemplo n.º 1
0
        public void ShouldDiscoverInitializationActionsMatchingToAssemblyDefinedInitializationHandlerAttributes()
        {
            TestApplicationInitializationContext          context    = new TestApplicationInitializationContext(Substitute.For <TestApplication>(Substitute.For <InitializationManager>(new TestInitializationActionDiscoverer(), new InitializationActionExecutor())));
            TestApplicationInitializationActionDiscoverer discoverer = new TestApplicationInitializationActionDiscoverer();

            IEnumerable <InitializationAction> result = discoverer.GetInitializationActions(context).ToArray();

            Assert.Equal(3, result.Count());

            Assert.Equal(typeof(SampleInitializationHandler).AssemblyQualifiedName, result.First().Id);
            Assert.IsType <InitializationHandler>(result.First().State);
            Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.First().State).Type);
            Assert.Empty(((InitializationHandler)result.First().State).Arguments);
            Assert.Equal(context, result.First().Context);

            Assert.Equal(typeof(SampleInitializationHandler).AssemblyQualifiedName, result.ElementAt(1).Id);
            Assert.IsType <InitializationHandler>(result.ElementAt(1).State);
            Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.ElementAt(1).State).Type);
            Assert.Equal(new object[] { "parameter" }, ((InitializationHandler)result.ElementAt(1).State).Arguments);
            Assert.Equal(context, result.ElementAt(1).Context);

            Assert.Equal(typeof(SampleInitializationHandler).AssemblyQualifiedName, result.ElementAt(2).Id);
            Assert.IsType <InitializationHandler>(result.ElementAt(2).State);
            Assert.Equal(typeof(SampleInitializationHandler), ((InitializationHandler)result.ElementAt(2).State).Type);
            Assert.Empty(((InitializationHandler)result.ElementAt(2).State).Arguments);
            Assert.Equal(context, result.ElementAt(2).Context);
        }
Exemplo n.º 2
0
        public void ShouldThrowNotSupportedExceptionForOtherThanTestApplicationInitializationContextTypesOfContexts()
        {
            TestApplicationInitializationActionDiscoverer discoverer = new TestApplicationInitializationActionDiscoverer();

            Assert.ThrowsDelegate action = () => discoverer.GetInitializationActions("context");

            Assert.Throws <NotSupportedException>(action);
        }