public void DomainClient_SubmitWithNonexistentDomainMethod()
        {
            TestEntityContainer container = new TestEntityContainer();
            WebDomainClient<CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient<CityDomainContext.ICityDomainServiceContract>(TestURIs.Cities)
            {
                EntityTypes = new Type[] { typeof(City) }
            };
            List<Entity> emptyList = new List<Entity>();
            List<Entity> modifiedEntities = new List<Entity>();

            // invoke domain methods on a few entities
            container.LoadEntities(_cities);

            _cities[0].CustomMethodInvocation = _reject;

            // submit changeset with hand-crafted entities (without calling Invoke)
            modifiedEntities.Add(_cities[0]);
            EntityChangeSet changeset = new EntityChangeSet(emptyList.AsReadOnly(), modifiedEntities.AsReadOnly(), emptyList.AsReadOnly());
            SubmitCompletedResult submitResults = null;
            DomainOperationException expectedException = null;

            EnqueueCallback(delegate
            {
                client.BeginSubmit(
                    changeset,
                    delegate(IAsyncResult asyncResult)
                    {
                        try
                        {
                            submitResults = client.EndSubmit(asyncResult);
                        }
                        catch (DomainOperationException e)
                        {
                            expectedException = e;
                        }
                    },
                    null
                );
            });
            EnqueueConditional(() => expectedException != null);
            EnqueueCallback(delegate
            {
                Assert.IsNull(submitResults);
                Assert.AreEqual("This DomainService does not support operation 'Reject' for entity 'CityWithInfo'.", expectedException.Message);
            });

            EnqueueTestComplete();
        }
        public void DomainClient_SubmitWithNullInvocation()
        {
            TestEntityContainer container = new TestEntityContainer();

            //TODO: find a better way to not hardcode the list of known types
            WebDomainClient<CityDomainContext.ICityDomainServiceContract> client = new WebDomainClient<CityDomainContext.ICityDomainServiceContract>(TestURIs.Cities)
            {
                EntityTypes = new Type[] { typeof(City), typeof(ChangeSetEntry), typeof(EntityOperationType) }
            };
            List<Entity> emptyList = new List<Entity>();
            List<Entity> modifiedEntities = new List<Entity>();

            // invoke domain methods on a few entities
            container.LoadEntities(_cities);
            _cities[1].AssignCityZone(_assignCityZone.Parameters.First().ToString());

            // submit changeset with hand-crafted entities: valid invocation and null invocation
            modifiedEntities.Add(_cities[0]);
            modifiedEntities.Add(_cities[1]);
            modifiedEntities.Add(_cities[2]);
            Assert.AreEqual(EntityState.Modified, _cities[1].EntityState);
            EntityChangeSet changeset = new EntityChangeSet(emptyList.AsReadOnly(), modifiedEntities.AsReadOnly(), emptyList.AsReadOnly());
            SubmitCompletedResult submitResults = null;
            client.BeginSubmit(
                changeset,
                delegate(IAsyncResult asyncResult)
                {
                    submitResults = client.EndSubmit(asyncResult);
                },
                null
            );

            // wait for submit to complete
            EnqueueConditional(() => submitResults != null);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(1, submitResults.Results.Count());
                Assert.AreEqual(1, submitResults.Results.Where(e => e.Operation == EntityOperationType.Update).Count());

                // REVIEW: Do we really need the operation data back from the server?
                // ChangeSetEntry returned = submitResults.Results.Single(e => e.OperationName == _assignCityZone.Name);
                // Assert.IsNotNull(returned);
                // Assert.AreEqual(1, returned.OperationData.Count());
            });

            EnqueueTestComplete();
        }