Inheritance: FileSystemItem
        private static void TestCore(EmitterFlavor emittingFlavor, SerializationMethod serializationMethod, Func <SerializationContext, SerializerBuilder <DirectoryItem> > builderProvider)
        {
            var root = new DirectoryItem()
            {
                Name = "/"
            };

            root.Directories =
                new[]
            {
                new DirectoryItem()
                {
                    Name = "tmp/"
                },
                new DirectoryItem()
                {
                    Name        = "var/",
                    Directories = new DirectoryItem[0],
                    Files       = new [] { new FileItem()
                                           {
                                               Name = "system.log"
                                           } }
                }
            };
            root.Files = new FileItem[0];

            var serializer = new AutoMessagePackSerializer <DirectoryItem>(new SerializationContext()
            {
                EmitterFlavor = emittingFlavor, SerializationMethod = serializationMethod, GeneratorOption = SerializationMethodGeneratorOption.CanDump
            }, builderProvider);

            using (var memoryStream = new MemoryStream())
            {
                serializer.Pack(memoryStream, root);

                memoryStream.Position = 0;
                var result = serializer.Unpack(memoryStream);
                Assert.That(result.Name, Is.EqualTo("/"));
                Assert.That(result.Files, Is.Not.Null.And.Empty);
                Assert.That(result.Directories, Is.Not.Null.And.Length.EqualTo(2));
                Assert.That(result.Directories[0], Is.Not.Null);
                Assert.That(result.Directories[0].Name, Is.EqualTo("tmp/"));
                Assert.That(result.Directories[0].Files, Is.Null);
                Assert.That(result.Directories[0].Directories, Is.Null);
                Assert.That(result.Directories[1], Is.Not.Null);
                Assert.That(result.Directories[1].Name, Is.EqualTo("var/"));
                Assert.That(result.Directories[1].Files, Is.Not.Null.And.Length.EqualTo(1));
                Assert.That(result.Directories[1].Files[0], Is.Not.Null);
                Assert.That(result.Directories[1].Files[0].Name, Is.EqualTo("system.log"));
                Assert.That(result.Directories[1].Directories, Is.Not.Null.And.Empty);
            }
        }
