public void CollectionSourceCacheEnabled_WhenCollectionIsRefreshed_InvokesSourceProvider()
        {
            List <Task>        originalTasks = TaskRepository.GetTasks();
            IEnumerable <Task> tasks         = originalTasks;

            Func <IEnumerable <Task> > sourceProvider = () => {
                return(tasks);
            };

            var vm = new TaskListVM(TaskListVM.CreateDescriptor(sourceProvider, cacheSourceCollection: true));

            CollectionAssert.AreEqual(
                originalTasks,
                vm.Tasks.Select(x => x.Source).ToList()
                );

            List <Task> refreshedTasks = TaskRepository.GetTasks();

            tasks = refreshedTasks;

            vm.RefreshTasks();

            CollectionAssert.AreEqual(
                refreshedTasks,
                vm.Tasks.Select(x => x.Source).ToList()
                );
        }
        public void CollectionSourceCacheEnabled_WhenCollectionChanges_DoesNotInvokeSourceProvider()
        {
            int sourceProviderInvocations             = 0;
            Func <IEnumerable <Task> > sourceProvider = () => {
                sourceProviderInvocations++;
                return(new List <Task>());
            };

            var vm = new TaskListVM(TaskListVM.CreateDescriptor(sourceProvider, cacheSourceCollection: true));

            var loadTrigger = vm.Tasks;

            vm.Tasks.Add(new TaskVM());
            vm.Tasks.Clear();

            Assert.AreEqual(1, sourceProviderInvocations);
        }
        public void CollectionSourceCacheDisabled_WhenCollectionChanges_DoesInvokeSourceProvider()
        {
            int sourceProviderInvocations = 0;
            var sourceList = new List <Task>();

            Func <IEnumerable <Task> > sourceProvider = () => {
                sourceProviderInvocations++;
                return(sourceList);
            };

            var vm = new TaskListVM(TaskListVM.CreateDescriptor(sourceProvider, cacheSourceCollection: false));

            var loadTrigger = vm.Tasks;

            vm.Tasks.Add(new TaskVM());
            vm.Tasks.Clear();

            Assert.IsTrue(sourceProviderInvocations >= 3);
        }