void SubmitChangesCallback(SubmitOperation submitOperation) { if (submitOperation.HasError) { if (submitOperation.CanCancel) { submitOperation.Cancel(); } context.RejectChanges(); HandleException(submitOperation.Error); submitOperation.MarkErrorAsHandled(); } uiDispatcher.BeginInvoke(() => riaInstantSource.Refresh()); }
[Ignore] // Need to fix Race condition before enabling again public async Task CancelSubmit_EmptyChangeset() { Northwind nw = new Northwind(TestURIs.LTS_Northwind); SubmitOperation so = nw.SubmitChanges(); // WARNING: Race condition // A SyncronizationContext needs to be provided // So that the the operation cannot be completed between the CanCancel // and the IsCompleted check in Cancel so.Cancel(); await so; Assert.IsNull(so.Error); }
public void Bug635474_IsSubmittingStateManagement() { Northwind nw = new Northwind(TestURIs.LTS_Northwind); Product prod = new Product { ProductID = 1, ProductName = "Tasty O's" }; nw.Products.Attach(prod); // verify that IsSubmitting is reset when the submit // is cancelled prod.ProductName += "x"; SubmitOperation so = nw.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); so.Cancel(); Assert.IsFalse(nw.IsSubmitting); }
public void CancelSubmit_EmptyChangeset() { Northwind nw = new Northwind(TestURIs.LTS_Northwind); SubmitOperation so = null; this.EnqueueCallback(() => { so = nw.SubmitChanges(); if (so.CanCancel) { so.Cancel(); } }); this.EnqueueConditional(() => so.IsComplete); this.EnqueueCallback(() => { Assert.IsNull(so.Error); }); this.EnqueueTestComplete(); }
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!"); }
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!"); }