예제 #1
0
        public void Validation_Plugins_Send_Correct_Notifications()
        {
            var data     = new IndeiTest();
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var result   = new List <object>();

            observer.Subscribe(x => result.Add(x));
            observer.SetValue(5);
            observer.SetValue(-5);
            observer.SetValue("foo");
            observer.SetValue(5);

            Assert.Equal(new[]
            {
                new BindingNotification(0),

                // Value is notified twice as ErrorsChanged is always called by IndeiTest.
                new BindingNotification(5),
                new BindingNotification(5),

                // Value is first signalled without an error as validation hasn't been updated.
                new BindingNotification(-5),
                new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, -5),

                // Exception is thrown by trying to set value to "foo".
                new BindingNotification(
                    new ArgumentException("Object of type 'System.String' cannot be converted to type 'System.Int32'."),
                    BindingErrorType.DataValidationError),

                // Value is set then validation is updated.
                new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, 5),
                new BindingNotification(5),
            }, result);
        }
        public void Validation_Plugins_Send_Correct_Notifications()
        {
            var data = new IndeiTest();
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var result = new List<object>();

            observer.Subscribe(x => result.Add(x));
            observer.SetValue(5);
            observer.SetValue(-5);
            observer.SetValue("foo");
            observer.SetValue(5);

            Assert.Equal(new[]
            {
                new BindingNotification(0),

                // Value is notified twice as ErrorsChanged is always called by IndeiTest.
                new BindingNotification(5),
                new BindingNotification(5),

                // Value is first signalled without an error as validation hasn't been updated.
                new BindingNotification(-5),
                new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, -5),

                // Exception is thrown by trying to set value to "foo".
                new BindingNotification(
                    new ArgumentException("Object of type 'System.String' cannot be converted to type 'System.Int32'."),
                    BindingErrorType.DataValidationError),

                // Value is set then validation is updated.
                new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, 5),
                new BindingNotification(5),
            }, result);
        }
        public void SetValue_Should_Return_False_For_Missing_Object()
        {
            var data   = new Class1();
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.False(target.SetValue("baz"));
        }
        public void SetValue_Should_Throw()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "!Foo");

            Assert.Throws<NotSupportedException>(() => target.SetValue("bar"));
        }
        public void SetValue_Should_Return_False()
        {
            var data   = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "!Foo");

            Assert.False(target.SetValue("bar"));
        }
예제 #6
0
        public void Should_Set_Simple_Property_Value()
        {
            var data   = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            target.SetValue("bar");

            Assert.Equal("foo", data.Foo);
        }
        public void SetValue_Should_Return_False_For_Missing_Property()
        {
            var data = new Class1 {
                Next = new WithoutBar()
            };
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.False(target.SetValue("baz"));
        }
 public void Exception_Validation_Sends_ValidationUpdate()
 {
     var data = new ExceptionTest { MustBePositive = 5 };
     var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false);
     var validationMessageFound = false;
     observer.Where(o => o is IValidationStatus).Subscribe(_ => validationMessageFound = true);
     observer.SetValue(-5);
     Assert.True(validationMessageFound);
 }
        public void Should_Set_Value_On_Simple_Property_Chain()
        {
            var data = new Class1 { Foo = new Class2 { Bar = "bar" } };
            var target = new ExpressionObserver(data, "Foo.Bar");

            target.SetValue("foo");

            Assert.Equal("foo", data.Foo.Bar);
        }
        public void Should_Set_Simple_Property_Value()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            target.SetValue("bar");

            Assert.Equal("foo", data.Foo);
        }
        public void SetValue_Should_Throw_For_Wrong_Type()
        {
            var data = new Class1 {
                Foo = "foo"
            };
            var target = new ExpressionObserver(data, "Foo");

            Assert.Throws <ArgumentException>(() => target.SetValue(1.2));
        }
