コード例 #1
0
 public IEnumerable<IRunElement> Perceive(ITestClassCommand ntcc)
 {
     var securityAttribute = ntcc.TypeUnderTest.GetFirstCustomAttribute<NuwaServerCertificateAttribute>();
     if (securityAttribute != null)
     {
         var elem = new SecurityOptionElement(securityAttribute.Certificate);
         return this.ToArray(elem);
     }
     else
     {
         return this.Empty();
     }
 }
コード例 #2
0
        protected override bool InitializeServer(RunFrame frame)
        {
            string baseAddress;
            string port;

            AppDomain sandbox = CreateFullTrustAppDomain();

            frame.SetState(KeySandbox, sandbox);

            // load test assemly into sandbox
            if (sandbox != null && TypeDescriptor.TestAssembly != null)
            {
                sandbox.Load(TypeDescriptor.TestAssembly.GetName());
            }

            // setup security strategy and base address
            port = _portArranger.Reserve();
            SecurityOptionElement securityElem = frame.GetFirstElement <SecurityOptionElement>();

            if (securityElem != null)
            {
                SetupSecureEnvironment(securityElem.Certificate, port);
                baseAddress = string.Format(SecureBaseAddressTemplate, port);
                frame.SetState(KeyIsSecuredServer, true);
            }
            else
            {
                baseAddress = string.Format(NormalBaseAddressTemplate, port);
                frame.SetState(KeyIsSecuredServer, false);
            }

            // looking into the RunFrames and search for TraceElement. if it exists
            // set the tracer's type to the configuration otherwise skip this step
            TraceElement traceElem = frame.GetFirstElement <TraceElement>();
            Type         traceType = null;

            if (traceElem != null)
            {
                traceType = traceElem.TracerType;
            }

            // create initiator in the sandbox
            SelfHostServerInitiator serverInitiator;

            if (sandbox != null)
            {
                serverInitiator = sandbox.CreateInstanceAndUnwrap(
                    typeof(SelfHostServerInitiator).Assembly.FullName,
                    typeof(SelfHostServerInitiator).FullName)
                                  as SelfHostServerInitiator;
            }
            else
            {
                serverInitiator = new SelfHostServerInitiator();
            }

            // set up the server
            serverInitiator.Setup(baseAddress, TypeDescriptor.ConfigureMethod, traceType, GetDefaultRouteTemplate());

            frame.SetState(KeyReservedPort, port);
            frame.SetState(KeyBaseAddresss, baseAddress);
            frame.SetState(KeyServerInitiator, serverInitiator);

            return(true);
        }