public void BinSerial_TwoIdenticalChildsShouldBeSameInstance()
        {
            var parent = new ParentChildTestClass
            {
                Name = "parent"
            };

            var child = new ParentChildTestClass
            {
                Name   = "child",
                Father = parent,
                Mother = parent
            };

            Assert.AreSame(child.Father, child.Mother, "Precondition: Saved Father and Mother are same instance");

            var stream     = new MemoryStream();
            var settings   = new BinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = GetSut(settings);

            serializer.Serialize(child, stream);

            serializer      = GetSut(settings);
            stream.Position = 0;
            var loaded = serializer.Deserialize(stream) as ParentChildTestClass;

            Assert.AreSame(loaded.Father, loaded.Mother, "Loaded Father and Mother are same instance");
        }
示例#2
0
 /// <summary>
 ///     Binary serialization with custom settings
 /// </summary>
 /// <param name="settings"></param>
 public SharpSerializer(BinarySettings settings)
 {
     if (settings == null)
     {
         throw new ArgumentNullException(nameof(settings));
     }
     Initialize(settings);
 }
示例#3
0
        public void HelloWorldTest()
        {
            foreach (var testCase in GetHelloWorldTestCases())
            {
                // Binary SizeOptimized
                Serialize(testCase, GetSut());

                // Binary Burst
                var settings = new BinarySettings(BinarySerializationMode.Burst);
                Serialize(testCase, GetSut(settings));
            }
        }
示例#4
0
        public void BurstBinaryStream_SizeIsTooShort_throwsDeserializingException()
        {
            // Arrange
            var myArray  = new[] { "ala", "ma", null, "kota" };
            var settings = new BinarySettings(BinarySerializationMode.Burst);
            var sut      = GetSut(settings);

            // Act
            void Action() => Serialize(myArray, sut, ShortenData);

            // Assert
            Assert.Throws <DeserializingException>(Action);
        }
示例#5
0
        public void BurstBinaryStream_StreamIsCorrupted_ThrowsDeserializingException()
        {
            // Arrange
            var myArray  = new[] { "ala", "ma", null, "kota" };
            var settings = new BinarySettings(BinarySerializationMode.Burst);
            var sut      = GetSut(settings);

            // Act
            void Action() => Serialize(myArray, sut, ReplaceSomeBytesInData);

            // Assert
            Assert.Throws <DeserializingException>(Action);
        }
        public void BinSerial_ShouldSerializeGuid()
        {
            var parent = new ClassWithGuid
            {
                Guid = Guid.NewGuid()
            };

            var stream     = new MemoryStream();
            var settings   = new BinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = GetSut(settings);

            serializer.Serialize(parent, stream);


            serializer      = GetSut(settings);
            stream.Position = 0;
            var loaded = serializer.Deserialize(stream) as ClassWithGuid;

            Assert.AreEqual(parent.Guid, loaded.Guid, "same guid");
        }
示例#7
0
 private SharpSerializer GetSut(BinarySettings settings) => new SharpSerializer(settings);