当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionObserver.Subscribe方法代码示例

本文整理汇总了C#中ExpressionObserver.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionObserver.Subscribe方法的具体用法?C# ExpressionObserver.Subscribe怎么用?C# ExpressionObserver.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionObserver的用法示例。


在下文中一共展示了ExpressionObserver.Subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_Set_Node_Target_To_Null_On_Unsubscribe

        public void Should_Set_Node_Target_To_Null_On_Unsubscribe()
        {
            var target = new ExpressionObserver(new { Foo = "foo" }, "Foo");
            var result = new List<object>();

            using (target.Subscribe(x => result.Add(x)))
            using (target.Subscribe(_ => { }))
            {
                Assert.NotNull(target.Node.Target);
            }

            Assert.Equal(new[] { "foo" }, result);
            Assert.Null(target.Node.Target);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:14,代码来源:ExpressionObserverTests_Lifetime.cs

示例2: Should_Unsubscribe_From_Update_Observable

        public void Should_Unsubscribe_From_Update_Observable()
        {
            var scheduler = new TestScheduler();
            var update = scheduler.CreateColdObservable<Unit>();
            var target = new ExpressionObserver(() => new { Foo = "foo" }, "Foo", update);
            var result = new List<object>();

            using (target.Subscribe(x => result.Add(x)))
            using (target.Subscribe(_ => { }))
            {
                scheduler.Start();
            }

            Assert.Equal(new[] { "foo" }, result);
            Assert.All(update.Subscriptions, x => Assert.NotEqual(Subscription.Infinite, x.Unsubscribe));
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:16,代码来源:ExpressionObserverTests_Lifetime.cs

示例3: Validation_Plugins_Send_Correct_Notifications

        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);
        }
开发者ID:mikel785,项目名称:Perspex,代码行数:34,代码来源:ExpressionObserverTests_DataValidation.cs

示例4: Should_Unsubscribe_From_Source_Observable

        public void Should_Unsubscribe_From_Source_Observable()
        {
            var scheduler = new TestScheduler();
            var source = scheduler.CreateColdObservable(
                OnNext(1, new { Foo = "foo" }));
            var target = new ExpressionObserver(source, "Foo");
            var result = new List<object>();

            using (target.Subscribe(x => result.Add(x)))
            using (target.Subscribe(_ => { }))
            {
                scheduler.Start();
            }

            Assert.Equal(new[] { AvaloniaProperty.UnsetValue, "foo" }, result);
            Assert.All(source.Subscriptions, x => Assert.NotEqual(Subscription.Infinite, x.Unsubscribe));
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:17,代码来源:ExpressionObserverTests_Lifetime.cs

示例5: Indei_Validation_Does_Not_Subscribe_When_DataValidatation_Not_Enabled

        public void Indei_Validation_Does_Not_Subscribe_When_DataValidatation_Not_Enabled()
        {
            var data = new IndeiTest { MustBePositive = 5 };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false);

            observer.Subscribe(_ => { });

            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
        }
开发者ID:mikel785,项目名称:Perspex,代码行数:9,代码来源:ExpressionObserverTests_DataValidation.cs

示例6: Disabled_Indei_Validation_Does_Not_Subscribe

        public void Disabled_Indei_Validation_Does_Not_Subscribe()
        {
            var data = new IndeiTest { MustBePositive = 5 };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false);

            observer.Subscribe(_ => { });

            Assert.Equal(0, data.SubscriptionCount);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:9,代码来源:ExpressionObserverTests_Validation.cs

示例7: Should_Get_Simple_Property_Value_Type

        public void Should_Get_Simple_Property_Value_Type()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            target.Subscribe(_ => { });

            Assert.Equal(typeof(string), target.ResultType);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:9,代码来源:ExpressionObserverTests_Property.cs

示例8: Enabled_Indei_Validation_Subscribes

        public void Enabled_Indei_Validation_Subscribes()
        {
            var data = new IndeiTest { MustBePositive = 5 };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var sub = observer.Subscribe(_ => { });

            Assert.Equal(1, data.ErrorsChangedSubscriptionCount);
            sub.Dispose();
            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
        }
开发者ID:mikel785,项目名称:Perspex,代码行数:10,代码来源:ExpressionObserverTests_DataValidation.cs

示例9: Should_Track_INCC_Add

        public void Should_Track_INCC_Add()
        {
            var data = new { Foo = new ObservableCollection<string> { "foo", "bar" } };
            var target = new ExpressionObserver(data, "Foo[2]");
            var result = new List<object>();

            var sub = target.Subscribe(x => result.Add(x));
            data.Foo.Add("baz");

            Assert.Equal(new[] { PerspexProperty.UnsetValue, "baz" }, result);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:11,代码来源:ExpressionObserverTests_Indexer.cs

示例10: Should_Complete_When_Source_Observable_Errors

        public void Should_Complete_When_Source_Observable_Errors()
        {
            var source = new BehaviorSubject<object>(1);
            var target = new ExpressionObserver(source, "Foo");
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);
            source.OnError(new Exception());

            Assert.True(completed);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:11,代码来源:ExpressionObserverTests_Lifetime.cs

示例11: Should_Complete_When_Update_Observable_Errors

        public void Should_Complete_When_Update_Observable_Errors()
        {
            var update = new Subject<Unit>();
            var target = new ExpressionObserver(() => 1, "Foo", update);
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);
            update.OnError(new Exception());

            Assert.True(completed);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:11,代码来源:ExpressionObserverTests_Lifetime.cs

示例12: Should_Set_Simple_Property_Value

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

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

            Assert.Equal("foo", data.Foo);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:12,代码来源:ExpressionObserverTests_SetValue.cs

示例13: Should_Set_Value_On_Simple_Property_Chain

        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");

            using (target.Subscribe(_ => { }))
            {
                target.SetValue("foo");
            }

            Assert.Equal("foo", data.Foo.Bar);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:12,代码来源:ExpressionObserverTests_SetValue.cs

示例14: Should_Get_Completed_Task_Value

        public void Should_Get_Completed_Task_Value()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data = new { Foo = Task.FromResult("foo") };
                var target = new ExpressionObserver(data, "Foo");
                var result = new List<object>();

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

                Assert.Equal(new object[] { "foo" }, result.ToArray());
            }
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:13,代码来源:ExpressionObserverTests_Task.cs

示例15: Should_Track_Simple_Property_Value

        public void Should_Track_Simple_Property_Value()
        {
            var data = new Class1();
            var target = new ExpressionObserver(data, "Foo");
            var result = new List<object>();

            var sub = target.Subscribe(x => result.Add(x));
            data.SetValue(Class1.FooProperty, "bar");

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

            sub.Dispose();
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:13,代码来源:ExpressionObserverTests_PerspexProperty.cs


注:本文中的ExpressionObserver.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。