Ejemplo n.º 1
0
        public void Custom_programmatic_SerializerWithStringManifest_should_work_with_base_class_binding()
        {
            var settings = SerializationSetup.Create(system =>
                                                     ImmutableHashSet <SerializerDetails> .Empty.Add(
                                                         new SerializerDetails(
                                                             alias: "custom",
                                                             serializer: new CustomManifestSerializer(system),
                                                             useFor: ImmutableHashSet <Type> .Empty.Add(typeof(MessageBase))))
                                                     );

            var setup = ActorSystemSetup.Create(settings);

            using (var system = ActorSystem.Create(nameof(CustomSerializerSpec), setup))
            {
                var firstMessage  = new FirstMessage("First message");
                var serialization = system.Serialization;
                var serializer    = (CustomManifestSerializer)serialization.FindSerializerFor(firstMessage);

                var serialized = serializer.ToBinary(firstMessage);
                var manifest   = serializer.Manifest(firstMessage);
                var deserializedFirstMessage = serializer.FromBinary(serialized, manifest);
                manifest.Should().Be(FirstMessage.Manifest);
                deserializedFirstMessage.Should().Be(firstMessage);

                var secondMessage = new SecondMessage("Second message");
                serialized = serializer.ToBinary(secondMessage);
                manifest   = serializer.Manifest(secondMessage);
                var deserializedSecondMessage = serializer.FromBinary(serialized, manifest);
                manifest.Should().Be(SecondMessage.Manifest);
                deserializedSecondMessage.Should().Be(secondMessage);
            }
        }
Ejemplo n.º 2
0
        public void Custom_SerializerWithStringManifest_should_work_with_base_class_binding()
        {
            var config = ConfigurationFactory.ParseString(@"
                akka.actor {
                    serializers {
                        custom = ""Akka.Tests.Serialization.CustomManifestSerializer, Akka.Tests""
                    }
                    serialization-bindings {
                        ""Akka.Tests.Serialization.MessageBase, Akka.Tests"" = custom
                    }
                    serialization-identifiers {
	                    ""Akka.Tests.Serialization.CustomManifestSerializer, Akka.Tests"" = 101
                    }
                }
            ");

            using (var system = ActorSystem.Create(nameof(CustomSerializerSpec), config))
            {
                var firstMessage  = new FirstMessage("First message");
                var serialization = system.Serialization;
                var serializer    = (CustomManifestSerializer)serialization.FindSerializerFor(firstMessage);

                var serialized = serializer.ToBinary(firstMessage);
                var manifest   = serializer.Manifest(firstMessage);
                var deserializedFirstMessage = serializer.FromBinary(serialized, manifest);
                manifest.Should().Be(FirstMessage.Manifest);
                deserializedFirstMessage.Should().Be(firstMessage);

                var secondMessage = new SecondMessage("Second message");
                serialized = serializer.ToBinary(secondMessage);
                manifest   = serializer.Manifest(secondMessage);
                var deserializedSecondMessage = serializer.FromBinary(serialized, manifest);
                manifest.Should().Be(SecondMessage.Manifest);
                deserializedSecondMessage.Should().Be(secondMessage);
            }
        }