public void InitialValueIsCorrect() { var value = ActiveValue.Create(10); var sut = value.ActiveAggregate(1, (currentValue, newValue) => currentValue + newValue); Assert.Equal(11, sut.Value); }
public void ExecutesImmediately() { var value = ActiveValue.Create(new IntegerTestClass()); var sut = value.ActiveDo(o => o.SetProperty(10)); Assert.Equal(10, sut.Value.Property); }
public void ExecutesOnValuePropertyChange() { var value = ActiveValue.Create(new IntegerTestClass()); var sut = value.ActiveDo(o => o.SetProperty(o.Key)); value.Value.Key = 10; Assert.Equal(10, sut.Value.Property); }
public void ExecutesOnParameterPropertyChange() { var value = ActiveValue.Create(new IntegerTestClass()); var parameter = ActiveValue.Create(new IntegerTestClass()); var sut = value.ActiveDo(parameter, (o, p) => o.SetProperty(p.Property)); parameter.Value.Property = 10; Assert.Equal(10, sut.Value.Property); }
public void ValueTypeIsNull() { var value = ActiveValue.Create <TypeBase>(null); var sut = value.ActiveCastOrDefault <TypeA>(); Assert.Null(sut.Value); value.Value = new TypeA(); Assert.Equal(value.Value, sut.Value); }
public void ValueTypeIsCorrectAndThenIncorrect() { var value = ActiveValue.Create <TypeBase>(new TypeA()); var sut = value.ActiveCastOrDefault <TypeB>(); Assert.Null(sut.Value); value.Value = new TypeB(); Assert.Equal(value.Value, sut.Value); }
public void SkipCountAndIncreaseSkip() { int raisedCount = 0; var skipCount = ActiveValue.Create(3); var list = ActiveList.Create(new[] { 1, 2, 3 }); var sut = list.ActiveSkip(skipCount); sut.CollectionChanged += (s, e) => ++ raisedCount; skipCount.Value = 4; Assert.Equal(0, raisedCount); }
public void SkipLessThanCountAndDecreaseSkip() { int raisedCount = 0; var skipCount = ActiveValue.Create(2); var list = ActiveList.Create(new[] { 1, 2, 3 }); var sut = list.ActiveSkip(skipCount); sut.CollectionChanged += (s, e) => raisedCount += e.Action == NotifyCollectionChangedAction.Add ? 1 : 0; skipCount.Value = 1; Assert.Equal(1, raisedCount); }
public void TakeLessThanCountAndDecreaseTake() { int raisedCount = 0; var takeCount = ActiveValue.Create(2); var list = ActiveList.Create(new[] { 1, 2, 3 }); var sut = list.ActiveTake(takeCount); sut.CollectionChanged += (s, e) => raisedCount += e.Action == NotifyCollectionChangedAction.Remove ? 1 : 0; takeCount.Value = 1; Assert.Equal(1, raisedCount); }
public void TakeMoreThanCountAndDecreaseTake() { int raisedCount = 0; var takeCount = ActiveValue.Create(4); var list = ActiveList.Create(new[] { 1, 2, 3 }); var sut = list.ActiveTake(takeCount); sut.CollectionChanged += (s, e) => ++ raisedCount; takeCount.Value = 3; Assert.Equal(0, raisedCount); }
public void SelectActiveValue() { var value = ActiveValue.Create(false); var sut = new object[] { null } .ToActiveList() .ActiveSelect(_ => value) .ActiveAny(b => b); Assert.False(sut.Value); value.Value = true; Assert.True(sut.Value); }
public void WhereActiveValue() { var value = ActiveValue.Create(false); var sut = new object[] { null } .ToActiveList() .ActiveWhere(_ => value) .ActiveAny(); Assert.False(sut.Value); value.Value = true; Assert.True(sut.Value); }
public void UpdatesOnSourceChange() { var value = ActiveValue.Create(0); var sut = value.ActiveAggregate(0, (currentValue, newValue) => currentValue + newValue); Assert.Equal(0, sut.Value); value.Value = 10; Assert.Equal(10, sut.Value); value.Value = 5; Assert.Equal(15, sut.Value); }
public void ChangingParameterStaysUpToDate() { var list = ActiveList.Create(Enumerable.Range(5, 10)); var lookup = list.ToActiveLookup(i => i / 10); var parameter = ActiveValue.Create(0); var sut = lookup.ActiveSelectByKey(parameter); Assert.True(list.Take(5).SequenceEqual(sut)); parameter.Value = 1; Assert.True(list.Skip(5).Take(5).SequenceEqual(sut)); }
public ActiveListJoiner(ActiveListJoinBehaviour joinBehaviour, Func <JoinOption <TLeft>, JoinOption <TRight>, TResult> resultSelector, IEnumerable <string> leftResultSelectorPropertiesToWatch, IEnumerable <string> rightResultSelectorPropertiesToWatch) { _joinBehaviour = joinBehaviour; _resultSelector = resultSelector; _left = ActiveValue.Create <TLeft>(); _leftWatcher = new ValueWatcher <TLeft>(_left, leftResultSelectorPropertiesToWatch); _leftWatcher.ValuePropertyChanged += () => OnLeftChanged(); _rightCollectionWrappper = new CollectionWrapper <TRight>(null, rightResultSelectorPropertiesToWatch?.ToArray()); _rightCollectionWrappper.ItemModified += (s, i, v) => OnRightReplaced(i, v, v); _rightCollectionWrappper.ItemAdded += (s, i, v) => OnRightAdded(i, v); _rightCollectionWrappper.ItemRemoved += (s, i, v) => OnRightRemoved(i, v); _rightCollectionWrappper.ItemReplaced += (s, i, o, n) => OnRightReplaced(i, o, n); _rightCollectionWrappper.ItemMoved += (s, o, n, v) => OnRightMoved(o, n, v); _rightCollectionWrappper.ItemsReset += s => OnRightReset(s); }
public void ChangingParameterThrowsResetNotification() { var list = ActiveList.Create(Enumerable.Range(5, 10)); var lookup = list.ToActiveLookup(i => i / 10); var parameter = ActiveValue.Create(0); var sut = lookup.ActiveSelectByKey(parameter); bool changeOccured = false; sut.CollectionChanged += (s, e) => changeOccured = true; Assert.False(changeOccured); parameter.Value = 1; Assert.True(changeOccured); }