예제 #1
0
        public void Setup()
        {
            serializer      = mockSerializer.Object;
            serializerCache = mockSerializerCache.Object;
            packageFactory  = mockPackageFactory.Object;

            package = new DataPackage <string>(new GuidPackageId(), obj);

            mockPackageFactory
            .Setup(m => m.Pack(It.IsAny <object>()))
            .Returns(package);

            mockPackageFactory
            .Setup(m => m.Unpack(It.IsAny <Package>()))
            .Returns(obj);

            mockSerializer
            .Setup(m => m.Descriptor)
            .Returns(dotNetSerializer.Descriptor);

            mockSerializer
            .Setup(m => m.Serialize(It.IsAny <Package>()))
            .Returns <Package>(p => dotNetSerializer.Serialize(p));

            mockSerializer
            .Setup(m => m.Serialize(It.IsAny <object>(), It.IsAny <int>()))
            .Returns <Package, int>((obj, offset) => dotNetSerializer.Serialize(obj, offset));

            mockSerializer
            .Setup(m => m.Deserialize <Package>(It.IsAny <byte[]>()))
            .Returns <byte[]>(d => dotNetSerializer.Deserialize <Package>(d));

            mockSerializer
            .Setup(m => m.Deserialize <Package>(It.IsAny <byte[]>(), It.IsAny <int>()))
            .Returns <byte[], int>((data, offset) => dotNetSerializer.Deserialize <Package>(data, offset));

            mockSerializerCache
            .Setup(m => m.DefaultSerializer)
            .Returns(serializer);
        }
예제 #2
0
        public void Deserialize_WithStringDataZeroOffset_ReproducesString()
        {
            // Arrange
            var serializer = new DotNetSerializer();
            var str        = "Some string";
            var data       = serializer.Serialize(str);

            // Act
            var deserializedStr = serializer.Deserialize <string>(data, 0);

            // Assert
            Assert.AreEqual(str, deserializedStr);
        }
예제 #3
0
        public void Deserialize_WithStringData_ReproducesString()
        {
            // Arrange
            var serializer = new DotNetSerializer();
            var str        = "Some string";
            var bytes      = serializer.Serialize(str);

            // Act
            var deserializedStr = serializer.Deserialize <string>(bytes);

            // Assert
            Assert.That(deserializedStr, Is.EqualTo(str));
        }
예제 #4
0
        public void Deserialize_WithStringDataOffset_ReproducesString()
        {
            // Arrange
            var serializer = new DotNetSerializer();
            var str        = "Some string";
            var offset     = (new Random()).Next(100);
            var data       = serializer.Serialize(str, offset);

            // Act
            var deserialized = serializer.Deserialize <string>(data, offset);

            // Assert
            Assert.AreEqual(str, deserialized);
        }