Ejemplo n.º 1
0
        /// <summary>
        /// Runs the given test <paramref name="action"/> within an environment
        /// where the given <paramref name="intrinsics"/> features.
        /// </summary>
        /// <param name="action">The test action to run.</param>
        /// <param name="intrinsics">The intrinsics features.</param>
        /// <param name="serializable">The value to pass as a parameter to the test action.</param>
        public static void RunWithHwIntrinsicsFeature <T>(
            Action <string> action,
            HwIntrinsics intrinsics,
            T serializable)
            where T : IXunitSerializable
        {
            if (!RemoteExecutor.IsSupported)
            {
                return;
            }

            foreach (KeyValuePair <HwIntrinsics, string> intrinsic in intrinsics.ToFeatureKeyValueCollection())
            {
                var processStartInfo = new ProcessStartInfo();
                if (intrinsic.Key != HwIntrinsics.AllowAll)
                {
                    processStartInfo.Environment[$"COMPlus_{intrinsic.Value}"] = "0";

                    RemoteExecutor.Invoke(
                        action,
                        BasicSerializer.Serialize(serializable),
                        new RemoteInvokeOptions
                    {
                        StartInfo = processStartInfo
                    })
                    .Dispose();
                }
                else
                {
                    // Since we are running using the default architecture there is no
                    // point creating the overhead of running the action in a separate process.
                    action(BasicSerializer.Serialize(serializable));
                }
            }
        }
Ejemplo n.º 2
0
        public static string Serialize(IXunitSerializable serializable)
        {
            var serializer = new BasicSerializer();

            serializable.Serialize(serializer);
            return(serializer.DumpToString(serializable.GetType()));
        }
Ejemplo n.º 3
0
        public static T Deserialize <T>(string dump) where T : IXunitSerializable
        {
            var  serializer = new BasicSerializer();
            Type type       = serializer.LoadDump(dump);

            var result = (T)Activator.CreateInstance(type);

            result.Deserialize(serializer);
            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Allows the deserialization of parameters passed to the feature test.
 /// <remark>
 /// <para>
 /// This is required because <see cref="RemoteExecutor"/> does not allow
 /// marshalling of fields so we cannot pass a wrapped <see cref="Action{T}"/>
 /// allowing automatic deserialization.
 /// </para>
 /// </remark>
 /// </summary>
 /// <typeparam name="T">The type to deserialize to.</typeparam>
 /// <param name="value">The string value to deserialize.</param>
 /// <returns>The <see cref="T"/> value.</returns>
 public static T DeserializeForXunit <T>(string value)
     where T : IXunitSerializable
 => BasicSerializer.Deserialize <T>(value);