UnitTests/BinarySerialisationVersioningTests.cs
/// <summary>
/// This is an extension to IgnoreFieldsInDataNotPresentOnDeserialisationType above that tests a fix that ensures that we don't call any deserialisation type converters for
/// fields that do not exist in the target type because this may result in an exception (the deserialisation type converter would not know what the destination type should
/// be because the destination field does not exist, without this information it is not possible for the type converter to do anything, which is why the summary comment on
/// the ConvertIfRequired states that it will not be called with a null 'targetType' reference)
/// </summary>
This is an extension to IgnoreFieldsInDataNotPresentOnDeserialisationType above that tests a fix that ensures that we don't call any deserialisation type converters for
fields that do not exist in the target type because this may result in an exception (the deserialisation type converter would not know what the destination type should
be because the destination field does not exist, without this information it is not possible for the type converter to do anything, which is why the summary comment on
the ConvertIfRequired states that it will not be called with a null 'targetType' reference)
This is an extension to IgnoreFieldsInDataNotPresentOnDeserialisationType above that tests a fix that ensures that we don ' t call any deserialisation type converters for fields that do not exist in the target type because this may result in an exception ( the deserialisation type converter would not know what the destination type should be because the destination field does not exist without this information it is not possible for the type converter to do anything which is why the summary comment on the ConvertIfRequired states that it will not be called with a null ' targetType ' reference )
[Fact]
		public static void IgnoreFieldsInDataNotPresentOnDeserialisationTypeWhenDeserialisationTypeConvertersUsed()
		{
			const string idFieldName = "Id";
			const string nameFieldName = "Name";
			var sourceType = ConstructType(
				GetModuleBuilder("DynamicAssemblyFor" + GetMyName(), new Version(1, 0)),
				"ClassWithIntId",
				new[]
				{
					Tuple.Create(idFieldName, typeof(int)),
					Tuple.Create(nameFieldName, typeof(string))
				}
			);
			var instance = Activator.CreateInstance(sourceType);
			var idFieldOnSource = sourceType.GetField(idFieldName);
			idFieldOnSource.SetValue(instance, 123);
			var serialisedData = BinarySerialisation.Serialise(instance);
			var destinationType = ConstructType(GetModuleBuilder("DynamicAssemblyFor" + GetMyName(), new Version(1, 0)), "ClassWithIntId", new[] { Tuple.Create(idFieldName, typeof(int)) });
			var clone = ResolveDynamicAssembliesWhilePerformingAction(
				() => Deserialise(serialisedData, destinationType, new[] { NullDeserialisationTypeConverter.Instance }),
				destinationType
			);
			var idFieldOnDestination = destinationType.GetField(idFieldName);
			Assert.Equal(123, idFieldOnDestination.GetValue(clone));
		}
[ Fact ] public static void IgnoreFieldsInDataNotPresentOnDeserialisationTypeWhenDeserialisationTypeConvertersUsed ( ) { const string idFieldName = " " ; const string nameFieldName = " " ; var sourceType = ConstructType ( GetModuleBuilder ( " " + GetMyName ( ) , new Version ( 1 , 0 ) ) , " " , new [ ] { Tuple . Create ( idFieldName , typeof ( int ) ) , Tuple . Create ( nameFieldName , typeof ( string ) ) } ) ; var instance = Activator . CreateInstance ( sourceType ) ; var idFieldOnSource = sourceType . GetField ( idFieldName ) ; idFieldOnSource . SetValue ( instance , 123 ) ; var serialisedData = BinarySerialisation . Serialise ( instance ) ; var destinationType = ConstructType ( GetModuleBuilder ( " " + GetMyName ( ) , new Version ( 1 , 0 ) ) , " " , new [ ] { Tuple . Create ( idFieldName , typeof ( int ) ) } ) ; var clone = ResolveDynamicAssembliesWhilePerformingAction ( ( ) => Deserialise ( serialisedData , destinationType , new [ ] { NullDeserialisationTypeConverter . Instance } ) , destinationType ) ; var idFieldOnDestination = destinationType . GetField ( idFieldName ) ; Assert . Equal ( 123 , idFieldOnDestination . GetValue ( clone ) ) ; }
This is an extension to IgnoreFieldsInDataNotPresentOnDeserialisationType above that tests a fix that ensures that we don't call any deserialisation type converters for
fields that do not exist in the target type because this may result in an exception (the deserialisation type converter would not know what the destination type should
be because the destination field does not exist, without this information it is not possible for the type converter to do anything, which is why the summary comment on
the ConvertIfRequired states that it will not be called with a null 'targetType' reference)
This is an extension to IgnoreFieldsInDataNotPresentOnDeserialisationType above that tests a fix that ensures that we don ' t call any deserialisation type converters for fields that do not exist in the target type because this may result in an exception ( the deserialisation type converter would not know what the destination type should be because the destination field does not exist without this information it is not possible for the type converter to do anything which is why the summary comment on the ConvertIfRequired states that it will not be called with a null ' targetType ' reference )