Example #1
0
        public void ShouldOnlyAddEvenNumbers()
        {
            var source = new ObservableCollection<int>();
            var dest = new List<int>();

            source.PushChangesTo(dest).AddOnlyIf(NumberIsEven);

            source.Add(1);
            dest.ShouldNotContain(1);

            source.Add(2);
            dest.ShouldContain(2);
        }
        public void ShouldExecuteAfterAdding()
        {
            var source = new ObservableCollection<int>();
            var dest = new List<int>();

            source.PushChangesTo(dest).If(NumberIsEven)
                .Execute(IncrementCount).AfterAdding();

            source.Add(1);
            notifiedCount.ShouldBe(0);

            source.Add(2);
            notifiedCount.ShouldBe(1);
        }
Example #3
0
        public void ShouldMaintainInitialDifferences()
        {
            var source = new ObservableCollection<int>();
            var dest = new List<int>();

            source.Add(1);

            source.PushChangesTo(dest);

            dest.ShouldNotContain(1);

            source.Remove(1);
            dest.ShouldNotContain(1);
        }
Example #4
0
        public void ShouldActAsAnEvenFilter()
        {
            var source = new ObservableCollection<int>();
            var dest = new List<int>();

            source.PushChangesTo(dest).If(NumberIsEven);

            source.Add(1);
            dest.ShouldNotContain(1);

            source.Add(2);
            dest.ShouldContain(2);

            source.Remove(2);
            dest.ShouldNotContain(2);

            dest.Add(1);
            source.Remove(1);
            dest.ShouldContain(1);
        }
        public void ShouldExecuteCallBacksInCorrectOrder()
        {
            var source = new ObservableCollection<int>();
            var dest = new List<int> {1, 2, 3};

            source.PushChangesTo(dest)
                .Execute(item => dest.Count.ShouldBe(3)).BeforeAdding()
                .Execute(item => dest.Count.ShouldBe(4)).AfterAdding()
                .Execute(item => dest.Count.ShouldBe(4)).BeforeRemoving()
                .Execute(item => dest.Count.ShouldBe(3)).AfterRemoving();

            source.Add(4);
            source.Remove(4);
        }
Example #6
0
        public void ShouldPushChangesToAListGivenAMapping()
        {
            var source = new ObservableCollection<int>();
            var dest = new List<float>();

            source.PushChangesTo(dest).WithMapping(i => i);

            source.Add(1);
            dest.ShouldContain(1.00f);

            source.Remove(1);
            dest.ShouldNotContain(1.00f);
        }