public void ReadAsTests() { InstanceCreatorSurrogate oldSurrogate = CreatorSettings.CreatorSurrogate; try { CreatorSettings.CreatorSurrogate = new NoInfinityFloatSurrogate(); DateTime now = DateTime.Now; int seed = (10000 * now.Year) + (100 * now.Month) + now.Day; Log.Info("Seed: {0}", seed); Random rndGen = new Random(seed); this.ReadAsTest <DCType_1>(rndGen); this.ReadAsTest <StructGuid>(rndGen); this.ReadAsTest <StructInt16>(rndGen); this.ReadAsTest <DCType_3>(rndGen); this.ReadAsTest <SerType_4>(rndGen); this.ReadAsTest <SerType_5>(rndGen); this.ReadAsTest <DCType_7>(rndGen); this.ReadAsTest <DCType_9>(rndGen); this.ReadAsTest <SerType_11>(rndGen); this.ReadAsTest <DCType_15>(rndGen); this.ReadAsTest <DCType_16>(rndGen); this.ReadAsTest <DCType_18>(rndGen); this.ReadAsTest <DCType_19>(rndGen); this.ReadAsTest <DCType_20>(rndGen); this.ReadAsTest <SerType_22>(rndGen); this.ReadAsTest <DCType_25>(rndGen); this.ReadAsTest <SerType_26>(rndGen); this.ReadAsTest <DCType_31>(rndGen); this.ReadAsTest <DCType_32>(rndGen); this.ReadAsTest <SerType_33>(rndGen); this.ReadAsTest <DCType_34>(rndGen); this.ReadAsTest <DCType_36>(rndGen); this.ReadAsTest <DCType_38>(rndGen); this.ReadAsTest <DCType_40>(rndGen); this.ReadAsTest <DCType_42>(rndGen); this.ReadAsTest <DCType_65>(rndGen); this.ReadAsTest <ListType_1>(rndGen); this.ReadAsTest <ListType_2>(rndGen); this.ReadAsTest <BaseType>(rndGen); this.ReadAsTest <PolymorphicMember>(rndGen); this.ReadAsTest <PolymorphicAsInterfaceMember>(rndGen); this.ReadAsTest <CollectionsWithPolymorphicMember>(rndGen); } finally { CreatorSettings.CreatorSurrogate = oldSurrogate; } }
public void CreateFromTests() { InstanceCreatorSurrogate oldSurrogate = CreatorSettings.CreatorSurrogate; try { CreatorSettings.CreatorSurrogate = new NoInfinityFloatSurrogate(); DateTime now = DateTime.Now; int seed = (10000 * now.Year) + (100 * now.Month) + now.Day; Log.Info("Seed: {0}", seed); Random rndGen = new Random(seed); foreach (Type testType in testTypes) { object instance = InstanceCreator.CreateInstanceOf(testType, rndGen); JsonValue jv = JsonValueExtensions.CreateFrom(instance); if (instance == null) { Assert.Null(jv); } else { DataContractJsonSerializer dcjs = new DataContractJsonSerializer(instance == null ? testType : instance.GetType()); string fromDCJS; using (MemoryStream ms = new MemoryStream()) { dcjs.WriteObject(ms, instance); fromDCJS = Encoding.UTF8.GetString(ms.ToArray()); } Log.Info("{0}: {1}", testType.Name, fromDCJS); if (instance == null) { Assert.Null(jv); } else { string fromJsonValue = jv.ToString(); Assert.Equal(fromDCJS, fromJsonValue); } } } } finally { CreatorSettings.CreatorSurrogate = oldSurrogate; } }