public void WhenCombineLatest_AndSomeExistingValues_ShouldSubscribeToPropertyChanges()
        {
            // Arrange
            List <Tuple <bool, string, object> > tuples = new List <Tuple <bool, string, object> >();
            var vm = new MyObservableObject(false, null);

            vm.Something     = "Woot";
            vm.ADynamicValue = vm;

            Observable.CombineLatest(
                vm.WhenPropertyChanged(x => x.IsChecked),
                vm.WhenPropertyChanged(x => x.Something),
                vm.WhenPropertyChanged(x => x.ADynamicValue),
                Tuple.Create)
            .Throttle(TimeSpan.FromMilliseconds(100), _ctx.Default)
            .Subscribe(arg => tuples.Add(arg));

            // Act
            tuples.Clear();
            vm.IsChecked = true;

            Assert.That(tuples.Count, Is.EqualTo(1));
            Assert.That(tuples[0].Item1, Is.EqualTo(true));
            Assert.That(tuples[0].Item2, Is.EqualTo("Woot"));
            Assert.That(tuples[0].Item3, Is.EqualTo((object)vm));
        }
        public void ShouldSubscribeToPropertyChanges()
        {
            // Arrange
            bool   boolReceived      = false;
            string somethingReceived = null;
            var    vm = new MyObservableObject(false, null);

            vm.WhenPropertyChanged(x => x.IsChecked).Subscribe(arg => boolReceived      = arg);
            vm.WhenPropertyChanged(x => x.Something).Subscribe(arg => somethingReceived = arg);

            // Act
            vm.IsChecked = true;

            // Assert
            Assert.That(vm.IsChecked, Is.True);
            Assert.That(boolReceived, Is.True);
            Assert.That(somethingReceived, Is.Null);
        }
        public void ShouldSubscribeToPropertyChanges2()
        {
            // Arrange
            bool   boolReceived      = false;
            string somethingReceived = null;
            var    vm = new MyObservableObject(false, null);

            vm.WhenPropertyChanged(x => x.IsChecked).Subscribe(arg => boolReceived      = arg);
            vm.WhenPropertyChanged(x => x.Something).Subscribe(arg => somethingReceived = arg);

            // Act
            vm.Something = "Hello";
            vm.Something = "World";

            // Assert
            Assert.That(vm.IsChecked, Is.False);
            Assert.That(boolReceived, Is.False);
            Assert.That(somethingReceived, Is.EqualTo("World"));
        }
        public void WhenCombineLatest_ShouldSubscribeToPropertyChanges()
        {
            // Arrange
            List <Tuple <bool, string, object> > tuples = new List <Tuple <bool, string, object> >();
            var vm = new MyObservableObject(false, null);

            Observable.CombineLatest(
                vm.WhenPropertyChanged(x => x.IsChecked),
                vm.WhenPropertyChanged(x => x.Something),
                vm.WhenPropertyChanged(x => x.ADynamicValue),
                Tuple.Create)
            .Throttle(TimeSpan.FromMilliseconds(100), _ctx.Default)
            .Subscribe(arg => tuples.Add(arg));

            Assert.That(tuples.Contains(Tuple.Create(false, (string)null, (object)null)));

            // Act 1
            tuples.Clear();
            vm.IsChecked = true;
            Assert.That(tuples.Contains(Tuple.Create(true, (string)null, (object)null)));

            // Act 2
            tuples.Clear();
            vm.Something = "Woot";
            Assert.That(tuples.Contains(Tuple.Create(true, "Woot", (object)null)));

            // Act 3
            tuples.Clear();
            vm.ADynamicValue = vm;
            Assert.That(tuples.Contains(Tuple.Create(true, "Woot", (object)vm)));

            // Act 3
            tuples.Clear();
            vm.IsChecked = false;
            Assert.That(tuples.Contains(Tuple.Create(false, "Woot", (object)vm)));
        }
        public void ShouldDisposeWith()
        {
            // Arrange
            string somethingReceived = null;
            var    vm = new MyObservableObject(false, null);

            vm.WhenPropertyChanged(x => x.Something).Subscribe(arg => somethingReceived = arg).DisposeWith(vm);

            // Act
            vm.Something = "Hello";
            vm.Dispose();
            vm.Something = "World";

            // Assert
            Assert.That(vm.IsChecked, Is.False);
            Assert.That(somethingReceived, Is.EqualTo("Hello"));
        }
        public void ShouldFireObservableEventsOnDynamicValueSet()
        {
            // Arrange
            var           obj             = new MyObservableObject(false, null);
            List <object> objectsReceived = new List <object>();

            obj.WhenPropertyChanged(x => x.ADynamicValue).Subscribe(v => objectsReceived.Add(v));
            objectsReceived.Clear();

            // Act
            obj.SetDynamicValue <object>("ADynamicValue", 123);
            obj.ADynamicValue = "Testing";
            obj.SetDynamicValue <object>("ADynamicValue", "Dynamic");

            // Assert
            Assert.That(objectsReceived.Count, Is.EqualTo(3));
            Assert.That(objectsReceived, Is.EquivalentTo(new object[] { 123, "Testing", "Dynamic" }));
        }