Exemplo n.º 1
0
        public TestEnvironmentBase(TestEnvironmentArgs args = null)
        {
            if (args == null)
            {
                args = new TestEnvironmentArgs();
            }

            if (args.FullUri == null && args.HostName == null)
            {
                args.HostName = "127.0.0.1";
            }

            string uri = args.FullUri != null ? args.FullUri : new Uri($"{(args.UseHttps ? "https" : "http")}://{args.HostName}:{args.Port}/").ToString();

            if (args.UseProxyBasedDependencyManager == true)
            {
                DefaultDependencyManager.Current = new AutofacTestDependencyManager();

                TestDependencyManager.CurrentTestDependencyManager.AutoProxyCreationIncludeRules.AddRange(args.AutoProxyCreationIncludeRules.Union(new Func <TypeInfo, bool>[]
                {
                    serviceType => GetType().GetTypeInfo().Assembly == serviceType.Assembly
                }));

                TestDependencyManager.CurrentTestDependencyManager.AutoProxyCreationIgnoreRules.AddRange(args.AutoProxyCreationIgnoreRules);
            }

            DefaultDependenciesManagerProvider.Current = args.CustomDependenciesManagerProvider ?? DependenciesManagerProviderBuilder(args);
            DefaultAppEnvironmentProvider.Current      = args.CustomAppEnvironmentProvider ?? AppEnvironmentProviderBuilder(args);

            if (args.UseRealServer == true)
            {
                Server = TestServerFactory.GetSelfHostTestServer();
            }
            else
            {
                Server = TestServerFactory.GetEmbeddedTestServer();
            }

            Server.Initialize(uri);
        }