/// <summary> /// Verifies the delete succeeded /// </summary> /// <param name="request">The request to verify</param> /// <param name="response">The response to verify</param> public override void Verify(ODataRequest request, ODataResponse response) { base.Verify(request, response); var originalUri = request.Uri; var entityUri = originalUri.ScopeToEntity(); var beforeSync = this.Evaluator.Evaluate(entityUri, false, false) as QueryStructuralValue; ExceptionUtilities.CheckObjectNotNull(beforeSync, "Could not get entity before syncing"); ExceptionUtilities.Assert(!beforeSync.IsNull, "Entity was null before syncing"); var afterSync = this.SynchronizeAndEvaluate(entityUri, beforeSync, originalUri.IsEntity()); QueryValue currentValue = afterSync; string message = null; if (originalUri.IsEntity()) { // DELETE Customers(1) message = "Entity was not deleted"; } else if (originalUri.IsPropertyValue()) { // DELETE Customers(1)/Name/$value message = "Property value was not null"; // drill down by each property in the uri after the entity portion foreach (var propertySegment in originalUri.Segments.Skip(entityUri.Segments.Count).OfType <PropertySegment>()) { currentValue = ((QueryStructuralValue)currentValue).GetValue(propertySegment.Property.Name); } } else if (originalUri.IsEntityReferenceLink()) { // TODO: verify back-links? var navigation = originalUri.Segments.OfType <NavigationSegment>().Last(); if (navigation.NavigationProperty.ToAssociationEnd.Multiplicity == EndMultiplicity.Many) { // DELETE Customers(1)/Orders/$ref?$id=Orders(1) message = "Collection link was not deleted"; var linkUri = new ODataUri(entityUri.Segments.Concat(navigation, originalUri.Segments.OfType <KeyExpressionSegment>().Last())); currentValue = this.Evaluator.Evaluate(linkUri, false, false); } else { // DELETE Customers(1)/BestFriend/$ref message = "Reference link was not deleted"; currentValue = ((QueryStructuralValue)afterSync).GetValue(navigation.NavigationProperty.Name); } } // at this point, the current value should be null if the delete was successful ExceptionUtilities.CheckObjectNotNull(message, "Uri did not represent an entity, value, or link: '{0}'", request.GetRequestUri()); this.Assert(currentValue.IsNull, message, request, response); if (originalUri.IsEntity()) { this.RequeryEntityAndVerifyStatusCode(request, response, entityUri); if (entityUri.Segments.OfType <NavigationSegment>().Any()) { // convert the uri into a top-level access entityUri = GetTopLevelUri(beforeSync); entityUri.Segments.Insert(0, originalUri.Segments.OfType <ServiceRootSegment>().Single()); this.RequeryEntityAndVerifyStatusCode(request, response, entityUri); } } }
/// <summary> /// Verifies the delete succeeded /// </summary> /// <param name="request">The request to verify</param> /// <param name="response">The response to verify</param> public override void Verify(ODataRequest request, ODataResponse response) { base.Verify(request, response); var originalUri = request.Uri; var entityUri = originalUri.ScopeToEntity(); var beforeSync = this.Evaluator.Evaluate(entityUri, false, false) as QueryStructuralValue; ExceptionUtilities.CheckObjectNotNull(beforeSync, "Could not get entity before syncing"); ExceptionUtilities.Assert(!beforeSync.IsNull, "Entity was null before syncing"); var afterSync = this.SynchronizeAndEvaluate(entityUri, beforeSync, originalUri.IsEntity()); QueryValue currentValue = afterSync; string message = null; if (originalUri.IsEntity()) { // DELETE Customers(1) message = "Entity was not deleted"; } else if (originalUri.IsPropertyValue()) { // DELETE Customers(1)/Name/$value message = "Property value was not null"; // drill down by each property in the uri after the entity portion foreach (var propertySegment in originalUri.Segments.Skip(entityUri.Segments.Count).OfType<PropertySegment>()) { currentValue = ((QueryStructuralValue)currentValue).GetValue(propertySegment.Property.Name); } } else if (originalUri.IsEntityReferenceLink()) { // TODO: verify back-links? var navigation = originalUri.Segments.OfType<NavigationSegment>().Last(); if (navigation.NavigationProperty.ToAssociationEnd.Multiplicity == EndMultiplicity.Many) { // DELETE Customers(1)/Orders/$ref?$id=Orders(1) message = "Collection link was not deleted"; var linkUri = new ODataUri(entityUri.Segments.Concat(navigation, originalUri.Segments.OfType<KeyExpressionSegment>().Last())); currentValue = this.Evaluator.Evaluate(linkUri, false, false); } else { // DELETE Customers(1)/BestFriend/$ref message = "Reference link was not deleted"; currentValue = ((QueryStructuralValue)afterSync).GetValue(navigation.NavigationProperty.Name); } } // at this point, the current value should be null if the delete was successful ExceptionUtilities.CheckObjectNotNull(message, "Uri did not represent an entity, value, or link: '{0}'", request.GetRequestUri()); this.Assert(currentValue.IsNull, message, request, response); if (originalUri.IsEntity()) { this.RequeryEntityAndVerifyStatusCode(request, response, entityUri); if (entityUri.Segments.OfType<NavigationSegment>().Any()) { // convert the uri into a top-level access entityUri = GetTopLevelUri(beforeSync); entityUri.Segments.Insert(0, originalUri.Segments.OfType<ServiceRootSegment>().Single()); this.RequeryEntityAndVerifyStatusCode(request, response, entityUri); } } }