public void Should_use_service_stack_to_deserialise_object_from_stream( ServiceStackJsonFormatter formatter, ClassWithAllTypes objectToSerialize, byte[] serializedObjectAsBytes, ClassWithAllTypes objectAfterDeserializing ) { "Given a ServiceStackJsonFormatter" .Given(() => formatter = new ServiceStackJsonFormatter()); "And an object to serialize" .And(() => objectToSerialize = ClassWithAllTypes.Create(1)); "And the object serialized to bytes using service stack directly" .And(() => { // use same configuration options as ServiceStackJsonFormatter for the ToJson call using (new ServiceStackJsonFormatter.ConfigurationScope()) { // as well as the same encoding var encoding = formatter.SupportedEncodings.Single(); serializedObjectAsBytes = encoding.GetBytes(objectToSerialize.ToJson()); } }); "When deserializing the serialized bytes using the formatter" .When(() => objectAfterDeserializing = formatter.Deserialize <ClassWithAllTypes>(serializedObjectAsBytes)); "Should result in the same object that was serialized" .Then(() => objectToSerialize.Should().Be(objectAfterDeserializing)); }
public void Should_use_service_stack_to_serialize_object_to_stream( ServiceStackJsonFormatter formatter, ClassWithAllTypes objectToSerialize, string expectedSerializedObject, string actualSerializedObject ) { "Given a ServiceStackJsonFormatter" .Given(() => formatter = new ServiceStackJsonFormatter()); "And an object to serialize" .And(() => objectToSerialize = ClassWithAllTypes.Create(1)); "And the object serialized using service stack directly" .And(() => { // use same configuration options as ServiceStackJsonFormatter for the ToJson call using (new ServiceStackJsonFormatter.ConfigurationScope()) { expectedSerializedObject = objectToSerialize.ToJson(); } }); "When serializing using the formatter" .When(() => actualSerializedObject = formatter.Serialize(objectToSerialize)); "Should result in the same serialized object" .Then(() => actualSerializedObject.Should().Be(expectedSerializedObject)); }
protected bool Equals(ClassWithAllTypes other) { return(CharValue == other.CharValue && ByteValue == other.ByteValue && SByteValue == other.SByteValue && ShortValue == other.ShortValue && UShortValue == other.UShortValue && IntValue == other.IntValue && UIntValue == other.UIntValue && LongValue == other.LongValue && ULongValue == other.ULongValue && FloatValue.Equals(other.FloatValue) && DoubleValue.Equals(other.DoubleValue) && DecimalValue == other.DecimalValue && DateTimeValue.Equals(other.DateTimeValue) && GuidValue.Equals(other.GuidValue) && StringValue.Equals(other.StringValue)); }