public void Get_Binding_For_Property()
        {
            var subject = new BindingFixtureElement <int, string>(10, "test");
            var binding = subject.BindingFor(p => p.Property);

            using (var monitoredBinding = binding.Monitor <INotifyPropertyChanged>())
            {
                subject.Property = "Changed!";
                monitoredBinding.Should().RaisePropertyChange(binding, nameof(IReadOnlyObservableValue.Value));
                binding.Value.Should().Be("Changed!");
            }
        }
        public void Get_Binding_For_Property_With_FunctionCall()
        {
            var subject = new BindingFixtureElement <int, int>(10, 25);
            var binding = subject.BindingFor(p => (double)CallMe(p.Field));

            using (var monitoredBinding = binding.Monitor <INotifyPropertyChanged>())
            {
                subject.Field = 11;
                subject.OnPropertyChanged(nameof(subject.Field));
                monitoredBinding.Should().RaisePropertyChange(binding, nameof(IReadOnlyObservableValue.Value));
                binding.Value.Should().Be(12.0);
            }
        }
        public void Get_Binding_For_Field_With_Cast()
        {
            var subject = new BindingFixtureElement <int, string>(10, "test");
            var binding = subject.BindingFor(p => (double)p.Field);

            using (var monitoredBinding = binding.Monitor <INotifyPropertyChanged>())
            {
                subject.Field = 11;
                subject.OnPropertyChanged(nameof(subject.Field));
                monitoredBinding.Should().RaisePropertyChange(binding, nameof(IReadOnlyObservableValue.Value));
                binding.Value.Should().Be(11.0);
            }
        }
Esempio n. 4
0
        public void Create_From_Array()
        {
            var backend = new BindingFixtureElement <string[], List <string> >();
            var binding = backend.BindingFor(e => e.Field).ToListBinding();

            using (var monitoredBinding = binding.Monitor <INotifyCollectionChanged>())
            {
                backend.Field = new[] { "Test" };
                backend.OnPropertyChanged(nameof(backend.Field));

                monitoredBinding.Should()
                .RaiseCollectionChange(binding, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

                binding.Should().BeEquivalentTo("Test");
            }
        }
        public void Get_Binding_For_Property_With_MultiParamFunctionCall_Property_Must_Be_First_Argument()
        {
            // This demonstates that the binding name automation always selects the first member access it
            // comes across. I generally do not recommend relying on complex magic here.

            var subject = new BindingFixtureElement <int, int>(10, 25);
            var binding = subject.BindingFor(p => (double)CallMe(p.Property, p.Field));

            using (var monitoredBinding = binding.Monitor <INotifyPropertyChanged>())
            {
                subject.Field = 11;
                subject.OnPropertyChanged(nameof(subject.Field));

                // the binding will not react to field changes.
                monitoredBinding.Should().NotRaise(nameof(INotifyPropertyChanged.PropertyChanged));

                // the binding will react to changes to "property" instead, as this is the first
                // member access the parser encountered.
                subject.OnPropertyChanged(nameof(subject.Property));
                monitoredBinding.Should().RaisePropertyChange(binding, nameof(IReadOnlyObservableValue.Value));
            }
        }