Exemple #1
0
        public void Get()
        {
            dynamic dyn = new Patchable <ToPatch>();

            dyn.Integer = 111;

            var delta = dyn as Patchable <ToPatch>;

            Assert.Equal(111, delta.Get <int>("Integer"));
        }
Exemple #2
0
        public void Cast()
        {
            dynamic dyn = new Patchable <ToPatch>();

            //dyn.Id = Guid.Parse("{7F27735C-FDE1-4141-985A-214502599C63}");
            dyn.Id = "{7F27735C-FDE1-4141-985A-214502599C63}";

            var delta = dyn as Patchable <ToPatch>;
            var id    = delta.Get <Guid>("Id");

            Assert.Equal(Guid.Parse("{7F27735C-FDE1-4141-985A-214502599C63}"), id);
        }
Exemple #3
0
        public void Indexer()
        {
            dynamic dyn = new Patchable <ToPatch>();

            dyn.Integer = 111;

            var delta = dyn as Patchable <ToPatch>;

            Assert.True(delta.Has("Integer"));
            Assert.False(delta.Has("Integer2"));
            Assert.Equal(111, delta.Get <int>("Integer"));
        }
Exemple #4
0
        public void Patch()
        {
            var toPatch = new ToPatch
            {
                Integer = 123,
                String  = "TEST"
            };
            dynamic dyn = new Patchable <ToPatch>();

            dyn.Integer = 111;

            dyn.Patch(toPatch);

            Assert.Equal(111, toPatch.Integer);
        }
Exemple #5
0
        public void NonExistingProperties()
        {
            Patchable <ToPatch> .NonExistingPropertiesMode = NonExistingPropertiesMode.NotAllowed;
            // Create a Patchable
            dynamic dyn = new Patchable <ToPatch>();

            // Set non existing property
            Assert.Throws <RuntimeBinderException>(() =>
            {
                dyn.Integer        = 123;
                dyn.DerivedInteger = 123;
            });
            Patchable <ToPatch> .NonExistingPropertiesMode = NonExistingPropertiesMode.OnlySet;
            dyn.Integer        = 123;
            dyn.DerivedInteger = 123;

            // Path a derived class
            var derived = new DerivedToPatch();

            (dyn as Patchable <ToPatch>).ToPatchable <DerivedToPatch>().Patch(derived);
            Assert.Equal(123, derived.Integer);
            Assert.Equal(123, derived.DerivedInteger);

            // Get non existing property
            var delta = dyn as Patchable <ToPatch>;
            int res, derivedRed;

            Assert.Throws <RuntimeBinderException>(() =>
            {
                res        = delta.Get <int>("Integer");
                derivedRed = delta.Get <int>("DerivedInteger");
            });
            Patchable <ToPatch> .NonExistingPropertiesMode = NonExistingPropertiesMode.GetAndSet;
            res        = delta.Get <int>("Integer");
            derivedRed = delta.Get <int>("DerivedInteger");

            Assert.Equal(123, res);
            Assert.Equal(123, derivedRed);
        }