Exemplo n.º 1
0
        public void InitialValue()
        {
            var property = new ManuallyRecalculatedProperty <int>(Calculator);

            calculations.Should().Be(1, "only calculated once, when constructing property");
            property.Value.Should().Be(1);
        }
Exemplo n.º 2
0
        public void Recalculation()
        {
            var property = new ManuallyRecalculatedProperty <int>(Calculator);

            property.Value.Should().Be(1);
            property.Recalculate();
            property.Value.Should().Be(2);
        }
Exemplo n.º 3
0
        private void manuallyRecalculatedProperty()
        {
            var manuallyRecalculated = new ManuallyRecalculatedProperty <long>(() => DateTimeOffset.Now.ToUnixTimeMilliseconds());

            Console.WriteLine(manuallyRecalculated); // 1591651725420
            Thread.Sleep(1000);
            manuallyRecalculated.Recalculate();
            Console.WriteLine(manuallyRecalculated); // 1591651726420
        }
Exemplo n.º 4
0
        public void EventNotFiredWhenRecalculatingSameValue()
        {
            var property    = new ManuallyRecalculatedProperty <int>(() => 8);
            int eventsFired = 0;

            property.PropertyChanged += (sender, args) => eventsFired++;
            property.Recalculate();
            eventsFired.Should().Be(0, "value did not change, so no events should be fired");
        }
Exemplo n.º 5
0
        public void EventFiredWhenRecalculating()
        {
            var property    = new ManuallyRecalculatedProperty <int>(Calculator);
            int eventsFired = 0;

            property.PropertyChanged += (sender, args) => eventsFired++;
            property.Recalculate();
            eventsFired.Should().Be(1);
        }