예제 #12
0
        public void SetValue_Should_Notify_New_Value_Without_Inpc()
        {
            var data   = new Class1();
            var target = new ExpressionObserver(data, "Bar");
            var result = new List <object>();

            target.Subscribe(x => result.Add(x));
            target.SetValue("bar");

            Assert.Equal(new[] { null, "bar" }, result);
        }
        public void SetValue_Should_Return_False_For_Invalid_Value()
        {
            var data   = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "!Foo");

            target.Subscribe(_ => { });

            Assert.False(target.SetValue("bar"));

            GC.KeepAlive(data);
        }
        public void Validation_Plugins_Send_Correct_Notifications()
        {
            var data     = new IndeiTest();
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var result   = new List <object>();

            var errmsg = string.Empty;

            try { typeof(IndeiTest).GetProperty(nameof(IndeiTest.MustBePositive)).SetValue(data, "foo"); }
            catch (Exception e) { errmsg = e.Message; }

            observer.Subscribe(x => result.Add(x));
            observer.SetValue(5);
            observer.SetValue(-5);
            observer.SetValue("foo");
            observer.SetValue(5);

            Assert.Equal(new[]
            {
                new BindingNotification(0),

                // Value is notified twice as ErrorsChanged is always called by IndeiTest.
                new BindingNotification(5),
                new BindingNotification(5),

                // Value is first signalled without an error as validation hasn't been updated.
                new BindingNotification(-5),
                new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, -5),

                // Exception is thrown by trying to set value to "foo".
                new BindingNotification(
                    new ArgumentException(errmsg),
                    BindingErrorType.DataValidationError),

                // Value is set then validation is updated.
                new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, 5),
                new BindingNotification(5),
            }, result);

            GC.KeepAlive(data);
        }
        public void Exception_Validation_Sends_ValidationUpdate()
        {
            var data = new ExceptionTest {
                MustBePositive = 5
            };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false);
            var validationMessageFound = false;

            observer.Where(o => o is IValidationStatus).Subscribe(_ => validationMessageFound = true);
            observer.SetValue(-5);
            Assert.True(validationMessageFound);
        }
        public void Should_Not_Try_To_Set_Value_On_Broken_Chain()
        {
            var data = new Class1 { Foo = new Class2 { Bar = "bar" } };
            var target = new ExpressionObserver(data, "Foo.Bar");

            // Ensure the ExpressionObserver's subscriptions are kept active.
            target.OfType<string>().Subscribe(x => { });

            data.Foo = null;

            Assert.False(target.SetValue("foo"));
        }
예제 #17
0
        public void SetValue_Should_Return_False_For_Missing_Object()
        {
            var data   = new Class1();
            var target = new ExpressionObserver(data, "Next.Bar");

            using (target.Subscribe(_ => { }))
            {
                Assert.False(target.SetValue("baz"));
            }

            GC.KeepAlive(data);
        }
        public void Should_SetArrayIndex()
        {
            var data   = new { Foo = new[] { "foo", "bar" } };
            var target = new ExpressionObserver(data, "Foo[1]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("baz"));
            }

            Assert.Equal("baz", data.Foo[1]);
        }
        public void SetValue_Should_Set_Property_At_The_End_Of_Chain()
        {
            var data = new Class1 {
                Next = new Class2 {
                    Bar = "bar"
                }
            };
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.True(target.SetValue("baz"));
            Assert.Equal("baz", ((Class2)data.Next).Bar);
        }
        public void Can_SetValue_For_Valid_Value()
        {
            var data = new Test {
                Foo = true
            };
            var target = new ExpressionObserver(data, "!Foo");

            target.Subscribe(_ => { });

            Assert.True(target.SetValue(true));

            Assert.False(data.Foo);
        }
예제 #21
0
        public void Should_Set_Value_On_Simple_Property_Chain()
        {
            var data = new Class1 {
                Foo = new Class2 {
                    Bar = "bar"
                }
            };
            var target = new ExpressionObserver(data, "Foo.Bar");

            target.SetValue("foo");

            Assert.Equal("foo", data.Foo.Bar);
        }
        public void Exception_Validation_Sends_DataValidationError()
        {
            var data = new ExceptionTest { MustBePositive = 5 };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var validationMessageFound = false;

            observer.OfType<BindingNotification>()
                .Where(x => x.ErrorType == BindingErrorType.DataValidationError)
                .Subscribe(_ => validationMessageFound = true);
            observer.SetValue(-5);

            Assert.True(validationMessageFound);
        }
예제 #23
0
        public void SetValue_Should_Set_Simple_Property_Value()
        {
            var data = new Class1 {
                Foo = "foo"
            };
            var target = new ExpressionObserver(data, "Foo");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar"));
            }

            Assert.Equal("bar", data.Foo);
        }
예제 #24
0
        public void Exception_Validation_Sends_DataValidationError()
        {
            var data = new ExceptionTest {
                MustBePositive = 5
            };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var validationMessageFound = false;

            observer.OfType <BindingNotification>()
            .Where(x => x.ErrorType == BindingErrorType.DataValidationError)
            .Subscribe(_ => validationMessageFound = true);
            observer.SetValue(-5);

            Assert.True(validationMessageFound);
        }
        public void Pushing_Null_To_RootObservable_Updates_Leaf_Node()
        {
            var data = new Class1 {
                Foo = new Class2 {
                    Bar = "bar"
                }
            };
            var rootObservable = new BehaviorSubject <Class1>(data);
            var target         = new ExpressionObserver(rootObservable, "Foo.Bar");

            target.Subscribe(_ => { });
            rootObservable.OnNext(null);
            target.SetValue("baz");

            Assert.Equal("bar", data.Foo.Bar);
        }
        public void Should_Set_NonIntegerIndexer()
        {
            var data = new { Foo = new NonIntegerIndexer() };

            data.Foo["foo"] = "bar";
            data.Foo["baz"] = "qux";

            var target = new ExpressionObserver(data, "Foo[foo]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar2"));
            }

            Assert.Equal("bar2", data.Foo["foo"]);
        }
