Ejemplo n.º 1
0
        private static void TestNonCollectionCore(
            Action <NilImplicationTestTarget> adjuster,
            Action <Packer, MessagePackObject, MessagePackObject, MessagePackObject, MessagePackObject, MessagePackObject> packing,
            MessagePackObject?memberDefault            = null,
            MessagePackObject?nullButValueType         = null,
            MessagePackObject?nullAndNullableValueType = null,
            MessagePackObject?nullAndReferenceType     = null,
            MessagePackObject?prohibitReferenceType    = null
            )
        {
            using (var buffer = new MemoryStream())
                using (var packer = Packer.Create(buffer))
                {
                    var serializer = MessagePackSerializer.Create <NilImplicationTestTarget>(new SerializationContext());
                    var target     = new NilImplicationTestTarget();

                    if (adjuster != null)
                    {
                        adjuster(target);
                    }

                    packing(
                        packer,
                        memberDefault ?? target.MemberDefault,
                        nullButValueType ?? target.NullButValueType,
                        nullAndNullableValueType ?? (target.NullAndNullableValueType == null ? MessagePackObject.Nil : target.NullAndNullableValueType.Value),
                        nullAndReferenceType ?? target.NullAndReferenceType,
                        prohibitReferenceType ?? target.ProhibitReferenceType
                        );

                    buffer.Position = 0;

                    var result = serializer.Unpack(buffer);
                    Assert.That(result.MemberDefault, Is.EqualTo(target.MemberDefault));
                    Assert.That(result.NullButValueType, Is.EqualTo(target.NullButValueType));
                    Assert.That(result.NullAndNullableValueType, Is.EqualTo(target.NullAndNullableValueType));
                    Assert.That(result.NullAndReferenceType, Is.EqualTo(target.NullAndReferenceType));
                    Assert.That(result.ProhibitReferenceType, Is.EqualTo(target.ProhibitReferenceType));

                    var expectedBytes = buffer.ToArray();
                    using (var actual = new MemoryStream())
                    {
                        serializer.Pack(actual, target);
                    }
                }
        }
Ejemplo n.º 2
0
		private static void TestNonCollectionCore(
			Action<NilImplicationTestTarget> adjuster,
			Action<Packer, MessagePackObject, MessagePackObject, MessagePackObject, MessagePackObject, MessagePackObject> packing,
			MessagePackObject? memberDefault = null,
			MessagePackObject? nullButValueType = null,
			MessagePackObject? nullAndNullableValueType = null,
			MessagePackObject? nullAndReferenceType = null,
			MessagePackObject? prohibitReferenceType = null
		)
		{
			using ( var buffer = new MemoryStream() )
			using ( var packer = Packer.Create( buffer ) )
			{
				var serializer = MessagePackSerializer.Create<NilImplicationTestTarget>( new SerializationContext() );
				var target = new NilImplicationTestTarget();

				if ( adjuster != null )
				{
					adjuster( target );
				}

				packing(
					packer,
					memberDefault ?? target.MemberDefault,
					nullButValueType ?? target.NullButValueType,
					nullAndNullableValueType ?? ( target.NullAndNullableValueType == null ? MessagePackObject.Nil : target.NullAndNullableValueType.Value ),
					nullAndReferenceType ?? target.NullAndReferenceType,
					prohibitReferenceType ?? target.ProhibitReferenceType
				);

				buffer.Position = 0;

				var result = serializer.Unpack( buffer );
				Assert.That( result.MemberDefault, Is.EqualTo( target.MemberDefault ) );
				Assert.That( result.NullButValueType, Is.EqualTo( target.NullButValueType ) );
				Assert.That( result.NullAndNullableValueType, Is.EqualTo( target.NullAndNullableValueType ) );
				Assert.That( result.NullAndReferenceType, Is.EqualTo( target.NullAndReferenceType ) );
				Assert.That( result.ProhibitReferenceType, Is.EqualTo( target.ProhibitReferenceType ) );

				var expectedBytes = buffer.ToArray();
				using ( var actual = new MemoryStream() )
				{
					serializer.Pack( actual, target );
				}
			}
		}