public void Submit_DefaultBehavior() { IAsyncResult asyncResult = null; this.EnqueueCallback(() => { asyncResult = this.BeginSubmitRequest(); }); this.EnqueueConditional(() => asyncResult.IsCompleted && this.SubmitCompletedResults != null); this.EnqueueCallback(() => { // Validate that we got back all of our entity operations, even though the entity didn't get any new values on the server. Assert.AreEqual(1, this.SubmitCompletedResults.Results.Count()); // Validate that a second call to EndLoad throws ExceptionHelper.ExpectInvalidOperationException(() => this.SubmitAsyncCallback(asyncResult), Resources.MethodCanOnlyBeInvokedOnce); }); this.EnqueueTestComplete(); }
public void EditableFalse_AllowInitialValue() { TestDomainServices.TestProvider_Scenarios ctxt = new TestDomainServices.TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); // Detached Entity : Editable(false, AllowInitialValue=true) - verify the property can be set TestDomainServices.Entity_TestEditableAttribute e = new TestDomainServices.Entity_TestEditableAttribute(); Assert.AreEqual(EntityState.Detached, e.EntityState); e.EditableFalse_AllowInitialValueTrue = "Foo"; Assert.AreEqual("Foo", e.EditableFalse_AllowInitialValueTrue); // New Entity : Editable(false, AllowInitialValue=true) - verify the property can be set e = new TestDomainServices.Entity_TestEditableAttribute(); e.InitializeNew(); Assert.AreEqual(EntityState.New, e.EntityState); e.EditableFalse_AllowInitialValueTrue = "Foo"; Assert.AreEqual("Foo", e.EditableFalse_AllowInitialValueTrue); // Unmodified Entity : Editable(false, AllowInitialValue=true) - verify the property is read only ctxt.Entity_TestEditableAttributes.Attach(e); Assert.AreEqual(EntityState.Unmodified, e.EntityState); ExceptionHelper.ExpectInvalidOperationException(delegate { e.EditableFalse_AllowInitialValueTrue = "Boom"; }, string.Format(Resource.Property_Is_ReadOnly, "EditableFalse_AllowInitialValueTrue")); // Detached Entity : Editable(false, AllowInitialValue=false) - verify the property is read only e = new TestDomainServices.Entity_TestEditableAttribute(); Assert.AreEqual(EntityState.Detached, e.EntityState); ExceptionHelper.ExpectInvalidOperationException(delegate { e.EditableFalse_AllowInitialValueFalse = "Boom"; }, string.Format(Resource.Property_Is_ReadOnly, "EditableFalse_AllowInitialValueFalse")); // New Entity : Editable(false, AllowInitialValue=false) - verify the property is read only e = new TestDomainServices.Entity_TestEditableAttribute(); e.InitializeNew(); Assert.AreEqual(EntityState.New, e.EntityState); ExceptionHelper.ExpectInvalidOperationException(delegate { e.EditableFalse_AllowInitialValueFalse = "Boom"; }, string.Format(Resource.Property_Is_ReadOnly, "EditableFalse_AllowInitialValueFalse")); }
public void NonComposableQuery() { EntityQuery <City> citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, false); IQueryable <City> queryable = new City[0].AsQueryable(); string expectedMessage = string.Format(Resource.EntityQuery_NotComposable, "City", "GetCities"); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.Where(p => p.StateName == "Toledo"); }, expectedMessage); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.Skip(1); }, expectedMessage); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.Take(1); }, expectedMessage); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.OrderBy(p => p.CountyName); }, expectedMessage); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.OrderByDescending(p => p.CountyName); }, expectedMessage); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.ThenBy(p => p.CountyName); }, expectedMessage); ExceptionHelper.ExpectInvalidOperationException(delegate { citiesQuery.ThenByDescending(p => p.CountyName); }, expectedMessage); }
public void Operation_MarkAsHandled() { TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc")); var query = ctxt.CreateQuery <Product>("ThrowGeneralException", null, false, true); LoadOperation lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, null); EventHandler action = (o, e) => { LoadOperation loadOperation = (LoadOperation)o; if (loadOperation.HasError) { loadOperation.MarkErrorAsHandled(); } }; lo.Completed += action; DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); lo.Complete(ex); // verify that calling MarkAsHandled again is a noop lo.MarkErrorAsHandled(); lo.MarkErrorAsHandled(); // verify that calling MarkAsHandled on an operation not in error // results in an exception lo = new LoadOperation <Product>(query, LoadBehavior.KeepCurrent, null, null, null); Assert.IsFalse(lo.HasError); Assert.IsTrue(lo.IsErrorHandled); ExceptionHelper.ExpectInvalidOperationException(delegate { lo.MarkErrorAsHandled(); }, Resource.Operation_HasErrorMustBeTrue); }
public void UncommitedEntityEdits() { Northwind ctxt = new Northwind(TestURIs.LTS_Northwind); Product prod = new Product { ProductID = 1, ProductName = "Cheezy Tots" }; ctxt.EntityContainer.LoadEntities(new Entity[] { prod }); // start an edit session and calculate // changes w/o ending the session IEditableObject eo = (IEditableObject)prod; eo.BeginEdit(); prod.ProductName = "Chikn Crisps"; Assert.IsTrue(prod.HasChanges); Assert.IsTrue(prod.IsEditing); EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.AreEqual(1, cs.ModifiedEntities.Count); // however, attempting to call submit will result in // an exception ExceptionHelper.ExpectInvalidOperationException(delegate { ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }, string.Format(Resource.Entity_UncommittedChanges, prod)); // end the session eo.EndEdit(); Assert.IsFalse(prod.IsEditing); cs = ctxt.EntityContainer.GetChanges(); Assert.AreEqual(1, cs.ModifiedEntities.Count); }
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!"); }