예제 #27
0
        public void Should_Not_Try_To_Set_Value_On_Broken_Chain()
        {
            var data = new Class1 {
                Foo = new Class2 {
                    Bar = "bar"
                }
            };
            var target = new ExpressionObserver(data, "Foo.Bar");

            // Ensure the ExpressionObserver's subscriptions are kept active.
            target.OfType <string>().Subscribe(x => { });

            data.Foo = null;

            Assert.False(target.SetValue("foo"));
        }
        public void Doesnt_Send_DataValidationError_When_DataValidatation_Not_Enabled()
        {
            var data = new ExceptionTest {
                MustBePositive = 5
            };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false);
            var validationMessageFound = false;

            observer.OfType <BindingNotification>()
            .Where(x => x.ErrorType == BindingErrorType.DataValidationError)
            .Subscribe(_ => validationMessageFound = true);
            observer.SetValue(-5);

            Assert.False(validationMessageFound);

            GC.KeepAlive(data);
        }
예제 #29
0
        public void SetValue_Should_Set_Property_At_The_End_Of_Chain()
        {
            var data = new Class1 {
                Next = new Class2 {
                    Bar = "bar"
                }
            };
            var target = new ExpressionObserver(data, "Next.Bar");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("baz"));
            }

            Assert.Equal("baz", ((Class2)data.Next).Bar);

            GC.KeepAlive(data);
        }
        public void Should_Add_NewDictionaryEntry()
        {
            var data = new
            {
                Foo = new Dictionary <string, int>
                {
                    { "foo", 1 }
                }
            };

            var target = new ExpressionObserver(data, "Foo[bar]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue(4));
            }

            Assert.Equal(4, data.Foo["bar"]);
        }
        public void Should_Set_ExistingDictionaryEntry()
        {
            var data = new
            {
                Foo = new Dictionary <string, int>
                {
                    { "foo", 1 }
                }
            };

            var target = new ExpressionObserver(data, "Foo[foo]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue(4));
            }

            Assert.Equal(4, data.Foo["foo"]);

            GC.KeepAlive(data);
        }
        public void SetValue_Should_Notify_New_Value_Without_Inpc()
        {
            var data = new Class1();
            var target = new ExpressionObserver(data, "Bar");
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));
            target.SetValue("bar");

            Assert.Equal(new[] { null, "bar" }, result);
        }
        public void SetValue_Should_Set_Simple_Property_Value()
        {
            var data = new Class1 { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar"));
            }

            Assert.Equal("bar", data.Foo);
        }
        public void Should_Add_NewDictionaryEntry()
        {
            var data = new
            {
                Foo = new Dictionary<string, int>
                {
                    {"foo", 1 }
                }
            };
            
            var target = new ExpressionObserver(data, "Foo[bar]");
            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue(4));
            }

            Assert.Equal(4, data.Foo["bar"]);
        }
        public void Should_SetArrayIndex()
        {
            var data = new { Foo = new[] { "foo", "bar" } };
            var target = new ExpressionObserver(data, "Foo[1]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("baz"));
            }

            Assert.Equal("baz", data.Foo[1]);
        }
        public void SetValue_Should_Throw_For_Wrong_Type()
        {
            var data = new Class1 { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            Assert.Throws<ArgumentException>(() => target.SetValue(1.2));
        }
        public void Should_Set_NonIntegerIndexer()
        {
            var data = new { Foo = new NonIntegerIndexer() };
            data.Foo["foo"] = "bar";
            data.Foo["baz"] = "qux";

            var target = new ExpressionObserver(data, "Foo[foo]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar2"));
            }
            
            Assert.Equal("bar2", data.Foo["foo"]);
        }
        public void SetValue_Should_Return_False_For_Missing_Object()
        {
            var data = new Class1();
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.False(target.SetValue("baz"));
        }
        public void SetValue_Should_Return_False_For_Missing_Property()
        {
            var data = new Class1 { Next = new WithoutBar()};
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.False(target.SetValue("baz"));
        }
        public void SetValue_Should_Set_Property_At_The_End_Of_Chain()
        {
            var data = new Class1 { Next = new Class2 { Bar = "bar" } };
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.True(target.SetValue("baz"));
            Assert.Equal("baz", ((Class2)data.Next).Bar);
        }
        public void SetValue_Should_Return_False()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "!Foo");

            Assert.False(target.SetValue("bar"));
        }
        public void SetValue_Should_Throw()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "!Foo");

            Assert.Throws<NotSupportedException>(() => target.SetValue("bar"));
        }