public virtual void HandleResponseEvent(object sender, ResponseEventArgs e) { AstoriaResponse response = e.Response; AstoriaRequest request = response.Request; KeyExpression keyExp = null; RowEntityType entityRow = null; PredicateExpression exp = null; bool linkUpdate = false; string linkProperty = ""; // don't track error responses if ((int)response.ActualStatusCode >= 400) return; // special case for ETags if (response.ActualStatusCode == System.Net.HttpStatusCode.NotModified) return; // don't track changes that would fail if (request.ErrorExpected) return; if (request.DefaultExpectedStatusCode() != request.ExpectedStatusCode) return; // Can't handle updates withouth update tree or queries if (request.UpdateTree == null && request.Payload != null) this.SkipContentVerification = true; if (request.Query == null) this.SkipContentVerification = true; if (this.SkipContentVerification) return; RequestVerb verb = request.Verb; if (request.TunnelledVerb != null) verb = (RequestVerb)request.TunnelledVerb; switch (verb) { case RequestVerb.Delete: DeleteParams deleteParams = DeleteVisit(null, request.Query, new DeleteParams()); if (deleteParams.LinkUpdate) { entityRow = FindRowInstance(deleteParams.Source); List<RowEntityType> resourceList = _resources[entityRow.EntitySet]; if (deleteParams.Property.Type is CollectionType) { // Delete /FailureSet(1)/Configs/$ref?$id=Configs(1) RowEntityType removeRow = FindRowInstance(deleteParams.Target); ((IList)entityRow.Properties[deleteParams.Property.Name]).Remove(removeRow); } else { // Delete /Vehicles(1)/OldDrivers/$ref entityRow.Properties[deleteParams.Property.Name] = null; } } else { if (deleteParams.Property == null) { // Delete /Vehicles(1) entityRow = FindRowInstance(deleteParams.Target); List<RowEntityType> resourceList = _resources[entityRow.EntitySet]; resourceList.Remove(entityRow); } else if (deleteParams.Property.IsNavigation) { if (deleteParams.Property.Type is CollectionType) { // Delete /FailureSet(1)/Configs(1) entityRow = FindRowInstance(deleteParams.Source); RowEntityType propertyEntityRow = FindRowInstance(deleteParams.Target); // remove from Source entity's property list ((IList)entityRow.Properties[deleteParams.Property.Name]).Remove(propertyEntityRow); // remove entity from its own list List<RowEntityType> resourceList = _resources[entityRow.EntitySet]; resourceList.Remove(propertyEntityRow); } else { // Delete /Vehicles(1)/OldDrivers entityRow = FindRowInstance(deleteParams.Target); RowEntityType propertyEntityRow = (RowEntityType)entityRow.Properties[deleteParams.Property.Name]; List<RowEntityType> resourceList = _resources[entityRow.EntitySet]; resourceList.Remove(propertyEntityRow); entityRow.Properties[deleteParams.Property.Name] = null; } } else if (deleteParams.IsValue) { entityRow.Properties[deleteParams.Property.Name] = null; } } break; case RequestVerb.Post: if (request.Query.Input.Type is ResourceType) { AddNewEntity((KeyedResourceInstance)request.UpdateTree, (ResourceType)request.Query.Input.Type); } else if (request.Query.Input.Type is ResourceCollection) { NavigationExpression ne = (NavigationExpression)request.Query.Input; linkProperty = ne.Property.Name; keyExp = (KeyExpression)((PredicateExpression)ne.Input).Predicate; entityRow = FindRowInstance(keyExp); AddEntityToCollection((KeyedResourceInstance)request.UpdateTree, entityRow, linkProperty); } break; case RequestVerb.Patch: case RequestVerb.Put: bool replace = false; if (request.Verb == RequestVerb.Put) replace = true; if (request.Query is PredicateExpression) exp = (PredicateExpression)request.Query; else if (request.Query is ProjectExpression) { ProjectExpression projectExp = (ProjectExpression)request.Query; if (projectExp.Input is NavigationExpression) { NavigationExpression ne = (NavigationExpression)projectExp.Input; linkProperty = ne.Property.Name; exp = (PredicateExpression)ne.Input; linkUpdate = true; } else if (projectExp.Input is PredicateExpression) { exp = (PredicateExpression)projectExp.Input; } else { throw new TestException(TestResult.Warning, "Unhandled query expression - " + request.Query.GetType().Name); } } else throw new TestException(TestResult.Warning, "Unhandled query expression - " + request.Query.GetType().Name); keyExp = (KeyExpression)exp.Predicate; entityRow = FindRowInstance(keyExp); if (request.UpdateTree is ResourceInstanceSimpleProperty) { ResourceInstanceSimpleProperty singleProperty = (ResourceInstanceSimpleProperty)request.UpdateTree; ModifyProperty(singleProperty, entityRow); } else if (request.UpdateTree is ResourceInstanceComplexProperty) { ResourceInstanceComplexProperty complexProperty = (ResourceInstanceComplexProperty)request.UpdateTree; ModifyProperty(complexProperty, entityRow); } else if (request.UpdateTree is KeyedResourceInstance) { KeyedResourceInstance updateTree = (KeyedResourceInstance)request.UpdateTree; if (linkUpdate) UpdateLink(updateTree, entityRow, linkProperty); else ModifyProperties(updateTree, entityRow, replace); } else throw new TestException(TestResult.Failed, "Unhandled UpdateTree - " + request.UpdateTree.GetType().Name); break; default: break; } }
private static void SnapshotAfterUpdate(object sender, ResponseEventArgs args) { args.Response.Request.AfterUpdatePayload = SnapshotEntityState(args.Response.Request); }
private static void SnapshotAfterUpdate(object sender, ResponseEventArgs args) { args.Response.Request.AfterUpdatePayload = SnapshotEntityState(args.Response.Request); }