Beispiel #1
0
        public void MutableValueShouldReturnValuePassedToConstructor()
        {
            var value            = new MutableValue <int>(10);
            var changedValues    = new List <int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }
Beispiel #2
0
        public void ObservableValueShouldNotChangeWhenSetToValueItAlreadyHas()
        {
            var value            = new MutableValue <int>(10);
            var changedValues    = new List <int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);
            value.SetValue(10);

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }
Beispiel #3
0
        public void ObservableValueShouldNotChangeWhenSetToValueThatFailsValidation()
        {
            var value            = new MutableValue <int>(10, v => v != 20);
            var changedValues    = new List <int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);

            Action setter = () => value.SetValue(20);

            setter.ShouldThrow <InvalidOperationException>();

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }