本文整理汇总了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);
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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();
}