public void EntityContainer_GetChanges()
        {
            TestEntityContainer container = new TestEntityContainer();
            container.LoadEntities(_cities);
            EntityChangeSet changeset = container.GetChanges();
            Assert.IsNotNull(changeset);
            Assert.IsTrue(changeset.IsEmpty);

            // invoke domain method on 2 cities and verify invocation is in changeset
            // TODO: need 2 separate legal domain methods
            _cities[0].InvokeAction(_assignCityZone.Name, _assignCityZone.Parameters.ToArray<object>());
            _cities[2].InvokeAction(_assignCityZone.Name, _assignCityZone.Parameters.ToArray<object>());
            changeset = container.GetChanges();
            Assert.IsTrue(changeset.AddedEntities.Count == 0);
            Assert.IsTrue(changeset.ModifiedEntities.Count == 2);
            Assert.IsTrue(changeset.RemovedEntities.Count == 0);

            Assert.AreEqual<string>(_assignCityZone.Name, changeset.ModifiedEntities[0].EntityActions.Single().Name);
            Assert.AreEqual<string>(_assignCityZone.Name, changeset.ModifiedEntities[1].EntityActions.Single().Name);

            // revert one of the domain method invocations. verify invocation in changeset is updated
            ((System.ComponentModel.IRevertibleChangeTracking)_cities[0]).RejectChanges();
            changeset = container.GetChanges();
            City returned = changeset.ModifiedEntities.Single(p => p == _cities[2]) as City;
            Assert.IsNotNull(returned);
            Assert.AreEqual<string>(_assignCityZone.Name, returned.EntityActions.Single().Name);
            Assert.AreEqual<int>(_assignCityZone.Parameters.Count(), returned.EntityActions.Single().Parameters.Count());
        }
        public void EntityContainer_GetChanges_DetachAfterInvoke()
        {
            TestEntityContainer container = new TestEntityContainer();
            container.LoadEntities(_cities);
            EntityChangeSet changeset = container.GetChanges();
            Assert.IsTrue(changeset.IsEmpty);

            // invoke then delete the entity. Verify the ModifiedEntities are updated
            _cities[0].InvokeAction(_assignCityZone.Name, _assignCityZone.Parameters.ToArray<object>());
            Assert.AreEqual(1, _cities[0].EntityActions.Count());
            Assert.AreEqual(1, container.GetChanges().ModifiedEntities.Count());

            container.GetEntitySet<City>().Detach(_cities[0]);
            Assert.AreEqual(0, container.GetChanges().ModifiedEntities.Count());
        }
        public void Entity_CancelEdit()
        {
            // verify that DomainMethod invocations participate in IEditableObject sessions properly
            TestEntityContainer container = new TestEntityContainer();
            container.LoadEntities(_cities);
            System.ComponentModel.IEditableObject editableCity = _cities[0] as System.ComponentModel.IEditableObject;
            Assert.IsNotNull(editableCity);

            editableCity.BeginEdit();
            int prevZoneID = _cities[0].ZoneID;
            _cities[0].ZoneID = 777;
            _cities[0].InvokeAction(_assignCityZone.Name, _assignCityZone.Parameters.ToArray<object>());
            Assert.AreEqual(1, _cities[0].EntityActions.Count());

            // cancel editing. Domain method invocation and property updates are reverted
            editableCity.CancelEdit();
            Assert.AreEqual(prevZoneID, _cities[0].ZoneID);
            Assert.AreEqual(0, _cities[0].EntityActions.Count());
            Assert.AreEqual(EntityState.Unmodified, _cities[0].EntityState);
            Assert.IsTrue(container.GetChanges().IsEmpty);

            // now start an edit session with a modified entity
            // and verify same results
            _cities[0].ZoneID = 777;
            Assert.AreEqual(EntityState.Modified, _cities[0].EntityState);
            editableCity.BeginEdit();
            _cities[0].ZoneID = 888;
            _cities[0].InvokeAction(_assignCityZone.Name, _assignCityZone.Parameters.ToArray<object>());
            editableCity.CancelEdit();
            Assert.AreEqual(777, _cities[0].ZoneID);
            Assert.AreEqual(0, _cities[0].EntityActions.Count());
            Assert.AreEqual(EntityState.Modified, _cities[0].EntityState);

            // now test an edit session where only a DM was invoked (no property edits)
            ((System.ComponentModel.IRevertibleChangeTracking)_cities[0]).RejectChanges();
            Assert.AreEqual(EntityState.Unmodified, _cities[0].EntityState);
            editableCity.BeginEdit();
            _cities[0].InvokeAction(_assignCityZone.Name, _assignCityZone.Parameters.ToArray<object>());
            Assert.AreEqual(EntityState.Modified, _cities[0].EntityState);
            editableCity.CancelEdit();
            Assert.AreEqual(EntityState.Unmodified, _cities[0].EntityState);
            Assert.IsTrue(container.GetChanges().IsEmpty);
        }