Exemple #1
0
        public void ILSerializer_SerializesStructWithHooks()
        {
            var input = new SimpleISerializableStruct
            {
                Payload = "pyjamas"
            };

            // Verify that our behavior conforms to our expected behavior.
            var result = SerializerLoop(input);

            Assert.Equal(
                new[]
            {
                "deserializing",
                "deserialized",
                "deserialization"
            },
                result.History);
            Assert.Equal(input.Payload, result.Payload, StringComparer.Ordinal);
            Assert.Equal(2, result.Contexts.Count);
            Assert.All(result.Contexts, ctx => Assert.True(ctx.Context is IDeserializationContext));

            // Verify that our behavior conforms to the behavior of BinaryFormatter.
            var input2 = new SimpleISerializableStruct
            {
                Payload = "pyjamas"
            };

            var result2 = (SimpleISerializableStruct)BuiltInSerializerTests.DotNetSerializationLoop(
                input2,
                this.fixture.SerializationManager);

            Assert.Equal(input2.History, input.History);
            Assert.Equal(result2.History, result.History);
        }
Exemple #2
0
        public void DotNetSerializableSerializerSerializesObjectWithCallbacks()
        {
            var input = new SimpleISerializableObject
            {
                Payload = "pyjamas"
            };

            // Verify that our behavior conforms to our expected behavior.
            var result = (SimpleISerializableObject)BuiltInSerializerTests.OrleansSerializationLoop(this.environment.SerializationManager, input);

            Assert.Equal(
                new[]
            {
                "default_ctor",
                "serializing",
                "serialized"
            },
                input.History);
            Assert.Equal(3, input.Contexts.Count);
            Assert.All(input.Contexts, ctx => Assert.True(ctx.Context is ICopyContext || ctx.Context is ISerializationContext));

            Assert.Equal(
                new[]
            {
                "deserializing",
                "serialization_ctor",
                "deserialized",
                "deserialization"
            },
                result.History);
            Assert.Equal(input.Payload, result.Payload, StringComparer.Ordinal);
            Assert.Equal(3, result.Contexts.Count);
            Assert.All(result.Contexts, ctx => Assert.True(ctx.Context is IDeserializationContext));
        }