public void Activate_is_not_called_until_dependencies_return_true() { var activations = 0; var notifications = new List <bool>(); var subject = new BehaviorSubject <bool>(false); var activator = new FeatureActivator(() => activations++, dependsOn: subject); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); subject.OnNext(false); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); subject.OnNext(true); Assert.That(activations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(false, true)); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(activations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(false, true, true)); }
public void When_there_are_multiple_subscribers_then_activate_is_not_called_repeatedly() { var activations = 0; var activator = new FeatureActivator(() => activations++); disposables.Add(activator.Subscribe(_ => { })); disposables.Add(activator.Subscribe(_ => { })); disposables.Add(activator.Subscribe(_ => { })); Assert.That(activations, Is.EqualTo(1)); }
public void When_there_are_multiple_dependencies_they_must_all_return_true_before_Activate_is_called() { var activations = 0; var dependency1 = new BehaviorSubject <bool>(false); var dependency2 = new BehaviorSubject <bool>(false); var activator = new FeatureActivator( activate: () => activations++, dependsOn: new[] { dependency1, dependency2 }); var notifications = new List <bool>(); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); dependency1.OnNext(true); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); dependency2.OnNext(true); Assert.That(activations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(false, true)); }
public void Deactivate_is_not_called_until_after_activate_has_been_called() { var deactivations = 0; var subject = new BehaviorSubject <bool>(false); var activator = new FeatureActivator(() => { }, () => deactivations++, dependsOn: subject); disposables.Add(activator.Subscribe(_ => { })); subject.OnNext(true); Assert.That(deactivations, Is.EqualTo(0)); subject.OnNext(false); Assert.That(deactivations, Is.EqualTo(1)); }
public void Produces_a_value_each_time_the_aggregate_availability_of_dependencies_changes() { var dependency = new BehaviorSubject <bool>(false); var activator = new FeatureActivator(() => { }, dependsOn: dependency); var notifications = new List <bool>(); disposables.Add(activator.Subscribe(notifications.Add)); dependency.OnNext(false); dependency.OnNext(false); dependency.OnNext(true); dependency.OnNext(true); dependency.OnNext(true); dependency.OnNext(true); dependency.OnNext(false); dependency.OnNext(false); dependency.OnNext(false); Assert.That(notifications.IsSameSequenceAs(false, true, false)); }
public void Produces_a_value_each_time_the_aggregate_availability_of_dependencies_changes() { var dependency = new BehaviorSubject<bool>(false); var activator = new FeatureActivator(() => { }, dependsOn: dependency); var notifications = new List<bool>(); disposables.Add(activator.Subscribe(notifications.Add)); dependency.OnNext(false); dependency.OnNext(false); dependency.OnNext(true); dependency.OnNext(true); dependency.OnNext(true); dependency.OnNext(true); dependency.OnNext(false); dependency.OnNext(false); dependency.OnNext(false); Assert.That(notifications.IsSameSequenceAs(false, true, false)); }
public void When_any_dependency_produces_false_then_deactivate_is_called() { var deactivations = 0; var dependency1 = new BehaviorSubject <bool>(true); var dependency2 = new BehaviorSubject <bool>(true); var activator = new FeatureActivator( activate: () => { }, deactivate: () => deactivations++, dependsOn: new[] { dependency1, dependency2 }); var notifications = new List <bool>(); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(deactivations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(true)); dependency1.OnNext(false); Assert.That(deactivations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(true, false)); }
public void Deactivate_is_not_called_until_after_activate_has_been_called() { var deactivations = 0; var subject = new BehaviorSubject<bool>(false); var activator = new FeatureActivator(() => { }, () => deactivations++, dependsOn: subject); disposables.Add(activator.Subscribe(_ => { })); subject.OnNext(true); Assert.That(deactivations, Is.EqualTo(0)); subject.OnNext(false); Assert.That(deactivations, Is.EqualTo(1)); }
public void When_any_dependency_produces_false_then_deactivate_is_called() { var deactivations = 0; var dependency1 = new BehaviorSubject<bool>(true); var dependency2 = new BehaviorSubject<bool>(true); var activator = new FeatureActivator( activate: () => { }, deactivate: () => deactivations++, dependsOn: new[] { dependency1, dependency2 }); var notifications = new List<bool>(); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(deactivations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(true)); dependency1.OnNext(false); Assert.That(deactivations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(true, false)); }
public void When_there_are_multiple_dependencies_they_must_all_return_true_before_Activate_is_called() { var activations = 0; var dependency1 = new BehaviorSubject<bool>(false); var dependency2 = new BehaviorSubject<bool>(false); var activator = new FeatureActivator( activate: () => activations++, dependsOn: new[] { dependency1, dependency2 }); var notifications = new List<bool>(); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); dependency1.OnNext(true); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); dependency2.OnNext(true); Assert.That(activations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(false, true)); }
public void Activate_is_not_called_until_dependencies_return_true() { var activations = 0; var notifications = new List<bool>(); var subject = new BehaviorSubject<bool>(false); var activator = new FeatureActivator(() => activations++, dependsOn: subject); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); subject.OnNext(false); Assert.That(activations, Is.EqualTo(0)); Assert.That(notifications.IsSameSequenceAs(false)); subject.OnNext(true); Assert.That(activations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(false, true)); disposables.Add(activator.Subscribe(notifications.Add)); Assert.That(activations, Is.EqualTo(1)); Assert.That(notifications.IsSameSequenceAs(false, true, true)); }
public void When_there_are_multiple_subscribers_then_activate_is_not_called_repeatedly() { var activations = 0; var activator = new FeatureActivator(() => activations++); disposables.Add(activator.Subscribe(_ => { })); disposables.Add(activator.Subscribe(_ => { })); disposables.Add(activator.Subscribe(_ => { })); Assert.That(activations, Is.EqualTo(1)); }