コード例 #1
0
        public void GetObjectData_of_generic_result_adds_object_in_context_when_success_result()
        {
            SerializationTestObject language = new SerializationTestObject {
                Number = 232, String = "C#"
            };
            Result <SerializationTestObject> okResult = Result.Ok(language);
            ISerializable serializableObject          = okResult;

            var serializationInfo = new SerializationInfo(typeof(Result), new FormatterConverter());

            serializableObject.GetObjectData(serializationInfo, new StreamingContext());

            serializationInfo.GetValue(nameof(Result <SerializationTestObject> .Value), typeof(SerializationTestObject))
            .Should().Be(language);
        }
コード例 #2
0
        public void GetObjectData_adds_error_object_in_serialization_context_when_failure_result()
        {
            SerializationTestObject errorObject = new SerializationTestObject {
                Number = 500, String = "Error message"
            };
            Result <object, SerializationTestObject> failResult = Result.Fail <object, SerializationTestObject>(errorObject);
            ISerializable serializableObject = failResult;

            var serializationInfo = new SerializationInfo(typeof(Result), new FormatterConverter());

            serializableObject.GetObjectData(serializationInfo, new StreamingContext());

            serializationInfo
            .GetValue(nameof(Result <object, SerializationTestObject> .Error), typeof(SerializationTestObject))
            .Should().Be(errorObject);
        }