public void ShouldStartApplication()
        {
            TestApplicationManager applicationManager = new TestApplicationManager();

            TestApplication result = applicationManager.StartApplication(this.applicationHost);

            Assert.NotNull(result);
            Assert.True(RemotingServices.IsObjectOutOfAppDomain(result));
            Assert.True(RemotingServices.IsTransparentProxy(result));
            Assert.Contains(this.applicationHost.ApplicationId, ApplicationManager.GetApplicationManager().GetRunningApplications().Select(app => app.ID));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of corresponding class.
        /// </summary>
        /// <param name="testType">Type of the test to instantiate.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>Instance of the class.</returns>
        public static LiveTest Instantiate(Type testType, params object[] arguments)
        {
            if (HostingEnvironment.IsHosted)
            {
                return(CreateUninitializedInstance(testType));
            }

            if (InstantiatedByProxy(testType, arguments))
            {
                return(Intercept(testType, null));
            }

            MethodInfo getDefaultTestApplicationManagerMethod = Utility.GetInheritedMethod(testType, GetDefaultTestApplicationManagerName, new[] { typeof(Type), typeof(object[]) });
            MethodInfo getDefaultApplicationHostMethod        = Utility.GetInheritedMethod(testType, GetDefaultApplicationHostName, new[] { typeof(Type), typeof(object[]) });

            if (getDefaultTestApplicationManagerMethod == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot create an instance of type '{0}' because there is no '{1}' static method defined in its inheritance hierarchy. See '{2}' methods for an example of corresponding method signature.", testType.AssemblyQualifiedName, GetDefaultTestApplicationManagerName, typeof(LiveTest).AssemblyQualifiedName));
            }

            if (getDefaultApplicationHostMethod == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot create an instance of type '{0}' because there is no '{1}' static method defined in its inheritance hierarchy. See '{2}' methods for an example of corresponding method signature.", testType.AssemblyQualifiedName, GetDefaultApplicationHostName, typeof(LiveTest).AssemblyQualifiedName));
            }

            object[] allArguments = { testType, arguments };

            TestApplicationManager testApplicationManager = (TestApplicationManager)getDefaultTestApplicationManagerMethod.Invoke(null, allArguments);

            if (testApplicationManager == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to get an instance of '{0}'.", typeof(TestApplicationManager).AssemblyQualifiedName));
            }

            TestApplicationHost host = (TestApplicationHost)getDefaultApplicationHostMethod.Invoke(null, allArguments);

            if (host == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to get an instance of '{0}'.", typeof(TestApplicationHost).AssemblyQualifiedName));
            }

            TestApplication testApplication = testApplicationManager.StartApplication(host);

            if (testApplication == null)
            {
                throw new InvalidOperationException("Failed to get application to execute tests in.");
            }

            return((LiveTest)testApplication.CreateObject(testType, arguments));
        }