Esempio n. 1
0
 /// <inheritdoc/>
 public virtual void GetData(XunitSerializationInfo data)
 {
     // TODO: Should throw when TestMethodArguments is not null/empty?
     data.AddValue("TestMethod", TestMethod);
     data.AddValue("TestMethodArguments", TestMethodArguments);
     data.AddValue("DefaultMethodDisplay", DefaultMethodDisplay.ToString());
 }
        /// <summary>
        /// Serializes an object.
        /// </summary>
        /// <param name="value">The value to serialize</param>
        /// <returns>The serialized value</returns>
        public static string Serialize(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var array = value as object[];

            if (array != null)
            {
                value = new XunitSerializationInfo.ArraySerializer(array);
            }

            var serializable = value as IXunitSerializable;

            if (serializable == null)
            {
                throw new ArgumentException("Cannot serialize an object that does not implement " + typeof(IXunitSerializable).FullName, "value");
            }

            var serializationInfo = new XunitSerializationInfo(serializable);

            return(String.Format("{0}:{1}", GetTypeNameForSerialization(value.GetType()), serializationInfo.ToSerializedString()));
        }
Esempio n. 3
0
        /// <summary>
        /// Serializes an object.
        /// </summary>
        /// <param name="value">The value to serialize</param>
        /// <returns>The serialized value</returns>
        public static string Serialize(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var array = value as object[];

            if (array != null)
            {
                value = new XunitSerializationInfo.ArraySerializer(array);
            }

            var getData = value as IGetTypeData;

            if (getData == null)
            {
                throw new ArgumentException("Cannot serialize an object that does not implement IGetTypeData", "value");
            }

            var serializationInfo = new XunitSerializationInfo(getData);

            return(String.Format("{0}:{1}", value.GetType().AssemblyQualifiedName, serializationInfo.ToSerializedString()));
        }
        /// <summary>
        /// De-serializes an object.
        /// </summary>
        /// <typeparam name="T">The type of the object</typeparam>
        /// <param name="serializedValue">The object's serialized value</param>
        /// <returns>The de-serialized object</returns>
        public static T Deserialize <T>(string serializedValue)
        {
            if (serializedValue == null)
            {
                throw new ArgumentNullException("serializedValue");
            }

            var pieces = serializedValue.Split(new[] { ':' }, 2);

            if (pieces.Length != 2)
            {
                throw new ArgumentException("De-serialized string is in the incorrect format.");
            }

            var deserializedType = GetType(pieces[0]);

            if (deserializedType == null)
            {
                throw new ArgumentException("Could not load type " + pieces[0], "serializedValue");
            }

            if (!typeof(IXunitSerializable).IsAssignableFrom(deserializedType))
            {
                throw new ArgumentException("Cannot de-serialize an object that does not implement " + typeof(IXunitSerializable).FullName, "T");
            }

            var obj = XunitSerializationInfo.Deserialize(deserializedType, pieces[1]);

            if (obj is XunitSerializationInfo.ArraySerializer)
            {
                obj = ((XunitSerializationInfo.ArraySerializer)obj).ArrayData;
            }

            return((T)obj);
        }
        public static void CanSerializeEnumFromLocalAssembly()
        {
            var data = MyEnum.SomeValue;

            var result = XunitSerializationInfo.Serialize(data);

            Assert.Equal("SomeValue", result);
        }
        public static void CanSerializeTypeFromMscorlib()
        {
            var data = typeof(string);

            var result = XunitSerializationInfo.Serialize(data);

            Assert.Equal("System.String", result);
        }
        public static void CanSerializeTypeFromLocalAssembly()
        {
            var data = typeof(XunitSerializationInfo);

            var result = XunitSerializationInfo.Serialize(data);

            Assert.Equal("Xunit.Serialization.XunitSerializationInfo, test.xunit.execution", result);
        }
Esempio n. 8
0
        /// <inheritdoc/>
        public void SetData(XunitSerializationInfo info)
        {
            TestClass = info.GetValue <ITestClass>("TestClass");

            var methodName = info.GetString("MethodName");

            Method = TestClass.Class.GetMethod(methodName, includePrivateMethod: false);
        }
        public static void CanSerializeEnumFromMscorlib()
        {
            var data = Base64FormattingOptions.InsertLineBreaks;

            var result = XunitSerializationInfo.Serialize(data);

            Assert.Equal("InsertLineBreaks", result);
        }
Esempio n. 10
0
        public static void CanRoundTripIXunitSerializableWithNoSerializedData()
        {
            var data = new MySerializableWithNoData();

            var serialized   = XunitSerializationInfo.Serialize(data);
            var deserialized = (MySerializableWithNoData)XunitSerializationInfo.Deserialize(typeof(MySerializableWithNoData), serialized);

            Assert.NotNull(deserialized);
        }
