public void ResetAddsTrackedAddedEntities()
        {
            PagedEntityCollection pagedCollection = new PagedEntityCollection(p => { return(true); });
            MockEntitySet         cities          = LoadCities(true, pagedCollection);

            // Remove one entity that won't get resurrected
            Entity toRemove = pagedCollection[1];

            cities.Remove(toRemove);

            // And remove another entity that will get resurrected
            Entity toRemoveAndAdd = pagedCollection[0];

            cities.Remove(toRemoveAndAdd);

            // Turn off the events so that the Add isn't raised
            cities.RaiseCollectionChangedEvents = false;
            cities.Add(toRemoveAndAdd);

            // Raise the Reset event to pick up the city that was added back
            cities.ResetCollection();
            Assert.AreEqual <int>(cities.Count, pagedCollection.Count, "pagedCollection.Count should equal the cities count after adding the city back and resetting the collection");
            Assert.IsTrue(pagedCollection.Contains(toRemoveAndAdd), "The city should be back in the pagedCollection after adding it back and resetting the collection");
            Assert.IsFalse(pagedCollection.Contains(toRemove), "The city that was removed but not added back should not be in the pagedCollection");
        }
        public void ResetEventRetainsEntitiesStillInSet()
        {
            PagedEntityCollection pagedCollection = new PagedEntityCollection(p => { return(true); });
            MockEntitySet         cities          = LoadCities(false, pagedCollection);

            cities.ResetCollection();
            Assert.AreEqual <int>(cities.Count, pagedCollection.Count, "pagedCollection.Count should match cities.Count after resetting the collection");
        }
        public void ResetRemovesRemovedEntities()
        {
            PagedEntityCollection pagedCollection = new PagedEntityCollection(p => { return(true); });
            MockEntitySet         cities          = LoadCities(false, pagedCollection);

            Entity toRemove = pagedCollection[0];

            cities.Remove(toRemove);
            Assert.AreEqual <int>(cities.Count + 1, pagedCollection.Count, "pagedCollection.Count should be one more than cities.Count after removing the city from the cities set");
            Assert.IsTrue(pagedCollection.Contains(toRemove), "pagedCollection should still contain the city removed from the cities set until the Reset is raised");

            cities.ResetCollection();
            Assert.AreEqual <int>(cities.Count, pagedCollection.Count, "pagedCollection.Count should match cities.Count after resetting the collection");
            Assert.IsFalse(pagedCollection.Contains(toRemove), "pagedCollection should no longer contain the city removed from the cities set after resetting the collection");
        }
        public void ResetIgnoresUntrackedAddedEntities()
        {
            PagedEntityCollection pagedCollection = new PagedEntityCollection(p => { return(true); });
            MockEntitySet         cities          = LoadCities(false, pagedCollection);

            City toAdd = new City
            {
                Name       = "New City",
                StateName  = "ST",
                CountyName = "County"
            };

            cities.Add(toAdd);
            Assert.AreEqual <int>(cities.Count - 1, pagedCollection.Count, "pagedCollection.Count should be one less than cities.Count after adding the city to the cities set");
            Assert.IsFalse(pagedCollection.Contains(toAdd), "pagedCollection should not contain the city added to the cities set before the Reset is raised");

            cities.ResetCollection();
            Assert.AreEqual <int>(cities.Count - 1, pagedCollection.Count, "pagedCollection.Count should be one less than cities.Count after resetting the collection");
            Assert.IsFalse(pagedCollection.Contains(toAdd), "pagedCollection should not contain the city added to the cities set after resetting the collection");
        }
        public void ResetEventRelayed()
        {
            PagedEntityCollection pagedCollection = new PagedEntityCollection(p => { return(true); });
            MockEntitySet         cities          = LoadCities(false, pagedCollection);

            // Remove an item
            pagedCollection.RemoveAt(0);

            // Add an item
            pagedCollection.Add(new City
            {
                Name       = "Added City",
                StateName  = "ST",
                CountyName = "County"
            });

            this.AssertCollectionChanged(
                () => cities.ResetCollection(),
                pagedCollection,
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset),
                "when resetting the collection.");
        }