public void Should_Complete_When_Activator_Completes() { var activator = new BehaviorSubject <bool>(false); var target = new ActivatedValue(activator, 1, string.Empty); var completed = false; target.Subscribe(_ => { }, () => completed = true); activator.OnCompleted(); Assert.True(completed); }
public void Should_Complete_When_Activator_Completes() { var activator = new BehaviorSubject<bool>(false); var target = new ActivatedValue(activator, 1, string.Empty); var completed = false; target.Subscribe(_ => { }, () => completed = true); activator.OnCompleted(); Assert.True(completed); }
public void Should_Error_When_Activator_Errors() { var activator = new BehaviorSubject <bool>(false); var target = new ActivatedValue(activator, 1, string.Empty); var error = new Exception(); var completed = false; target.Subscribe(_ => { }, x => completed = true); activator.OnError(error); Assert.True(completed); }
public void Should_Produce_Correct_Values() { var activator = new BehaviorSubject<bool>(false); var target = new ActivatedValue(activator, 1, string.Empty); var result = new List<object>(); target.Subscribe(x => result.Add(x)); activator.OnNext(true); activator.OnNext(false); Assert.Equal(new[] { AvaloniaProperty.UnsetValue, 1, AvaloniaProperty.UnsetValue }, result); }
public void Should_Produce_Correct_Values() { var activator = new BehaviorSubject <bool>(false); var target = new ActivatedValue(activator, 1, string.Empty); var result = new List <object>(); target.Subscribe(x => result.Add(x)); activator.OnNext(true); activator.OnNext(false); Assert.Equal(new[] { PerspexProperty.UnsetValue, 1, PerspexProperty.UnsetValue }, result); }
public void Should_Unsubscribe_From_Activator_When_All_Subscriptions_Disposed() { var scheduler = new TestScheduler(); var activator1 = scheduler.CreateColdObservable<bool>(); var activator2 = scheduler.CreateColdObservable<bool>(); var activator = StyleActivator.And(new[] { activator1, activator2 }); var target = new ActivatedValue(activator, 1, string.Empty); var subscription = target.Subscribe(_ => { }); Assert.Equal(1, activator1.Subscriptions.Count); Assert.Equal(Subscription.Infinite, activator1.Subscriptions[0].Unsubscribe); subscription.Dispose(); Assert.Equal(1, activator1.Subscriptions.Count); Assert.Equal(0, activator1.Subscriptions[0].Unsubscribe); }
public void Should_Unsubscribe_From_Activator_When_All_Subscriptions_Disposed() { var scheduler = new TestScheduler(); var activator1 = scheduler.CreateColdObservable <bool>(); var activator2 = scheduler.CreateColdObservable <bool>(); var activator = StyleActivator.And(new[] { activator1, activator2 }); var target = new ActivatedValue(activator, 1, string.Empty); var subscription = target.Subscribe(_ => { }); Assert.Equal(1, activator1.Subscriptions.Count); Assert.Equal(Subscription.Infinite, activator1.Subscriptions[0].Unsubscribe); subscription.Dispose(); Assert.Equal(1, activator1.Subscriptions.Count); Assert.Equal(0, activator1.Subscriptions[0].Unsubscribe); }
private InstancedBinding Clone(InstancedBinding sourceInstance, IStyle style, IObservable<bool> activator) { InstancedBinding cloned; if (activator != null) { var description = style?.ToString(); if (sourceInstance.Subject != null) { var activated = new ActivatedSubject(activator, sourceInstance.Subject, description); cloned = new InstancedBinding(activated, sourceInstance.Mode, BindingPriority.StyleTrigger); } else if (sourceInstance.Observable != null) { var activated = new ActivatedObservable(activator, sourceInstance.Observable, description); cloned = new InstancedBinding(activated, sourceInstance.Mode, BindingPriority.StyleTrigger); } else { var activated = new ActivatedValue(activator, sourceInstance.Value, description); cloned = new InstancedBinding(activated, BindingMode.OneWay, BindingPriority.StyleTrigger); } } else { if (sourceInstance.Subject != null) { cloned = new InstancedBinding(sourceInstance.Subject, sourceInstance.Mode, BindingPriority.Style); } else if (sourceInstance.Observable != null) { cloned = new InstancedBinding(sourceInstance.Observable, sourceInstance.Mode, BindingPriority.Style); } else { cloned = new InstancedBinding(sourceInstance.Value, BindingPriority.Style); } } return cloned; }
/// <summary> /// Applies the setter to a control. /// </summary> /// <param name="style">The style that is being applied.</param> /// <param name="control">The control.</param> /// <param name="activator">An optional activator.</param> public IDisposable Apply(IStyle style, IStyleable control, IObservable<bool> activator) { Contract.Requires<ArgumentNullException>(control != null); var description = style?.ToString(); if (Property == null) { throw new InvalidOperationException("Setter.Property must be set."); } var value = Value; var binding = value as IBinding; if (binding == null) { var template = value as ITemplate; if (template != null) { var materialized = template.Build(); NameScope.SetNameScope((Visual)materialized, new NameScope()); value = materialized; } if (activator == null) { return control.Bind(Property, ObservableEx.SingleValue(value), BindingPriority.Style); } else { var activated = new ActivatedValue(activator, value, description); return control.Bind(Property, activated, BindingPriority.StyleTrigger); } } else { var source = binding.Initiate(control, Property); if (source != null) { var cloned = Clone(source, style, activator); return BindingOperations.Apply(control, Property, cloned, null); } } return Disposable.Empty; }
/// <summary> /// Applies the setter to the control. /// </summary> /// <param name="style">The style that is being applied.</param> /// <param name="control">The control.</param> /// <param name="activator">An optional activator.</param> public void Apply(IStyle style, IStyleable control, IObservable<bool> activator) { Contract.Requires<ArgumentNullException>(control != null); var description = style?.ToString(); if (Property == null) { throw new InvalidOperationException("Setter.Property must be set."); } var binding = Value as IBinding; if (binding != null) { if (activator == null) { control.Bind(Property, binding); } else { var subject = binding.CreateSubject(control, Property); var activated = new ActivatedSubject(activator, subject, description); Bind(control, Property, binding, activated); } } else { if (activator == null) { control.SetValue(Property, Value, BindingPriority.Style); } else { var activated = new ActivatedValue(activator, Value, description); control.Bind(Property, activated, BindingPriority.StyleTrigger); } } }