Example #1
0
            public void Assumption()
            {
                manager = new ManagerUnderTestBuilder()
                          .WithAllRegisteredServices()
                          .Build();

                manager.IsConfigured.Should().BeTrue(because: "we are assuming that all services are registered. ");
            }
Example #2
0
            public void RegisteringTestCaseReporterContextWillMakeItPartiallyConfigured()
            {
                manager = new ManagerUnderTestBuilder()
                          .WithTestCaseReporterContextRegistered()
                          .Build();

                manager.IsPartiallyConfigured.Should().BeTrue(because: "we have registered a single service. ");
            }
Example #3
0
        public static void Initialize(ILogger bootstrappingLogger, string prefix, Action <string, IServiceCollection, ITestRunReporterContext> beforeContainerBuild)
        {
            if (_instance != null)
            {
                throw new InvalidOperationException($"The Initialize method has already been called. ");
            }
            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }
            if (beforeContainerBuild == null)
            {
                throw new ArgumentNullException(nameof(beforeContainerBuild));
            }

            Environment.SetEnvironmentVariable("TEST_OUTPUT_FOLDER", Directory.GetCurrentDirectory(), EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("TEST_DEPLOYMENT_FOLDER", Directory.GetCurrentDirectory(), EnvironmentVariableTarget.Process);

            //
            // TODO: When this gets too big, look at Factories
            //

            var services = new ServiceCollection();

            RegisterDeviceSettings(bootstrappingLogger, prefix, services);
            RegisterBrowserSettings(bootstrappingLogger, prefix, services);

            var instrumentationSettings = ConfigureSettings <IInstrumentationSettings, InstrumentationSettings>(bootstrappingLogger, prefix, "InstrumentationSettings", "common.json", "instrumentationSettings", services);

            RegisterSettings <RemoteWebDriverSettings>(bootstrappingLogger, prefix, "RemoteWebDriverSettings", "common-localhost-selenium.json", "remoteWebDriverSettings", services, registerInstance: true);
            RegisterSettings <EnvironmentSettings>(bootstrappingLogger, prefix, "EnvironmentSettings", "internet.json", "environmentSettings", services, registerInstance: true);
            ConfigureSettings <IControlSettings, ControlSettings>(bootstrappingLogger, prefix, "ControlSettings", "common.json", "controlSettings", services);

            // Clear the variables so they do not creep into the rest of our implementation
            Environment.SetEnvironmentVariable("TEST_OUTPUT_FOLDER", null, EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("TEST_DEPLOYMENT_FOLDER", null, EnvironmentVariableTarget.Process);

            // Singletons: statics that are instantiated once for the lifetime of the entire test run
            services.AddSingleton <IDriverSessionFactory, DriverSessionFactory>();

            var testRunReporterContext = new TestRunReporterContext()
            {
                InstrumentationSettings = instrumentationSettings,
                RootReportingFolder     = instrumentationSettings.RootReportingFolder,
                TestRunIdentity         = DateTime.Now.ToString("yyyyMMdd-HHmmss")
            };

            services.AddSingleton <ITestRunReporterContext>(testRunReporterContext);

            // Scoped: per test
            services.AddScoped(isp =>
            {
                var serilogContext = BuildSerilogConfiguration();

                var logPath = isp.GetRequiredService <ITestCaseReporterContext>().LogFilePath;

                LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
                                                          .ReadFrom
                                                          .Configuration(serilogContext)
                                                          .Enrich
                                                          .FromLogContext();

                if (isp.GetRequiredService <IInstrumentationSettings>().LogFilePerTest)
                {
                    loggerConfiguration.WriteTo
                    .File(logPath);
                }
                ;

                ILogger logger = loggerConfiguration.CreateLogger();

                return(logger);
            });

            services.AddScoped <ICommandExecutor>(isp =>
            {
                var remoteWebDriverSettings = isp.GetRequiredService <RemoteWebDriverSettings>();

                var commandExecutor = new HttpCommandExecutor(new Uri(remoteWebDriverSettings.RemoteUri), TimeSpan.FromSeconds(remoteWebDriverSettings.HttpCommandExecutorTimeoutInSeconds));

                return(commandExecutor);
            });

            services.AddScoped(isp =>
            {
                var factory                 = isp.GetRequiredService <IDriverSessionFactory>();
                var browserProperties       = isp.GetRequiredService <IBrowserProperties>();
                var remoteWebDriverSettings = isp.GetRequiredService <RemoteWebDriverSettings>();
                var environmentSettings     = isp.GetRequiredService <EnvironmentSettings>();
                var controlSettings         = isp.GetRequiredService <IControlSettings>();
                var deviceSettings          = isp.GetRequiredService <IDeviceProperties>();
                var logger              = isp.GetRequiredService <ILogger>();
                var testCaseReporter    = isp.GetRequiredService <ITestCaseReporter>();
                var httpCommandExecutor = isp.GetRequiredService <ICommandExecutor>();

                var driverSession = factory.Create(deviceSettings, browserProperties, remoteWebDriverSettings, environmentSettings, controlSettings, logger, testCaseReporter, httpCommandExecutor);
                return(driverSession);
            });

            beforeContainerBuild(prefix, services, testRunReporterContext);

            var reportingContextManager = new ReportingContextRegistrationManager(bootstrappingLogger, services, testRunReporterContext);

            reportingContextManager.AssertIsNotPartiallyConfigured();
            if (!reportingContextManager.IsConfigured)
            {
                reportingContextManager.PopulateDefaultReportingContexts();
            }

            _instance = services.BuildServiceProvider();
        }
Example #4
0
 public void Assumption()
 {
     manager = new ManagerUnderTestBuilder()
               .WithNoRegisteredServices()
               .Build();
 }
Example #5
0
 public void Assumption()
 {
     manager = new ManagerUnderTestBuilder()
               .WithTestCaseReporterContextRegistered()
               .Build();
 }