Esempio n. 11
0
        /// <inheritdoc/>
        public void SetData(XunitSerializationInfo info)
        {
            TestCollection = info.GetValue <ITestCollection>("TestCollection");

            var assemblyName = info.GetString("ClassAssemblyName");
            var typeName     = info.GetString("ClassTypeName");

            Class = Reflector.Wrap(Reflector.GetType(assemblyName, typeName));
        }
        public static void CanRoundTrip_PublicClass_PublicTestMethod()
        {
            var testCase = TestableTestMethodTestCase.Create <Serialization>("CanRoundTrip_PublicClass_PublicTestMethod");

            var serialized   = XunitSerializationInfo.Serialize(testCase);
            var deserialized = XunitSerializationInfo.Deserialize(typeof(TestableTestMethodTestCase), serialized);

            Assert.NotNull(deserialized);
        }
Esempio n. 13
0
        public static void IXunitSerializableWithoutParameterlessConstructorThrows()
        {
            var data = new MySerializableWithoutParameterlessConstructor(42);

            var serialized = XunitSerializationInfo.Serialize(data);
            var ex         = Record.Exception(() => XunitSerializationInfo.Deserialize(typeof(MySerializableWithoutParameterlessConstructor), serialized));

            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("Could not de-serialize type 'XunitSerializationInfoTests+MySerializableWithoutParameterlessConstructor' because it lacks a parameterless constructor.", ex.Message);
        }
Esempio n. 14
0
        public static void CanRoundTripIntrinsics(Type dataType, object data)
        {
            var triple       = new XunitSerializationTriple(Guid.NewGuid().ToString(), data, dataType);
            var serialized   = XunitSerializationInfo.SerializeTriple(triple);
            var deserialized = XunitSerializationInfo.DeserializeTriple(serialized);

            Assert.Equal(triple.Key, deserialized.Key);
            Assert.Equal(triple.Type, deserialized.Type);
            Assert.Equal(triple.Value, deserialized.Value);
        }
Esempio n. 15
0
        public static void CanRoundTypeIXunitSerializable()
        {
            var data = new MySerializable {
                IntValue = 42, StringValue = "Hello\r\nworld!"
            };

            var deserialized = (MySerializable)XunitSerializationInfo.Deserialize(typeof(MySerializable), XunitSerializationInfo.Serialize(data));

            Assert.Equal(42, deserialized.IntValue);
            Assert.Equal("Hello\r\nworld!", deserialized.StringValue);
        }
Esempio n. 16
0
        /// <inheritdoc/>
        public void SetData(XunitSerializationInfo info)
        {
            var assemblyPath = info.GetString("AssemblyPath");
            var assembly     = System.Reflection.Assembly.Load(new AssemblyName
            {
                Name = Path.GetFileNameWithoutExtension(assemblyPath)
            });

            ConfigFileName = info.GetString("ConfigFileName");
            Assembly       = Reflector.Wrap(assembly);
        }
Esempio n. 17
0
        public static void UnsupportedTypeThrows()
        {
            var data = new object();

            var ex = Record.Exception(() => XunitSerializationInfo.Serialize(data));

            var argEx = Assert.IsType <ArgumentException>(ex);

            Assert.Equal("value", argEx.ParamName);
            Assert.StartsWith("We don't know how to serialize type System.Object", argEx.Message);
        }
Esempio n. 18
0
        public static void UnsupportedTypeThrows()
        {
            var triple = new XunitSerializationTriple(Guid.NewGuid().ToString(), new object(), typeof(object));

            var ex = Record.Exception(() => XunitSerializationInfo.SerializeTriple(triple));

            var argEx = Assert.IsType <ArgumentException>(ex);

            Assert.Equal("value", argEx.ParamName);
            Assert.StartsWith("We don't know how to serialize type System.Object", argEx.Message);
        }
Esempio n. 19
0
        public static void CannotSerializeTypeFromGAC()
        {
            var data = typeof(XmlDocument);

            var ex = Record.Exception(() => XunitSerializationInfo.Serialize(data));

            var argEx = Assert.IsType <ArgumentException>(ex);

            Assert.Equal("type", argEx.ParamName);
            Assert.StartsWith("We cannot serialize type System.Xml.XmlDocument because it lives in the GAC", argEx.Message);
        }
Esempio n. 20
0
        public static void CannotSerializeEnumFromGAC()
        {
            var data = ConformanceLevel.Auto;

            var ex = Record.Exception(() => XunitSerializationInfo.Serialize(data));

            var argEx = Assert.IsType <ArgumentException>(ex);

            Assert.Equal("value", argEx.ParamName);
            Assert.StartsWith("We cannot serialize enum System.Xml.ConformanceLevel.Auto because it lives in the GAC", argEx.Message);
        }
