Exemplo n.º 1
0
        private byte[] SerializeInternal(Type type, object value)
        {
            var method   = SerializeMethods.GetOrAdd(type, t => SerializeMethod.MakeGenericMethod(t));
            var accessor = CallAccessor.Create(method);

            return((byte[])accessor.Call(_serializer, new[] { value }));
        }
Exemplo n.º 2
0
        private object DeserializeInternal(Type type, byte[] bytes)
        {
            var method   = DeserializeMethods.GetOrAdd(type, t => DeserializeMethod.MakeGenericMethod(t));
            var accessor = CallAccessor.Create(method);

            return(accessor.Call(_serializer, new object[] { bytes }));
        }
Exemplo n.º 3
0
        public void Invoke(string handler)
        {
            if (!_handlers.TryGetValue(handler, out var accessor))
            {
                var tokens = handler.Split('.');
                if (tokens.Length > 1)
                {
                    var typeString   = tokens[0];
                    var methodString = tokens[1];

                    var resolver = UiServices.GetRequiredService <ITypeResolver>();
                    var type     = resolver.FindFirstByName(typeString);
                    var method   = type.GetMethod(methodString);

                    _instances[handler] = Instancing.CreateInstance(type, UiServices);
                    _handlers[handler]  = accessor = CallAccessor.Create(method);
                }
            }

            accessor?.Call(_instances[handler], UiServices);
        }
Exemplo n.º 4
0
        private static void ExecuteStandardTest(ITestExecutionRecorder recorder, TestCase test, MethodInfo method,
                                                TestContext context, object instance)
        {
            try
            {
                recorder.SendMessage(TestMessageLevel.Informational, "Running standard test");

                var accessor    = CallAccessor.Create(method);
                var occurrences = 0;

                recorder.RecordResult(DutyCycle(accessor, ++occurrences));

                while (!context.Skipped && context.RepeatCount > 0)
                {
                    recorder.RecordResult(DutyCycle(accessor, ++occurrences));
                    context.RepeatCount--;
                }
            }
            finally
            {
                context.Dispose();
            }

            TestResult DutyCycle(IMethodCallAccessor accessor, int occurrence)
            {
                if (occurrence > 1)
                {
                    var clone = new TestCase
                    {
                        DisplayName        = $"{test.DisplayName ?? "<No Name>"} #{occurrence}",
                        ExecutorUri        = test.ExecutorUri,
                        FullyQualifiedName = test.FullyQualifiedName,
                        Id                 = test.Id,
                        LineNumber         = test.LineNumber,
                        LocalExtensionData = test.LocalExtensionData,
                        CodeFilePath       = test.CodeFilePath,
                        Source             = test.Source
                    };

                    clone.Traits.AddRange(test.Traits);

                    test = clone;
                }


                TestResult testResult = null;

                try
                {
                    recorder.SendMessage(TestMessageLevel.Informational, "Starting test");
                    recorder.RecordStart(test);

                    context.BeginTest();
                    var result = ExecuteTestMethod(accessor, instance, context);
                    context.EndTest();

                    var outcome = context.Skipped ? TestOutcome.Skipped :
                                  result ? TestOutcome.Passed : TestOutcome.Failed;
                    recorder.SendMessage(TestMessageLevel.Informational,
                                         $"{test.DisplayName} => {outcome.ToString().ToLowerInvariant()}");

                    recorder.SendMessage(TestMessageLevel.Informational, "Ending test");
                    recorder.RecordEnd(test, outcome);

                    testResult = new TestResult(test)
                    {
                        Outcome = outcome
                    };
                    if (context.Skipped)
                    {
                        testResult.Messages.Add(new TestResultMessage(Constants.Categories.Skipped,
                                                                      context.SkipReason));
                    }

                    var listener = Trace.Listeners.OfType <TestResultTraceListener>().SingleOrDefault();
                    if (listener != null)
                    {
                        testResult.Messages.Add(listener.ToMessage());
                    }

                    return(testResult);
                }
                catch (Exception ex)
                {
                    recorder.SendMessage(TestMessageLevel.Error, ex.Message);
                    testResult ??= new TestResult(test);

                    testResult.Messages.Add(new TestResultMessage(Constants.Categories.Failed,
                                                                  "Test failed because an exception prevented execution."));

                    testResult.Outcome         = TestOutcome.Failed;
                    testResult.ErrorMessage    = ex.Message;
                    testResult.ErrorStackTrace = ex.StackTrace;

                    return(testResult);
                }
            }
        }
Exemplo n.º 5
0
        private IWebHostBuilder CreateWebHostBuilder
        (
            ICollection <Action <IConfiguration> > configuration,
            ICollection <Action <IServiceCollection> > configureServices,
            ICollection <Action <IApplicationBuilder> > configure,
            SystemTopology topology)
        {
            T startup = null;
            IConfiguration      config   = null;
            IServiceCollection  services = null;
            IWebHostEnvironment env;

            var builder = new WebHostBuilder()
                          .ConfigureAppConfiguration((context, cb) =>
            {
                env = context.HostingEnvironment;
                var testSettings = BuildTestSettings(env.ContentRootPath, env.EnvironmentName);
                ConfigureAppConfiguration(env, testSettings, cb);
                config = cb.Build();
            })
                          .ConfigureServices(serviceCollection =>
            {
                services = serviceCollection;

                Debug.Assert(services != null);
                Debug.Assert(config != null);

                var serviceProvider = serviceCollection.BuildServiceProvider();
                Debug.Assert(serviceProvider != null);

                var container = new DependencyContainer(serviceProvider);

                container.Register(serviceProvider);
                container.Register(services);
                container.Register(config);

                startup = container.Resolve <T>();
                Debug.Assert(startup != null);
                foreach (var action in configuration)
                {
                    action(config);
                }

                container.Register(startup);

                var method = startup.GetType().GetMethod("ConfigureServices");
                if (method != null)
                {
                    var accessor = CallAccessor.Create(method);
                    accessor.Call(startup);
                }

                foreach (var action in configureServices)
                {
                    action(serviceCollection);
                }
            });

            if (topology == SystemTopology.Web)
            {
                builder.Configure(app =>
                {
                    Debug.Assert(services != null);
                    Debug.Assert(config != null);
                    Debug.Assert(startup != null);
                    Debug.Assert(app != null);

                    var serviceProvider = services.BuildServiceProvider();
                    Debug.Assert(serviceProvider != null);

                    var container = new DependencyContainer(serviceProvider);

                    container.Register(serviceProvider);
                    container.Register(services);
                    container.Register(config);
                    container.Register(startup);
                    container.Register(app);

                    var method = startup.GetType().GetMethod("Configure");
                    if (method != null)
                    {
                        var accessor = CallAccessor.Create(method);
                        accessor.Call(startup);
                    }
                    foreach (var action in configure)
                    {
                        action(app);
                    }
                });
            }

            UseAssemblyForSetting <T>(builder, WebHostDefaults.ApplicationKey);
            UseAssemblyForSetting <T>(builder, WebHostDefaults.StartupAssemblyKey);

            Services = services;

            return(builder);
        }