public void TestMockClient_CancellationSupport()
        {
            Cities.CityDomainContext dp = new Cities.CityDomainContext(new CitiesMockDomainClient());

            bool domainClientQueryCompleted = false;

            dp.DomainClient.BeginQuery(
                new EntityQuery <Cities.City>(dp.DomainClient, "GetCities", null, true, false),
                delegate(IAsyncResult getCitiesAsyncResult)
            {
                ExceptionHelper.ExpectException <NotSupportedException>(delegate
                {
                    dp.DomainClient.CancelQuery(getCitiesAsyncResult);
                }, string.Format(CultureInfo.CurrentCulture, Resource.DomainClient_CancellationNotSupported, typeof(CitiesMockDomainClient).FullName));

                domainClientQueryCompleted = true;
            }, null);

            EnqueueConditional(() => domainClientQueryCompleted);
            EnqueueCallback(delegate
            {
                var query        = dp.GetCitiesQuery();
                LoadOperation lo = dp.Load(query, false);
                Assert.IsFalse(lo.CanCancel, "Cancellation should not be supported.");
                Assert.IsFalse(dp.DomainClient.SupportsCancellation, "Cancellation should not be supported.");

                ExceptionHelper.ExpectException <NotSupportedException>(delegate
                {
                    lo.Cancel();
                }, string.Format(CultureInfo.CurrentCulture, Resources.AsyncOperation_CancelNotSupported));
            });

            EnqueueTestComplete();
        }
Example #2
0
        public void TestMockClient_CancellationSupport()
        {
            Cities.CityDomainContext dp = new Cities.CityDomainContext(new CitiesMockDomainClient());

            var           query = dp.GetCitiesQuery();
            LoadOperation lo    = dp.Load(query, false);

            Assert.IsFalse(lo.CanCancel, "Cancellation should not be supported.");
            Assert.IsFalse(dp.DomainClient.SupportsCancellation, "Cancellation should not be supported.");

            ExceptionHelper.ExpectException <NotSupportedException>(delegate
            {
                lo.Cancel();
            }, string.Format(CultureInfo.CurrentCulture, Resources.AsyncOperation_CancelNotSupported));
        }
        void FindCustomerByIDCallback(LoadOperation <Customers> loadOperation)
        {
            if (loadOperation.HasError)
            {
                if (loadOperation.CanCancel)
                {
                    loadOperation.Cancel();
                }
                HandleException(loadOperation.Error);
                loadOperation.MarkErrorAsHandled();
                return;
            }
            Action <Customers> action = (Action <Customers>)loadOperation.UserState;

            foreach (Customers customer in loadOperation.Entities)
            {
                try {
                    uiDispatcher.BeginInvoke(() => action(customer));
                } catch (Exception ex) {
                    HandleException(ex);
                }
            }
        }
Example #4
0
        public void Exceptions()
        {
            Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities);

            Action <LoadOperation <City> > loCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            Action <SubmitOperation> soCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            Action <InvokeOperation> ioCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            LoadOperation lo = new LoadOperation <City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, loCallback, null, loCallback);

            // verify completion callbacks that throw
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                try
                {
                    lo.Complete(DomainClientResult.CreateQueryResult(new Entity[0], new Entity[0], 0, new ValidationResult[0]));
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved.");

                    throw;
                }
            }, "Fnord!");

            // verify cancellation callbacks for all fx operation types
            lo = new LoadOperation <City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, loCallback);
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                lo.Cancel();
            }, "Fnord!");

            SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback);

            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                so.Cancel();
            }, "Fnord!");

            InvokeOperation io = new InvokeOperation("Fnord", null, null, null, ioCallback);

            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                io.Cancel();
            }, "Fnord!");
        }
Example #5
0
        public void Exceptions()
        {
            Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities);

            Action <LoadOperation <City> > loCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            Action <SubmitOperation> soCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            Action <InvokeOperation> ioCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            var query               = cities.GetCitiesQuery();
            var loadBehaviour       = LoadBehavior.MergeIntoCurrent;
            LoadOperation <City> lo = new LoadOperation <City>(query, loadBehaviour, loCallback, null, false);

            // verify completion callbacks that throw
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                try
                {
                    lo.Complete(new LoadResult <City>(query, loadBehaviour, Array.Empty <City>(), Array.Empty <Entity>(), 0));
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved.");

                    throw;
                }
            }, "Fnord!");

            // verify cancellation callbacks for all fx operation types
            lo = new LoadOperation <City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, true);
            lo.CancellationToken.Register(() => throw new InvalidOperationException("Fnord!"));
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                lo.Cancel();
            }, "Fnord!");

            SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback);

            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                so.Cancel();
            }, "Fnord!");

            InvokeOperation io = new InvokeOperation("Fnord", null, null, null, true);

            io.CancellationToken.Register(() => throw new InvalidOperationException("Fnord!"));
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                io.Cancel();
            }, "Fnord!");
        }
        public void Exceptions()
        {
            Cities.CityDomainContext cities = new CityDomainContext(TestURIs.Cities);

            Action<LoadOperation<City>> loCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            Action<SubmitOperation> soCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            Action<InvokeOperation> ioCallback = (op) =>
            {
                if (op.HasError)
                {
                    op.MarkErrorAsHandled();
                }

                throw new InvalidOperationException("Fnord!");
            };

            LoadOperation lo = new LoadOperation<City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, loCallback, null, loCallback);

            // verify completion callbacks that throw
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                try
                {
                    lo.Complete(DomainClientResult.CreateQueryResult(new Entity[0], new Entity[0], 0, new ValidationResult[0]));
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex.StackTrace.Contains("at OpenRiaServices.DomainServices.Client.Test.OperationTests"), "Stacktrace not preserved.");

                    throw;
                }
            }, "Fnord!");

            // verify cancellation callbacks for all fx operation types
            lo = new LoadOperation<City>(cities.GetCitiesQuery(), LoadBehavior.MergeIntoCurrent, null, null, loCallback);
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                lo.Cancel();
            }, "Fnord!");

            SubmitOperation so = new SubmitOperation(cities.EntityContainer.GetChanges(), soCallback, null, soCallback);
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                so.Cancel();
            }, "Fnord!");

            InvokeOperation io = new InvokeOperation("Fnord", null, null, null, ioCallback);
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                io.Cancel();
            }, "Fnord!");
        }