Example #2
0
        private static void TestCore(EmitterFlavor emittingFlavor, SerializationMethod serializationMethod, ISerializerBuilder <DirectoryItem> generator)
        {
            var root = new DirectoryItem()
            {
                Name = "/"
            };

            root.Directories =
                new[]
            {
                new DirectoryItem()
                {
                    Name = "tmp/"
                },
                new DirectoryItem()
                {
                    Name        = "var/",
                    Directories = new DirectoryItem[0],
                    Files       = new [] { new FileItem()
                                           {
                                               Name = "system.log"
                                           } }
                }
            };
            root.Files = new FileItem[0];

            var serializer =
                new AutoMessagePackSerializer <DirectoryItem>(
                    new SerializationContext
            {
                EmitterFlavor       = emittingFlavor,
                SerializationMethod = serializationMethod,
#if SILVERLIGHT
                GeneratorOption = SerializationMethodGeneratorOption.Fast
#else
                GeneratorOption = SerializationMethodGeneratorOption.CanDump
#endif
            },
Example #3
0
		private static void TestCore( EmitterFlavor emittingFlavor, Func<SerializationContext, SerializerBuilder<DirectoryItem>> builderProvider )
		{
			var root = new DirectoryItem() { Name = "/" };
			root.Directories =
				new[]
				{
					new DirectoryItem() { Name = "tmp/" },
					new DirectoryItem() 
					{ 
						Name = "var/", 
						Directories = new DirectoryItem[ 0 ], 
						Files = new []{ new FileItem(){ Name = "system.log" } }
					}
				};
			root.Files = new FileItem[ 0 ];

			var serializer = new AutoMessagePackSerializer<DirectoryItem>( new SerializationContext() { EmitterFlavor = emittingFlavor, GeneratorOption = SerializationMethodGeneratorOption.CanDump }, builderProvider );
			using ( var memoryStream = new MemoryStream() )
			{
				serializer.Pack( memoryStream, root );

				memoryStream.Position = 0;
				var result = serializer.Unpack( memoryStream );
				Assert.That( result.Name, Is.EqualTo( "/" ) );
				Assert.That( result.Files, Is.Not.Null.And.Empty );
				Assert.That( result.Directories, Is.Not.Null.And.Length.EqualTo( 2 ) );
				Assert.That( result.Directories[ 0 ], Is.Not.Null );
				Assert.That( result.Directories[ 0 ].Name, Is.EqualTo( "tmp/" ) );
				Assert.That( result.Directories[ 0 ].Files, Is.Null );
				Assert.That( result.Directories[ 0 ].Directories, Is.Null );
				Assert.That( result.Directories[ 1 ], Is.Not.Null );
				Assert.That( result.Directories[ 1 ].Name, Is.EqualTo( "var/" ) );
				Assert.That( result.Directories[ 1 ].Files, Is.Not.Null.And.Length.EqualTo( 1 ) );
				Assert.That( result.Directories[ 1 ].Files[ 0 ], Is.Not.Null );
				Assert.That( result.Directories[ 1 ].Files[ 0 ].Name, Is.EqualTo( "system.log" ) );
				Assert.That( result.Directories[ 1 ].Directories, Is.Not.Null.And.Empty );
			}
		}
Example #4
0
        private static void TestCore(EmitterFlavor emittingFlavor, SerializationMethod serializationMethod, ISerializerBuilder generator)
        {
            var root = new DirectoryItem()
            {
                Name = "/"
            };

            root.Directories =
                new[]
            {
                new DirectoryItem()
                {
                    Name = "tmp/"
                },
                new DirectoryItem()
                {
                    Name        = "var/",
                    Directories = new DirectoryItem[0],
                    Files       = new [] { new FileItem()
                                           {
                                               Name = "system.log"
                                           } }
                }
            };
            root.Files = new FileItem[0];

            var context =
                new SerializationContext
            {
                SerializationMethod = serializationMethod,
                SerializerOptions   =
                {
#if !NETSTANDARD1_3
                    GeneratorOption = SerializationMethodGeneratorOption.CanDump,
#endif // !NETSTANDARD1_3
                    EmitterFlavor   = emittingFlavor
                }
            };

            var serializer =
                (MessagePackSerializer <DirectoryItem>)generator.BuildSerializerInstance(
                    context,
                    typeof(DirectoryItem),
                    PolymorphismSchema.Default
                    );

            using (var memoryStream = new MemoryStream())
            {
                serializer.Pack(memoryStream, root);

                memoryStream.Position = 0;
                var result = serializer.Unpack(memoryStream);
                Assert.That(result.Name, Is.EqualTo("/"));
                Assert.That(result.Files, Is.Not.Null.And.Empty);
                Assert.That(result.Directories, Is.Not.Null.And.Length.EqualTo(2));
                Assert.That(result.Directories[0], Is.Not.Null);
                Assert.That(result.Directories[0].Name, Is.EqualTo("tmp/"));
                Assert.That(result.Directories[0].Files, Is.Null);
                Assert.That(result.Directories[0].Directories, Is.Null);
                Assert.That(result.Directories[1], Is.Not.Null);
                Assert.That(result.Directories[1].Name, Is.EqualTo("var/"));
                Assert.That(result.Directories[1].Files, Is.Not.Null.And.Length.EqualTo(1));
                Assert.That(result.Directories[1].Files[0], Is.Not.Null);
                Assert.That(result.Directories[1].Files[0].Name, Is.EqualTo("system.log"));
                Assert.That(result.Directories[1].Directories, Is.Not.Null.And.Empty);
            }
        }
Example #5
0
		private static void TestCore( EmitterFlavor emittingFlavor, SerializationMethod serializationMethod, ISerializerBuilder generator )
		{
			var root = new DirectoryItem() { Name = "/" };
			root.Directories =
				new[]
				{
					new DirectoryItem() { Name = "tmp/" },
					new DirectoryItem() 
					{ 
						Name = "var/", 
						Directories = new DirectoryItem[ 0 ], 
						Files = new []{ new FileItem(){ Name = "system.log" } }
					}
				};
			root.Files = new FileItem[ 0 ];

			var context =
				new SerializationContext
				{
					SerializationMethod = serializationMethod,
					SerializerOptions =
					{
						GeneratorOption = SerializationMethodGeneratorOption.CanDump,
						EmitterFlavor = emittingFlavor
					}
				};

			var serializer =
				( MessagePackSerializer<DirectoryItem> ) generator.BuildSerializerInstance(
					context,
					typeof( DirectoryItem ),
					PolymorphismSchema.Default
				);
			using ( var memoryStream = new MemoryStream() )
			{
				serializer.Pack( memoryStream, root );

				memoryStream.Position = 0;
				var result = serializer.Unpack( memoryStream );
				Assert.That( result.Name, Is.EqualTo( "/" ) );
				Assert.That( result.Files, Is.Not.Null.And.Empty );
				Assert.That( result.Directories, Is.Not.Null.And.Length.EqualTo( 2 ) );
				Assert.That( result.Directories[ 0 ], Is.Not.Null );
				Assert.That( result.Directories[ 0 ].Name, Is.EqualTo( "tmp/" ) );
				Assert.That( result.Directories[ 0 ].Files, Is.Null );
				Assert.That( result.Directories[ 0 ].Directories, Is.Null );
				Assert.That( result.Directories[ 1 ], Is.Not.Null );
				Assert.That( result.Directories[ 1 ].Name, Is.EqualTo( "var/" ) );
				Assert.That( result.Directories[ 1 ].Files, Is.Not.Null.And.Length.EqualTo( 1 ) );
				Assert.That( result.Directories[ 1 ].Files[ 0 ], Is.Not.Null );
				Assert.That( result.Directories[ 1 ].Files[ 0 ].Name, Is.EqualTo( "system.log" ) );
				Assert.That( result.Directories[ 1 ].Directories, Is.Not.Null.And.Empty );
			}
		}