Ejemplo n.º 1
0
        public void TestReadByAttribute()
        {
            const string        hexBuffer = "A16249640C"; // {"Id":12}
            ObjectWithCallbacks obj       = Helper.Read <ObjectWithCallbacks>(hexBuffer);

            Assert.NotNull(obj);
            Assert.True(obj.OnDeserializingCalled);
            Assert.True(obj.OnDeserializedCalled);
            Assert.False(obj.OnSerializingCalled);
            Assert.False(obj.OnSerializedCalled);
        }
Ejemplo n.º 2
0
        public void TestReadByAttribute()
        {
            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();

            const string        json = @"{""Id"":12}";
            ObjectWithCallbacks obj  = Helper.Read <ObjectWithCallbacks>(json, options);

            Assert.NotNull(obj);
            Assert.True(obj.OnDeserializingCalled);
            Assert.True(obj.OnDeserializedCalled);
            Assert.False(obj.OnSerializingCalled);
            Assert.False(obj.OnSerializedCalled);
        }
Ejemplo n.º 3
0
        public void TestReadByApi()
        {
            CborOptions options = new CborOptions();

            options.Registry.ObjectMappingRegistry.Register <ObjectWithCallbacks>(om =>
            {
                om.MapMember(o => o.Id);
                om.SetOnDeserializingMethod(o => o.OnDeserializing());
                om.SetOnDeserializedMethod(o => o.OnDeserialized());
            });

            const string        hexBuffer = "A16249640C"; // {"Id":12}
            ObjectWithCallbacks obj       = Helper.Read <ObjectWithCallbacks>(hexBuffer, options);

            Assert.NotNull(obj);
            Assert.True(obj.OnDeserializingCalled);
            Assert.True(obj.OnDeserializedCalled);
            Assert.False(obj.OnSerializingCalled);
            Assert.False(obj.OnSerializedCalled);
        }
Ejemplo n.º 4
0
        public void TestReadByApi()
        {
            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();
            options.GetObjectMappingRegistry().Register <ObjectWithCallbacks>(om =>
            {
                om.MapMember(o => o.Id);
                om.SetOnDeserializingMethod(o => o.OnDeserializing());
                om.SetOnDeserializedMethod(o => o.OnDeserialized());
            });

            const string        json = @"{""Id"":12}";
            ObjectWithCallbacks obj  = Helper.Read <ObjectWithCallbacks>(json, options);

            Assert.NotNull(obj);
            Assert.True(obj.OnDeserializingCalled);
            Assert.True(obj.OnDeserializedCalled);
            Assert.False(obj.OnSerializingCalled);
            Assert.False(obj.OnSerializedCalled);
        }