public void TestChangedSynchronousOnUiThread()
        {
            TestChanger tc = new TestChanger(true);

            var threadId = Thread.CurrentThread.ManagedThreadId;

            bool startFirstChagne  = false;
            bool finishFirstchange = false;
            bool gotNestedChange   = false;

            PropertyChangedEventHandler hander = null;

            hander = (s, a) =>
            {
                bool testComplete = false;

                if (!startFirstChagne)
                {
                    startFirstChagne  = true;
                    tc.TestProp       = "again";
                    finishFirstchange = true;
                    if (!gotNestedChange)
                    {
                        Assert.Fail();
                        testComplete = true;
                    }
                }
                else if (!finishFirstchange)
                {
                    gotNestedChange = true;
                    Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId);
                    testComplete = true;
                }
                else
                {
                    Assert.Fail();
                    testComplete = true;
                }

                if (testComplete)
                {
                    tc.PropertyChanged -= hander;
                    TestComplete();
                }
            };

            tc.PropertyChanged += hander;

            ThreadPool.QueueUserWorkItem((s) =>
            {
                tc.TestProp = "123";
            },
                                         null
                                         );
        }
Exemplo n.º 2
0
        public void StatusChangedWontFireTwice()
        {
            var changr = new TestChanger();
            var countr = new TestCounter();

            var testC1 = new TestClass(changr, countr);
            var testC2 = new TestClass(changr, countr);

            changr.RaiseStatusChange();

            countr.CallCount.Should().Be(1);
        }
        public void TestFakeDependantProperty()
        {
            TestChanger tc = new TestChanger();

            bool gotDependantChange = false;

            tc.PropertyChanged += (s, a) =>
            {
                gotDependantChange |= a.PropertyName == "FakeDependentProp";
            };

            tc.NotifyFakeProperty("FakeProp");

            Assert.IsTrue(gotDependantChange);
        }
        public void TestChangedOnUIThread()
        {
            TestChanger tc = new TestChanger(false);

            bool gotChange = false;

            tc.PropertyChanged += (s, a) =>
            {
                gotChange = true;
            };

            tc.TestProp = "xyz";

            Assert.IsTrue(gotChange);
        }
        public void TestDependantProperty()
        {
            TestChanger tc = new TestChanger();

            bool gotDependantChange = false;

            tc.PropertyChanged += (s, a) =>
            {
                gotDependantChange |= a.PropertyName == "DependentProp";
            };

            tc.TestProp = "changed";

            Assert.IsTrue(gotDependantChange);
        }
        public void TestMultiDependantProperty()
        {
            TestChanger tc = new TestChanger();

            int notifyCount = 0;

            tc.PropertyChanged += (s, a) =>
            {
                if (a.PropertyName == "MultiDependentProp")
                {
                    notifyCount++;
                }
            };

            tc.TestProp  = "changed";
            tc.TestProp2 = "changed";

            Assert.AreEqual(2, notifyCount);
        }
        public void TestChangedOnNonUiThread()
        {
            TestChanger tc = new TestChanger(true);


            var threadId = Thread.CurrentThread.ManagedThreadId;

            PropertyChangedEventHandler handler = null;

            handler = (s, a) =>
            {
                Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId);

                tc.PropertyChanged -= handler;
                TestComplete();
            };

            tc.PropertyChanged += handler;

            ThreadPool.QueueUserWorkItem((s) =>
            {
                tc.TestProp = "123";
            }, null);
        }