Beispiel #1
0
        public void AddTypedValue_AddsBothValueAndTypeToInfo()
        {
            // Arrange
            var expectedValue = new TestClass {
                Value = 1
            };
            var info = new SerializationInfo(expectedValue.GetType(), MockFormatterConverter());

            // Act
            info.AddTypedValue(nameof(TestClass), expectedValue);

            // Assert
            Assert.Equal(2, info.MemberCount);
            var actualValue = info.GetValue(nameof(TestClass), typeof(TestClass)) as TestClass;

            Assert.NotNull(actualValue);
            Assert.Equal(expectedValue, actualValue);
            Assert.Equal(expectedValue.Value, actualValue.Value);
            var actualType = info.GetValue(
                nameof(TestClass) + SerializationInfoExtensions.TypedValuePostfix,
                typeof(Type));

            Assert.NotNull(actualType);
            Assert.Equal(typeof(TestClass), actualType);
        }
Beispiel #2
0
        public void AddTypedValue_EmptyNameThrowsArgumentException()
        {
            // Arrange
            var info = new SerializationInfo(typeof(TestClass), MockFormatterConverter());

            // Assert
            Assert.Throws <ArgumentException>(() => {
                // Act
                info.AddTypedValue(string.Empty, null /* Null is perfectly fine here */);
            });
        }
Beispiel #3
0
        public void GetTypedValue_ReturnsCorrectlyTypedObject()
        {
            // Arrange
            var expectedValue = new TestClass {
                Value = 1
            };
            var info = new SerializationInfo(expectedValue.GetType(), MockFormatterConverter());

            info.AddTypedValue(nameof(TestClass), expectedValue);

            // Act
            var actual = info.GetTypedValue <TestClass>(nameof(TestClass));

            // Assert
            Assert.Equal(expectedValue.GetType(), actual.GetType());
        }
Beispiel #4
0
        public void AddTypedValue_TypeCanBeUsedToDeserializeTypedValue()
        {
            // Arrange
            var expectedValue = new TestClass {
                Value = 1
            };
            var info = new SerializationInfo(expectedValue.GetType(), MockFormatterConverter());

            info.AddTypedValue(nameof(TestClass), expectedValue);
            var actualType = info.GetValue(
                nameof(TestClass) + SerializationInfoExtensions.TypedValuePostfix,
                typeof(Type)) as Type;

            // Act
            var actualValue = info.GetValue(nameof(TestClass), actualType) as TestClass;

            // Assert
            Assert.NotNull(actualValue);
            Assert.Equal(expectedValue, actualValue);
            Assert.Equal(expectedValue.Value, actualValue.Value);
        }
 /// <summary>
 /// Object serialization method
 /// </summary>
 public override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddTypedValue(nameof(Generator), _generator);
 }
 /// <summary>
 /// Object serialization method
 /// </summary>
 public override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddTypedValue(nameof(Source), Source);
 }
Beispiel #7
0
 /// <summary>
 /// Object serialization method
 /// </summary>
 public override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("Dimensions", Dimensions, typeof(Size?));
     info.AddValue(nameof(Dependencies), _dependencies, _dependencies.GetType());
     info.AddTypedValue(nameof(BlendMode), BlendMode);
 }