Exemplo n.º 1
0
        public void Deserialize_Should_Deserialize_Given_Object()
        {
            var serializer = new Serializer(new SerializerOptions(
                                                preserveObjectReferences: HyperionSerializerSettings.Default.PreserveObjectReferences,
                                                versionTolerance: HyperionSerializerSettings.Default.VersionTolerance,
                                                ignoreISerializable: HyperionSerializerSettings.Default.IgnoreISerializable));

            HyperionSerializer hyperionSerializer = new HyperionSerializer();

            var user = new TestUser
            {
                Age  = 31,
                Id   = Guid.NewGuid(),
                Name = "Deniz"
            };

            using (var bodyStream = new MemoryStream())
            {
                serializer.Serialize(user, bodyStream);

                byte[] array = bodyStream.ToArray();

                object deserializedUser = hyperionSerializer.Deserialize(array, typeof(TestUser));

                var testUser = deserializedUser as TestUser;

                Assert.True(testUser != null);

                Assert.Equal(testUser.Name, user.Name);
                Assert.Equal(testUser.Age, user.Age);
                Assert.Equal(testUser.Id, user.Id);
            }
        }
Exemplo n.º 2
0
        public void Should_Serialize_Given_Object()
        {
            var serializer = new Serializer(new SerializerOptions(
                                                preserveObjectReferences: HyperionSerializerSettings.Default.PreserveObjectReferences,
                                                versionTolerance: HyperionSerializerSettings.Default.VersionTolerance,
                                                ignoreISerializable: true));

            var user = new TestUser
            {
                Age  = 31,
                Id   = Guid.NewGuid(),
                Name = "Deniz"
            };

            var hyperionSerializer = new HyperionSerializer(serializer);

            using (var bodyStream = new MemoryStream())
            {
                hyperionSerializer.Serialize("application/x-hyperion", user, bodyStream);

                bodyStream.Position = 0;

                var deserializedUser = serializer.Deserialize(bodyStream);

                var testUser = deserializedUser as TestUser;

                Assert.True(testUser != null);

                Assert.Equal(testUser.Name, user.Name);
                Assert.Equal(testUser.Age, user.Age);
                Assert.Equal(testUser.Id, user.Id);
            }
        }
Exemplo n.º 3
0
        public void Setup_disallow_unsafe_type_should_work(object dangerousObject, Type type)
        {
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, HyperionSerializerSettings.Default);
            var serialized = serializer.ToBinary(dangerousObject);

            serializer.Invoking(s => s.FromBinary(serialized, type)).Should().Throw <SerializationException>();
        }
Exemplo n.º 4
0
        public void Should_Return_True_If_Given_Mime_Is_Correct()
        {
            var hyperionDeserializer = new HyperionSerializer();

            var canDeserialize = hyperionDeserializer.CanSerialize("application/x-hyperion");

            Assert.True(canDeserialize);
        }
Exemplo n.º 5
0
        private void CheckDeserialize(object msg, string message)
        {
            Log.Info("testing " + message);
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys);
            var bytes      = serializer.ToBinary(msg);
            var restored   = serializer.FromBinary(bytes, msg.GetType());

            Assert.NotNull(restored);
        }
Exemplo n.º 6
0
        public void Test_deserialization()
        {
            //CoffeMakeFailedEvent
            var msg = new Akka.Actor.Status.Failure(new UndefinedCoffeMachineException());
            //var msg =
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys);
            var bytes      = serializer.ToBinary(msg);
            var restored   = serializer.FromBinary(bytes, msg.GetType());

            Assert.NotNull(restored);
        }
Exemplo n.º 7
0
        public SerializationBenchmarks()

        {
            var config = ConfigurationFactory.ParseString("akka.suppress-json-serializer-warning=true");
            var system = ActorSystem.Create("SerializationBenchmarks", config);

            MsgPackSerializer  = new MsgPackSerializer(system.AsInstanceOf <ExtendedActorSystem>());
            HyperionSerializer = new HyperionSerializer(
                system.AsInstanceOf <ExtendedActorSystem>(),
                new HyperionSerializerSettings(false, false, typeof(SimpleTypesProvider)));
            NewtonSoftJsonSerializer = new NewtonSoftJsonSerializer(system.AsInstanceOf <ExtendedActorSystem>());
        }
Exemplo n.º 8
0
        public void GetOpenGeneric_Should_Return_Type_Of_HyperionCacheItem()
        {
            HyperionSerializer hyperionSerializer = new HyperionSerializer();

            MethodInfo getOpenGeneric = hyperionSerializer.GetType().GetMethod("GetOpenGeneric", BindingFlags.Instance | BindingFlags.NonPublic);

            Assert.NotNull(getOpenGeneric);

            object openGenericItemType = getOpenGeneric.Invoke(hyperionSerializer, null);

            Assert.Equal(typeof(HyperionCacheItem <>), openGenericItemType);
        }
Exemplo n.º 9
0
        public static void HyperionBody <TModel>(this BrowserContext browserContext, TModel model, ISerializer serializer = null)
        {
            if (serializer == null)
            {
                serializer = new HyperionSerializer();
            }

            IBrowserContextValues browserContextValues = browserContext;

            browserContextValues.Body = new MemoryStream();
            serializer.Serialize("application/x-hyperion", model, browserContextValues.Body);
            browserContext.Header("Content-Type", "application/x-hyperion");
        }
Exemplo n.º 10
0
        public void Setup_surrogate_should_work()
        {
            var surrogated = new List <Foo>();
            var setup      = HyperionSerializerSetup.Empty
                             .WithSurrogates(new [] { Surrogate.Create <Foo, FooSurrogate>(
                                                          foo =>
                {
                    surrogated.Add(foo);
                    return(new FooSurrogate(foo.Bar + "."));
                },
                                                          surrogate => new Foo(surrogate.Bar)) });
            var settings   = setup.ApplySettings(HyperionSerializerSettings.Default);
            var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, settings);

            var expected     = new Foo("bar");
            var serialized   = serializer.ToBinary(expected);
            var deserialized = serializer.FromBinary <Foo>(serialized);

            deserialized.Bar.Should().Be("bar.");
            surrogated.Count.Should().Be(1);
            surrogated[0].Should().BeEquivalentTo(expected);
        }
Exemplo n.º 11
0
 public HyperionSerializerWrapper(ExtendedActorSystem system, HyperionSerializerSettings settings) : base(system)
 {
     _serializer = new HyperionSerializer(system, settings);
 }
Exemplo n.º 12
0
 public HyperionSerializerWrapper(ExtendedActorSystem system, Config config) : base(system)
 {
     _serializer = new HyperionSerializer(system, config);
 }