Beispiel #1
0
        public void Should_Get_Property_Value_From_Task()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var tcs    = new TaskCompletionSource <Class2>();
                var data   = new Class1(tcs.Task);
                var target = new ExpressionObserver(data, "Next^.Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                tcs.SetResult(new Class2("foo"));
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { "foo" }, result);
            }
        }
Beispiel #2
0
        public void Should_Get_Simple_Observable_Value()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var source = new BehaviorSubject <string>("foo");
                var data   = new { Foo = source };
                var target = new ExpressionObserver(data, "Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                source.OnNext("bar");
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { PerspexProperty.UnsetValue, "foo", "bar" }, result);
            }
        }
Beispiel #3
0
        public void Should_Not_Get_Task_Result_Without_Modifier_Char()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var tcs    = new TaskCompletionSource <string>();
                var data   = new { Foo = tcs.Task };
                var target = new ExpressionObserver(data, "Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                tcs.SetResult("foo");
                sync.ExecutePostedCallbacks();

                Assert.Equal(1, result.Count);
                Assert.IsType <Task <string> >(result[0]);
            }
        }
        public void Should_Not_Get_Observable_Value_Without_Modifier_Char()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var source = new BehaviorSubject <string>("foo");
                var data   = new { Foo = source };
                var target = new ExpressionObserver(data, "Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                source.OnNext("bar");
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { source }, result);

                GC.KeepAlive(data);
            }
        }
Beispiel #5
0
        public void Should_Get_Property_Value_From_Observable()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data   = new Class1();
                var target = new ExpressionObserver(data, "Next.Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                data.Next.OnNext(new Class2("foo"));
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { PerspexProperty.UnsetValue, "foo" }, result);

                sub.Dispose();
                Assert.Equal(0, data.SubscriptionCount);
            }
        }
        public void Should_Get_Property_Value_From_Observable_With_DataValidation_Enabled()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data   = new Class1();
                var target = new ExpressionObserver(data, "Next.Foo", true);
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                data.Next.OnNext(new Class2("foo"));
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { new BindingNotification("foo") }, result);

                sub.Dispose();
                Assert.Equal(0, data.PropertyChangedSubscriptionCount);
            }
        }
        public void Should_Get_Simple_Observable_Value_With_DataValidation_Enabled()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var source = new BehaviorSubject <string>("foo");
                var data   = new { Foo = source };
                var target = new ExpressionObserver(data, "Foo", true);
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                source.OnNext("bar");
                sync.ExecutePostedCallbacks();

                // What does it mean to have data validation on an observable? Without a use-case
                // it's hard to know what to do here so for the moment the value is returned.
                Assert.Equal(new[] { "foo", "bar" }, result);
            }
        }
Beispiel #8
0
        public void Should_Get_Simple_Observable_Value()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var source = new BehaviorSubject <string>("foo");
                var data   = new { Foo = source };
                var target = ExpressionObserver.Create(data, o => o.Foo.StreamBinding());
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                source.OnNext("bar");
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { "foo", "bar" }, result);

                GC.KeepAlive(data);
            }
        }
Beispiel #9
0
        public void Should_Work_With_Value_Type()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var source = new BehaviorSubject <int>(1);
                var data   = new { Foo = source };
                var target = ExpressionObserver.Create(data, o => o.Foo.StreamBinding());
                var result = new List <int>();

                var sub = target.Subscribe(x => result.Add((int)x));
                source.OnNext(42);
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { 1, 42 }, result);

                GC.KeepAlive(data);
            }
        }
        public void Should_Get_Simple_Task_Value_With_Data_DataValidation_Enabled()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var tcs    = new TaskCompletionSource <string>();
                var data   = new { Foo = tcs.Task };
                var target = new ExpressionObserver(data, "Foo", true);
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                tcs.SetResult("foo");
                sync.ExecutePostedCallbacks();

                // What does it mean to have data validation on a Task? Without a use-case it's
                // hard to know what to do here so for the moment the value is returned.
                Assert.Equal(new [] { "foo" }, result);
            }
        }
        public void Should_Not_Get_Task_Result_Without_StreamBinding()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var tcs    = new TaskCompletionSource <string>();
                var data   = new { Foo = tcs.Task };
                var target = ExpressionObserver.Create(data, o => o.Foo);
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                tcs.SetResult("foo");
                sync.ExecutePostedCallbacks();

                Assert.Single(result);
                Assert.IsType <Task <string> >(result[0]);

                GC.KeepAlive(data);
            }
        }
Beispiel #12
0
        public void Should_Get_Property_Value_From_Observable()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data   = new Class1();
                var target = ExpressionObserver.Create(data, o => o.Next.StreamBinding().Foo);
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                data.Next.OnNext(new Class2("foo"));
                sync.ExecutePostedCallbacks();

                Assert.Equal(new[] { "foo" }, result);

                sub.Dispose();
                Assert.Equal(0, data.PropertyChangedSubscriptionCount);

                GC.KeepAlive(data);
            }
        }
        public void Should_Return_BindingNotification_Error_For_Faulted_Task()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data   = new { Foo = TaskFromException(new NotSupportedException()) };
                var target = new ExpressionObserver(data, "Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));

                Assert.Equal(
                    new[]
                {
                    new BindingNotification(
                        new AggregateException(new NotSupportedException()),
                        BindingErrorType.Error)
                },
                    result);
            }
        }
Beispiel #14
0
        public void Should_Return_BindingNotification_If_Stream_Operator_Applied_To_Not_Supported_Type()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data   = new Class2("foo");
                var target = new ExpressionObserver(data, "Foo^", true);
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                sync.ExecutePostedCallbacks();

                Assert.Equal(
                    new[]
                {
                    new BindingNotification(
                        new MarkupBindingChainException("Stream operator applied to unsupported type", "Foo^", "Foo^"),
                        BindingErrorType.Error)
                },
                    result);

                sub.Dispose();
            }
        }
        public void Should_Return_BindingNotification_Error_On_Task_Exception()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var tcs    = new TaskCompletionSource <string>();
                var data   = new { Foo = tcs.Task };
                var target = new ExpressionObserver(data, "Foo");
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));
                tcs.SetException(new NotSupportedException());
                sync.ExecutePostedCallbacks();

                Assert.Equal(
                    new[]
                {
                    new BindingNotification(
                        new AggregateException(new NotSupportedException()),
                        BindingErrorType.Error)
                },
                    result);
            }
        }