Esempio n. 21
0
        /// <inheritdoc/>
        public void SetData(XunitSerializationInfo info)
        {
            DisplayName  = info.GetString("DisplayName");
            TestAssembly = info.GetValue <ITestAssembly>("TestAssembly");
            UniqueID     = Guid.Parse(info.GetString("UniqueID"));

            var assemblyName = info.GetString("DeclarationAssemblyName");
            var typeName     = info.GetString("DeclarationTypeName");

            if (!String.IsNullOrWhiteSpace(assemblyName) && String.IsNullOrWhiteSpace(typeName))
            {
                CollectionDefinition = Reflector.Wrap(Reflector.GetType(assemblyName, typeName));
            }
        }
Esempio n. 22
0
        public static void CanRoundTypeIXunitSerializable()
        {
            var data = new MySerializable {
                IntValue = 42, StringValue = "Hello\r\nworld!"
            };
            var triple       = new XunitSerializationTriple(Guid.NewGuid().ToString(), data, data.GetType());
            var serialized   = XunitSerializationInfo.SerializeTriple(triple);
            var deserialized = XunitSerializationInfo.DeserializeTriple(serialized);

            Assert.Equal(triple.Key, deserialized.Key);
            Assert.Equal(triple.Type, deserialized.Type);
            var deserializedInner = (MySerializable)deserialized.Value;

            Assert.Equal(42, deserializedInner.IntValue);
            Assert.Equal("Hello\r\nworld!", deserializedInner.StringValue);
        }
Esempio n. 23
0
        /// <inheritdoc/>
        public void GetData(XunitSerializationInfo info)
        {
            info.AddValue("DisplayName", DisplayName);
            info.AddValue("TestAssembly", TestAssembly);
            info.AddValue("UniqueID", UniqueID.ToString());

            if (CollectionDefinition != null)
            {
                info.AddValue("DeclarationAssemblyName", CollectionDefinition.Assembly.Name);
                info.AddValue("DeclarationTypeName", CollectionDefinition.Name);
            }
            else
            {
                info.AddValue("DeclarationAssemblyName", null);
                info.AddValue("DeclarationTypeName", null);
            }
        }
Esempio n. 24
0
        void SerializationWorks()
        {
            var exceptionTestCase = CreateTestCase();

            var info = new XunitSerializationInfo();

            exceptionTestCase.Serialize(info);

            var deserializedTestCase = new ExceptionTestCase();

            deserializedTestCase.Deserialize(info);

            Assert.Equal(exceptionTestCase.Types, deserializedTestCase.Types);
            Assert.Equal(exceptionTestCase.Messages, deserializedTestCase.Messages);
            Assert.Equal(exceptionTestCase.StackTraces, deserializedTestCase.StackTraces);
            Assert.Equal(exceptionTestCase.ParentIndices, deserializedTestCase.ParentIndices);
        }
Esempio n. 25
0
        /// <summary>
        /// Serializes an object.
        /// </summary>
        /// <param name="value">The value to serialize</param>
        /// <returns>The serialized value</returns>
        public static string Serialize(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value is object[] array)
            {
                value = new XunitSerializationInfo.ArraySerializer(array);
            }

            if (!(value is IXunitSerializable serializable))
            {
                throw new ArgumentException("Cannot serialize an object that does not implement " + typeof(IXunitSerializable).FullName, nameof(value));
            }

            var serializationInfo = new XunitSerializationInfo(serializable);

            return($"{GetTypeNameForSerialization(value.GetType())}:{serializationInfo.ToSerializedString()}");
        }
Esempio n. 26
0
 /// <inheritdoc/>
 public void SetData(XunitSerializationInfo data)
 {
     TestMethod          = data.GetValue <ITestMethod>("TestMethod");
     TestMethodArguments = null;
 }
Esempio n. 27
0
        public static VsTestCaseBase DeserializeFromString(string value)
        {
            var triple = XunitSerializationInfo.DeserializeTriple(value);

            return((VsTestCaseBase)triple.Value);
        }
Esempio n. 28
0
        public string SerializeToString()
        {
            var triple = new XunitSerializationTriple(nameof(VsTestCaseBase), this, GetType());

            return(XunitSerializationInfo.SerializeTriple(triple));
        }
 public static T GetValue <T>(this XunitSerializationInfo info, string name)
 {
     return((T)info.GetValue(name, typeof(T)));
 }
Esempio n. 30
0
 public static void CanRoundTripIntrinsics(Type dataType, object data)
 {
     Assert.Equal(data, XunitSerializationInfo.Deserialize(dataType, XunitSerializationInfo.Serialize(data)));
 }