public void NamedUpdate_CustomOnly_SuccessfulUpdate()
        {
            LoadOperation<MockEntity1> loadOp = null;
            SubmitOperation submitOp = null;
            Uri uri = new Uri(TestURIs.RootURI, "TestDomainServices-NamedUpdates-NamedUpdate_CustomOnly.svc");
            NamedUpdate_CustomOnly ctx = new NamedUpdate_CustomOnly(uri);

            // Here, we have a custom method defined on the server.  Let's 
            // perform some update operations on an entity, invoke a custom 
            // method and submit changes.
            loadOp = ctx.Load(ctx.GetEntitiesQuery(), false);
            this.EnqueueConditional(() => loadOp.IsComplete);
            this.EnqueueCallback(() =>
            {
                // Verify we loaded OK
                this.AssertCompletedWithoutErrors(loadOp);
                Assert.AreEqual(1, loadOp.Entities.Count(), "Expected to load 1 entity.");

                // Retrieve an editable entity
                MockEntity1 entity = ctx.MockEntity1s.First();
                Assert.IsFalse(entity.IsReadOnly);

                // Verify the initial expected state
                Assert.AreEqual("OriginalValue1", entity.Property1);
                Assert.AreEqual("OriginalValue2", entity.Property2);
                Assert.AreEqual("OriginalValue3", entity.Property3);

                // Update entity state using property setters and a custom method
                entity.Property2 = "NewValue2";
                entity.Property3 = "NewValue3";
                entity.NamedUpdateMethod("NewValue1");

                // Submit changes
                Assert.IsTrue(entity.IsReadOnly);
                submitOp = ctx.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            this.EnqueueConditional(() => submitOp.IsComplete);
            this.EnqueueCallback(() =>
            {
                // Verify we submitted OK
                this.AssertCompletedWithoutErrors(submitOp);

                // Verify our update persisted
                MockEntity1 entity = ctx.MockEntity1s.First();
                Assert.IsFalse(entity.IsReadOnly);
                Assert.AreEqual("NewValue1", entity.Property1);
                Assert.AreEqual("NewValue2", entity.Property2);
                Assert.AreEqual("OriginalValue3", entity.Property3); // Our update is a masked update that always reverts the Property3 value.
            });
            this.EnqueueTestComplete();
        }
        public void NamedUpdate_CustomOnly_FailWhenCustomMethodNotCalled()
        {
            LoadOperation<MockEntity1> loadOp = null;
            SubmitOperation submitOp = null;
            Uri uri = new Uri(TestURIs.RootURI, "TestDomainServices-NamedUpdates-NamedUpdate_CustomOnly.svc");
            NamedUpdate_CustomOnly ctx = new NamedUpdate_CustomOnly(uri);

            // Here, we have a custom method defined on the server.  Let's 
            // perform some update operations on an entity and submit changes.
            // This should result in a failure since no custom method was 
            // invoked.
            loadOp = ctx.Load(ctx.GetEntitiesQuery(), false);
            this.EnqueueConditional(() => loadOp.IsComplete);
            this.EnqueueCallback(() =>
            {
                // Verify we loaded OK
                this.AssertCompletedWithoutErrors(loadOp);
                Assert.AreEqual(1, loadOp.Entities.Count(), "Expected to load 1 entity.");

                // Retrieve an editable entity
                MockEntity1 entity = ctx.MockEntity1s.First();
                Assert.IsFalse(entity.IsReadOnly);

                // Verify the initial expected state
                Assert.AreEqual("OriginalValue1", entity.Property1);
                Assert.AreEqual("OriginalValue2", entity.Property2);
                Assert.AreEqual("OriginalValue3", entity.Property3);

                // Update entity state using property setters
                entity.Property1 = "NewValue1";
                entity.Property2 = "NewValue2";
                entity.Property3 = "NewValue3";

                // Submit changes
                submitOp = ctx.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            this.EnqueueConditional(() => submitOp.IsComplete);
            this.EnqueueCallback(() =>
            {
                // Verify error message
                string expectedMessage = string.Format(Resource.DomainContext_SubmitOperationFailed, string.Format("This DomainService does not support operation '{0}' for entity '{1}'.", "Update", typeof(MockEntity1).Name));
                this.AssertCompletedWithError(submitOp, expectedMessage);
            });
            this.EnqueueTestComplete();
        }
        public void NamedUpdate_CustomOnly_SupportedOperations()
        {
            Uri uri = new Uri(TestURIs.RootURI, "TestDomainServices-NamedUpdates-NamedUpdate_CustomOnly.svc");
            NamedUpdate_CustomOnly ctx = new NamedUpdate_CustomOnly(uri);

            Assert.IsFalse(ctx.MockEntity1s.CanAdd);
            Assert.IsTrue(ctx.MockEntity1s.CanEdit);
            Assert.IsFalse(ctx.MockEntity1s.CanRemove);
        }