예제 #1
0
        public void SimpleNotifyPropertyTest()
        {
            var model = new TestModelBase();

            var counter = 0;

            model.SetChangedAction(x => x.NotifyProperty, () => counter++);

            // modify
            model.NotifyProperty = 1;
            Assert.AreEqual(counter, 1);

            // modify
            model.NotifyProperty += 2;
            Assert.AreEqual(counter, 2);

            // not modify
            model.NotifyProperty = 3;
            Assert.AreEqual(counter, 2);

            // modify other
            model.OtherNotifyProperty = 100;
            Assert.AreEqual(counter, 2);

            Assert.AreEqual(model.NotifyProperty, 3);
            Assert.AreEqual(model.OtherNotifyProperty, 100);
        }
예제 #2
0
        public void PatchDictionnaryAddKeyWithSlash()
        {
            var patchString = @"{ ""SubModels"": {""te/st"": {} } }";
            JsonMergePatchDocument <TestModelBase> patch = PatchBuilder.Build <TestModelBase>(patchString);
            TestModelBase patchedModel = patch.ApplyTo(GetTestModel());

            Assert.Equal("te/st", patchedModel.SubModels.First().Key);
        }
예제 #3
0
        public void CastingTest()
        {
            var model = new TestModelBase();

            Assert.IsTrue(model is TestModelBase);
            Assert.AreNotEqual(model as TestModelBase, null);
            Assert.AreNotEqual((TestModelBase)model, null);
        }
예제 #4
0
        public void VirtualNotNotifyPropertyTest()
        {
            var model = new TestModelBase();

            var counter = 0;

            model.SetChangedAction(x => x.VirtualNotNotifyProperty, () => counter++);

            model.VirtualNotNotifyProperty = 1;

            Assert.AreEqual(counter, 0);
        }
예제 #5
0
        static WeakReference CreateWeakRef()
        {
            var model = new TestModelBase();

            var counter = 0;

            model.SetChangedAction(x => x.NotifyProperty, () => counter++);

            model.NotifyProperty = 1;
            Assert.AreEqual(counter, 1);

            return(new WeakReference(model));
        }
예제 #6
0
        public void MultyNoifyPropertyTest()
        {
            var model = new TestModelBase();

            var doubleCounter = 0;
            var otherCounter  = 0;

            model.SetChangedAction(x => x.MultyNotifyProperty, () => doubleCounter++);
            model.SetChangedAction(x => x.OtherNotifyProperty, () => otherCounter++);

            model.MultyNotifyProperty = 1;

            Assert.AreEqual(doubleCounter, 1);
            Assert.AreEqual(otherCounter, 1);
        }
예제 #7
0
        public void RefletionTest()
        {
            var model = new TestModelBase();

            var counter = 0;

            model.SetChangedAction(x => x.NotifyProperty, () => counter++);

            Assert.DoesNotThrow(() =>
            {
                var prop = model.GetType().GetProperty("NotifyProperty");
                prop.SetValue(model, 1, null);
            });

            Assert.AreEqual(counter, 1);
        }
예제 #8
0
        public void DefaultPrecisionFloatNoifyPropertyTest()
        {
            var model = new TestModelBase();

            var counter = 0;

            model.SetChangedAction(x => x.FloatNotifyProperty, () => counter++);

            model.FloatNotifyProperty = 1;
            Assert.AreEqual(counter, 1);

            // very small number
            model.FloatNotifyProperty += 1e-9f;
            Assert.AreEqual(counter, 1);

            model.FloatNotifyProperty += 1e-7f;
            Assert.AreEqual(counter, 2);
        }