@@ -8614,7 +8614,7 @@ public void TestImplementsNonGenericIEnumerableWithNoAdd_ProhibitEnumerableNonCo
86148614 [Test]
86158615 public void TestAsymmetric_PackOnly_NoSettableNoConstructors_Packable()
86168616 {
8617- TestAsymmetricPackOnlyCore(
8617+ this. TestAsymmetricPackOnlyCore(
86188618 () => new NoSettableNoConstructorsForAsymmetricTest().Initialize( "A" ),
86198619 SerializerCapabilities.PackTo,
86208620 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8624,7 +8624,7 @@ public void TestAsymmetric_PackOnly_NoSettableNoConstructors_Packable()
86248624 [Test]
86258625 public void TestAsymmetric_PackOnly_NoSettableMultipleConstructors_Packable()
86268626 {
8627- TestAsymmetricPackOnlyCore(
8627+ this. TestAsymmetricPackOnlyCore(
86288628 () => new NoSettableMultipleConstructorsForAsymmetricTest( "A", 0 ),
86298629 SerializerCapabilities.PackTo,
86308630 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8634,7 +8634,7 @@ public void TestAsymmetric_PackOnly_NoSettableMultipleConstructors_Packable()
86348634 [Test]
86358635 public void TestAsymmetric_PackOnly_NoDefaultConstructor_Packable()
86368636 {
8637- TestAsymmetricPackOnlyCore(
8637+ this. TestAsymmetricPackOnlyCore(
86388638 () => new NoDefaultConstructorForAsymmetricTest( 'A' ),
86398639 SerializerCapabilities.PackTo,
86408640 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8644,7 +8644,7 @@ public void TestAsymmetric_PackOnly_NoDefaultConstructor_Packable()
86448644 [Test]
86458645 public void TestAsymmetric_PackOnly_UnconstructableEnumerable_Packable()
86468646 {
8647- TestAsymmetricPackOnlyCore(
8647+ this. TestAsymmetricPackOnlyCore(
86488648 () => new UnconstructableEnumerableForAsymmetricTest( "A" ),
86498649 SerializerCapabilities.PackTo,
86508650 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8654,7 +8654,7 @@ public void TestAsymmetric_PackOnly_UnconstructableEnumerable_Packable()
86548654 [Test]
86558655 public void TestAsymmetric_PackOnly_UnconstructableCollection_Packable()
86568656 {
8657- TestAsymmetricPackOnlyCore(
8657+ this. TestAsymmetricPackOnlyCore(
86588658 () => new UnconstructableCollectionForAsymmetricTest( "A" ),
86598659 SerializerCapabilities.PackTo,
86608660 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8664,7 +8664,7 @@ public void TestAsymmetric_PackOnly_UnconstructableCollection_Packable()
86648664 [Test]
86658665 public void TestAsymmetric_PackOnly_UnconstructableList_Packable()
86668666 {
8667- TestAsymmetricPackOnlyCore(
8667+ this. TestAsymmetricPackOnlyCore(
86688668 () => new UnconstructableListForAsymmetricTest( "A" ),
86698669 SerializerCapabilities.PackTo,
86708670 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8674,7 +8674,7 @@ public void TestAsymmetric_PackOnly_UnconstructableList_Packable()
86748674 [Test]
86758675 public void TestAsymmetric_PackOnly_UnconstructableDictionary_Packable()
86768676 {
8677- TestAsymmetricPackOnlyCore(
8677+ this. TestAsymmetricPackOnlyCore(
86788678 () => new UnconstructableDictionaryForAsymmetricTest( new KeyValuePair<string, string>( "A", "A" ) ),
86798679 SerializerCapabilities.PackTo,
86808680 new byte[] { 0x81, 0xA1, ( byte )'A', 0xA1, ( byte )'A' }
@@ -8684,7 +8684,7 @@ public void TestAsymmetric_PackOnly_UnconstructableDictionary_Packable()
86848684 [Test]
86858685 public void TestAsymmetric_PackOnly_UnconstructableNonGenericEnumerable_Packable()
86868686 {
8687- TestAsymmetricPackOnlyCore(
8687+ this. TestAsymmetricPackOnlyCore(
86888688 () => new UnconstructableNonGenericEnumerableForAsymmetricTest( "A" ),
86898689 SerializerCapabilities.PackTo,
86908690 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8694,7 +8694,7 @@ public void TestAsymmetric_PackOnly_UnconstructableNonGenericEnumerable_Packable
86948694 [Test]
86958695 public void TestAsymmetric_PackOnly_UnconstructableNonGenericCollection_Packable()
86968696 {
8697- TestAsymmetricPackOnlyCore(
8697+ this. TestAsymmetricPackOnlyCore(
86988698 () => new UnconstructableNonGenericCollectionForAsymmetricTest( "A" ),
86998699 SerializerCapabilities.PackTo,
87008700 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8704,7 +8704,7 @@ public void TestAsymmetric_PackOnly_UnconstructableNonGenericCollection_Packable
87048704 [Test]
87058705 public void TestAsymmetric_PackOnly_UnconstructableNonGenericList_Packable()
87068706 {
8707- TestAsymmetricPackOnlyCore(
8707+ this. TestAsymmetricPackOnlyCore(
87088708 () => new UnconstructableNonGenericListForAsymmetricTest( "A" ),
87098709 SerializerCapabilities.PackTo,
87108710 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8714,7 +8714,7 @@ public void TestAsymmetric_PackOnly_UnconstructableNonGenericList_Packable()
87148714 [Test]
87158715 public void TestAsymmetric_PackOnly_UnconstructableNonGenericDictionary_Packable()
87168716 {
8717- TestAsymmetricPackOnlyCore(
8717+ this. TestAsymmetricPackOnlyCore(
87188718 () => new UnconstructableNonGenericDictionaryForAsymmetricTest( new DictionaryEntry( "A", "A" ) ),
87198719 SerializerCapabilities.PackTo,
87208720 new byte[] { 0x81, 0xA1, ( byte )'A', 0xA1, ( byte )'A' }
@@ -8724,7 +8724,7 @@ public void TestAsymmetric_PackOnly_UnconstructableNonGenericDictionary_Packable
87248724 [Test]
87258725 public void TestAsymmetric_PackOnly_UnappendableEnumerable_Packable()
87268726 {
8727- TestAsymmetricPackOnlyCore(
8727+ this. TestAsymmetricPackOnlyCore(
87288728 () => new UnappendableEnumerableForAsymmetricTest( "A" ),
87298729 SerializerCapabilities.PackTo,
87308730 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8734,7 +8734,7 @@ public void TestAsymmetric_PackOnly_UnappendableEnumerable_Packable()
87348734 [Test]
87358735 public void TestAsymmetric_PackOnly_UnappendableNonGenericEnumerable_Packable()
87368736 {
8737- TestAsymmetricPackOnlyCore(
8737+ this. TestAsymmetricPackOnlyCore(
87388738 () => new UnappendableNonGenericEnumerableForAsymmetricTest( "A" ),
87398739 SerializerCapabilities.PackTo,
87408740 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8744,7 +8744,7 @@ public void TestAsymmetric_PackOnly_UnappendableNonGenericEnumerable_Packable()
87448744 [Test]
87458745 public void TestAsymmetric_PackOnly_UnappendableNonGenericCollection_Packable()
87468746 {
8747- TestAsymmetricPackOnlyCore(
8747+ this. TestAsymmetricPackOnlyCore(
87488748 () => new UnappendableNonGenericCollectionForAsymmetricTest( "A" ),
87498749 SerializerCapabilities.PackTo,
87508750 new byte[] { 0x91, 0xA1, ( byte )'A' }
@@ -8755,41 +8755,57 @@ public void TestAsymmetric_PackOnly_UnappendableNonGenericCollection_Packable()
87558755 [Test]
87568756 public void TestAsymmetric_PackOnly_UnsettableArrayMemberObject_Packable()
87578757 {
8758- TestAsymmetricPackOnlyCore(
8758+ this. TestAsymmetricPackOnlyCore(
87598759 () => new UnsettableArrayMemberObjectForAsymmetricTest(),
87608760 SerializerCapabilities.PackTo,
87618761 new byte[] { 0x92, 0x91, 0xA1, ( byte )'A', 0x91, 0xA1, ( byte )'A' }
87628762 );
87638763 }
87648764
8765- private static void TestAsymmetricPackOnlyCore<T>( Func<T> factory, SerializerCapabilities expectedCapabilities, byte[] serialized )
8765+ private void TestAsymmetricPackOnlyCore<T>( Func<T> factory, SerializerCapabilities expectedCapabilities, byte[] serialized )
87668766 {
8767- var context = GetSerializationContext();
8768- context.CompatibilityOptions.AllowAsymmetricSerializer = true;
8769- context.CompatibilityOptions.AllowNonCollectionEnumerableTypes = false;
8770-
8771- var serializer = context.GetSerializer<T>();
8772- Assert.That( serializer.Capabilities, Is.EqualTo( expectedCapabilities ) );
8767+ this.TestAsymmetricPackOnlyCore( factory, expectedCapabilities, serialized, true );
8768+ this.TestAsymmetricPackOnlyCore( factory, expectedCapabilities, serialized, false );
8769+ }
87738770
8774- var obj = factory();
8775- using ( var buffer = new MemoryStream() )
8771+ private void TestAsymmetricPackOnlyCore<T>( Func<T> factory, SerializerCapabilities expectedCapabilities, byte[] serialized, bool avoidsGenericSerializer )
8772+ {
8773+ var previousAvoidsGenericSerializer = SerializerDebugging.AvoidsGenericSerializer;
8774+ SerializerDebugging.AvoidsGenericSerializer = avoidsGenericSerializer;
8775+ try
87768776 {
8777- if ( ( expectedCapabilities & SerializerCapabilities.PackTo ) != 0 )
8778- {
8779- serializer.Pack( buffer, obj );
8780- Assert.That( buffer.ToArray(), Is.EqualTo( serialized ), "{0} != {1}", BitConverter.ToString( buffer.ToArray() ), BitConverter.ToString( serialized ) );
8781- }
8782- else if ( ( expectedCapabilities & SerializerCapabilities.UnpackFrom ) != 0 )
8777+ var context = GetSerializationContext();
8778+ context.CompatibilityOptions.AllowAsymmetricSerializer = true;
8779+ context.CompatibilityOptions.AllowNonCollectionEnumerableTypes = false;
8780+
8781+ var serializer = this.CreateTarget<T>( context );
8782+ Assert.That( serializer.Capabilities, Is.EqualTo( expectedCapabilities ) );
8783+
8784+ var obj = factory();
8785+ using ( var buffer = new MemoryStream() )
87838786 {
8784- buffer.Write( serialized, 0, serialized.Length );
8785- buffer.Position = 0;
8786- var unpacked = serializer.Unpack( buffer );
8787- Assert.That( obj, Is.EqualTo( unpacked ) );
8787+ if ( ( expectedCapabilities & SerializerCapabilities.PackTo ) != 0 )
8788+ {
8789+ serializer.Pack( buffer, obj );
8790+ Assert.That( buffer.ToArray(), Is.EqualTo( serialized ), "{0} != {1}", BitConverter.ToString( buffer.ToArray() ), BitConverter.ToString( serialized ) );
8791+ }
8792+ else if ( ( expectedCapabilities & SerializerCapabilities.UnpackFrom ) != 0 )
8793+ {
8794+ buffer.Write( serialized, 0, serialized.Length );
8795+ buffer.Position = 0;
8796+ var unpacked = serializer.Unpack( buffer );
8797+ Assert.That( obj, Is.EqualTo( unpacked ) );
8798+ }
87888799 }
87898800 }
8801+ finally
8802+ {
8803+ SerializerDebugging.AvoidsGenericSerializer = previousAvoidsGenericSerializer;
8804+ }
87908805 }
87918806
87928807 #endregion -- Asymmetric --
8808+
87938809 #region -- Polymorphism --
87948810 #region ---- KnownType ----
87958811
0 commit comments