Пример #1
0
        public void ParentPropertyUpdatesTriggerValueChangesInTentativeProperty()
        {
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            parent.Value = 2;
            tentativeProperty.Value.Should().Be(2);
        }
Пример #2
0
        public void SettingValueChangesPropertyValue()
        {
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.Value.Should().Be(1, "before setting");

            tentativeProperty.Value = 2;
            tentativeProperty.Value.Should().Be(2, "after setting");
        }
Пример #3
0
        public void SettingValueToSameValueDoesNotFireChangeEvents()
        {
            bool eventFired        = false;
            var  tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.PropertyChanged += delegate { eventFired = true; };

            tentativeProperty.Value = 1;
            eventFired.Should().BeFalse("value set to existing value");
        }
Пример #4
0
        public void SettingValueFiresChangeEvents()
        {
            bool eventFired        = false;
            var  tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.PropertyChanged += delegate { eventFired = true; };

            tentativeProperty.Value = 2;
            eventFired.Should().BeTrue();
        }
Пример #5
0
        public void ParentPropertyUpdatesTriggerChangeEventsInTentativeProperty()
        {
            bool eventTriggered    = false;
            var  tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.PropertyChanged += delegate { eventTriggered = true; };

            parent.Value = 2;
            eventTriggered.Should().BeTrue();
        }
Пример #6
0
        public Task SettingValueRevertsToParentValueAfterDuration()
        {
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.Value.Should().Be(1, "before setting temporary value");

            tentativeProperty.Value = 2;
            tentativeProperty.Value.Should().Be(2, "directly after setting temporary value");

            return(Task.Delay(longDuration).ContinueWith(task => tentativeProperty.Value.Should().Be(1, "after waiting temporary value to revert to parent value")));
        }
Пример #7
0
        private void tentativeProperty()
        {
            var backing   = new StoredProperty <int>(8);
            var tentative = new TentativeProperty <int>(backing, TimeSpan.FromMilliseconds(500));

            Console.WriteLine(tentative.Value); // 8
            backing.Value = 9;
            Console.WriteLine(tentative.Value); // 9
            tentative.Value = 10;
            backing.Value   = 11;
            Console.WriteLine(tentative.Value); // 10
            Thread.Sleep(1000);
            Console.WriteLine(tentative.Value); // 11
        }
Пример #8
0
        public void SettingSecondTemporaryValueExtendsDurationUntilValueReverts()
        {
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.Value.Should().Be(1, "before setting temporary value");

            tentativeProperty.Value = 2;
            Thread.Sleep(shortDuration * 0.8);
            tentativeProperty.Value = 3;
            Thread.Sleep(shortDuration * 0.8);
            tentativeProperty.Value.Should().Be(3, "should not have reverted because we set a tentative value recently");
            Thread.Sleep(shortDuration * 0.5);
            tentativeProperty.Value.Should().Be(1, "enough time has passed that the property should have reverted to its parent value");
        }
Пример #9
0
        public void SettingValueFiresEventsWhenReverting()
        {
            int eventsFired       = 0;
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.Value.Should().Be(1, "before setting temporary value");
            tentativeProperty.PropertyChanged += delegate { eventsFired++; };

            tentativeProperty.Value = 2;
            tentativeProperty.Value.Should().Be(2, "directly after setting temporary value");
            eventsFired.Should().Be(1, "changed once, to temporary value");

            Thread.Sleep(longDuration);
            eventsFired.Should().Be(2, "changed once, to and from temporary value");
            tentativeProperty.Value.Should().Be(1, "after waiting temporary value to revert to parent value");
        }
Пример #10
0
        public void DisposingPropertyCancelsReverts()
        {
            int eventsFired       = 0;
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.PropertyChanged += delegate { eventsFired++; };

            tentativeProperty.Value = 2;
            eventsFired.Should().Be(1, "one change event from explicitly setting value");
            // Thread.Sleep(shortDuration * 0.8);
            tentativeProperty.Dispose();

            Thread.Sleep(longDuration);
            tentativeProperty.Value.Should().Be(2, "value should not have reverted because we disposed the property because it could happen");
            eventsFired.Should().Be(1, "value should not have reverted because we disposed the property because it could happen");
        }
Пример #11
0
        public void SettingTemporaryValuesFiresEventsWhenReverting()
        {
            int eventsFired       = 0;
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.PropertyChanged += delegate { eventsFired++; };

            tentativeProperty.Value = 2;
            eventsFired.Should().Be(1, "after setting once");

            Thread.Sleep(shortDuration * 0.8);
            eventsFired.Should().Be(1, "has not yet reverted yet");

            tentativeProperty.Value = 3;
            Thread.Sleep(shortDuration * 0.8);
            eventsFired.Should().Be(2, "has been set a second time, but didn't revert yet");

            Thread.Sleep(shortDuration * 0.4);
            eventsFired.Should().Be(3, "should have reverted from second temporary value to parent value");
            tentativeProperty.Value.Should().Be(1, "value should have reverted");
        }
Пример #12
0
        public void InitialValueFromParent()
        {
            var tentativeProperty = new TentativeProperty <int>(parent, shortDuration);

            tentativeProperty.Value.Should().Be(1);
        }