-Refactor tests

This commit is contained in:
James Newton-King
2017-07-23 17:01:48 +12:00
parent 403470d59a
commit 36bcc55ee6
26 changed files with 956 additions and 292 deletions
@@ -10182,293 +10182,4 @@ This is just junk, though.";
"Unexpected character encountered while parsing value: ,. Path 'E', line 1, position 36.");
}
}
public class JsonPropertyConverterTestClass
{
public DateTime NormalDate { get; set; }
public DateTime JavaScriptDate { get; set; }
}
public class JsonPropertyConverterContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
if (property.PropertyName == "JavaScriptDate")
{
property.Converter = new JavaScriptDateTimeConverter();
}
return property;
}
}
public class BaseClassWithProtectedVirtual
{
protected virtual string MyProperty { get; set; }
}
public class ChildClassWithProtectedOverridePlusJsonProperty : BaseClassWithProtectedVirtual
{
[JsonProperty]
protected override string MyProperty { get; set; }
public string GetPropertyValue()
{
return MyProperty;
}
}
public class DerivedWithPrivate : BaseWithPrivate
{
[JsonProperty]
public string DerivedProperty { get; private set; }
}
public class BaseWithPrivate
{
[JsonProperty]
public string BaseProperty { get; private set; }
}
public abstract class Test<T>
{
public abstract T Value { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class DecimalTest : Test<decimal>
{
protected DecimalTest()
{
}
public DecimalTest(decimal val)
{
Value = val;
}
[JsonProperty]
public override decimal Value { get; set; }
}
public class NonPublicConstructorWithJsonConstructor
{
public string Value { get; private set; }
public string Constructor { get; private set; }
[JsonConstructor]
private NonPublicConstructorWithJsonConstructor()
{
Constructor = "NonPublic";
}
public NonPublicConstructorWithJsonConstructor(string value)
{
Value = value;
Constructor = "Public Parameterized";
}
}
public abstract class AbstractTestClass
{
public string Value { get; set; }
}
public class AbstractImplementationTestClass : AbstractTestClass
{
}
public abstract class AbstractListTestClass<T> : List<T>
{
}
public class AbstractImplementationListTestClass<T> : AbstractListTestClass<T>
{
}
public abstract class AbstractDictionaryTestClass<TKey, TValue> : Dictionary<TKey, TValue>
{
}
public class AbstractImplementationDictionaryTestClass<TKey, TValue> : AbstractDictionaryTestClass<TKey, TValue>
{
}
public class PublicConstructorOverridenByJsonConstructor
{
public string Value { get; private set; }
public string Constructor { get; private set; }
public PublicConstructorOverridenByJsonConstructor()
{
Constructor = "NonPublic";
}
[JsonConstructor]
public PublicConstructorOverridenByJsonConstructor(string value)
{
Value = value;
Constructor = "Public Parameterized";
}
}
public class MultipleParametrizedConstructorsJsonConstructor
{
public string Value { get; private set; }
public int Age { get; private set; }
public string Constructor { get; private set; }
public MultipleParametrizedConstructorsJsonConstructor(string value)
{
Value = value;
Constructor = "Public Parameterized 1";
}
[JsonConstructor]
public MultipleParametrizedConstructorsJsonConstructor(string value, int age)
{
Value = value;
Age = age;
Constructor = "Public Parameterized 2";
}
}
public class EnumerableClass
{
public IEnumerable<string> Enumerable { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class ItemBase
{
[JsonProperty]
public string Name { get; set; }
}
public class ComplexItem : ItemBase
{
public Stream Source { get; set; }
}
public class DeserializeStringConvert
{
public string Name { get; set; }
public int Age { get; set; }
public double Height { get; set; }
public decimal Price { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class StaticTestClass
{
[JsonProperty]
public int x = 1;
[JsonProperty]
public static int y = 2;
[JsonProperty]
public static int z { get; set; }
static StaticTestClass()
{
z = 3;
}
}
public class CompletionDataRequest
{
public CompletionDataRequest(string text, int cursorPosition, string dataSource, string project)
{
Text = text;
CursorPosition = cursorPosition;
DataSource = dataSource;
Project = project;
}
public string Text { get; }
public int CursorPosition { get; }
public string DataSource { get; }
public string Project { get; }
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
public class ISerializableTestObject : ISerializable
{
internal string _stringValue;
internal int _intValue;
internal DateTimeOffset _dateTimeOffsetValue;
internal Person _personValue;
internal Person _nullPersonValue;
internal int? _nullableInt;
internal bool _booleanValue;
internal byte _byteValue;
internal char _charValue;
internal DateTime _dateTimeValue;
internal decimal _decimalValue;
internal short _shortValue;
internal long _longValue;
internal sbyte _sbyteValue;
internal float _floatValue;
internal ushort _ushortValue;
internal uint _uintValue;
internal ulong _ulongValue;
public ISerializableTestObject(string stringValue, int intValue, DateTimeOffset dateTimeOffset, Person personValue)
{
_stringValue = stringValue;
_intValue = intValue;
_dateTimeOffsetValue = dateTimeOffset;
_personValue = personValue;
_dateTimeValue = new DateTime(0, DateTimeKind.Utc);
}
protected ISerializableTestObject(SerializationInfo info, StreamingContext context)
{
_stringValue = info.GetString("stringValue");
_intValue = info.GetInt32("intValue");
_dateTimeOffsetValue = (DateTimeOffset)info.GetValue("dateTimeOffsetValue", typeof(DateTimeOffset));
_personValue = (Person)info.GetValue("personValue", typeof(Person));
_nullPersonValue = (Person)info.GetValue("nullPersonValue", typeof(Person));
_nullableInt = (int?)info.GetValue("nullableInt", typeof(int?));
_booleanValue = info.GetBoolean("booleanValue");
_byteValue = info.GetByte("byteValue");
_charValue = info.GetChar("charValue");
_dateTimeValue = info.GetDateTime("dateTimeValue");
_decimalValue = info.GetDecimal("decimalValue");
_shortValue = info.GetInt16("shortValue");
_longValue = info.GetInt64("longValue");
_sbyteValue = info.GetSByte("sbyteValue");
_floatValue = info.GetSingle("floatValue");
_ushortValue = info.GetUInt16("ushortValue");
_uintValue = info.GetUInt32("uintValue");
_ulongValue = info.GetUInt64("ulongValue");
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("stringValue", _stringValue);
info.AddValue("intValue", _intValue);
info.AddValue("dateTimeOffsetValue", _dateTimeOffsetValue);
info.AddValue("personValue", _personValue);
info.AddValue("nullPersonValue", _nullPersonValue);
info.AddValue("nullableInt", null);
info.AddValue("booleanValue", _booleanValue);
info.AddValue("byteValue", _byteValue);
info.AddValue("charValue", _charValue);
info.AddValue("dateTimeValue", _dateTimeValue);
info.AddValue("decimalValue", _decimalValue);
info.AddValue("shortValue", _shortValue);
info.AddValue("longValue", _longValue);
info.AddValue("sbyteValue", _sbyteValue);
info.AddValue("floatValue", _floatValue);
info.AddValue("ushortValue", _ushortValue);
info.AddValue("uintValue", _uintValue);
info.AddValue("ulongValue", _ulongValue);
}
}
#endif
}