private void VerifyQueryResult(ODataRequest request, ODataResponse response, FunctionSegment functionSegment, IVerifyServiceActionQueryResult verifyServiceQueryResult) { EntitySet expectedBindingEntitySet = null; var actionLessUri = ConstructODataUriWithoutActionInformation(this.entityModelSchema.GetDefaultEntityContainer().EntitySets, request.Uri); bool entitySetFound = actionLessUri.TryGetExpectedEntitySet(out expectedBindingEntitySet); ExceptionUtilities.Assert(entitySetFound, "EntitySet not found for Uri {0}", actionLessUri.ToString()); // SDP never applies for actions var preActionQueryValueResult = this.ODataUriEvaluator.Evaluate(actionLessUri, true, false); IDictionary <string, QueryValue> queryValueParametersLookup = new Dictionary <string, QueryValue>(); if (request.Body != null) { queryValueParametersLookup = this.CreateQueryValueParameters(request, functionSegment, queryValueParametersLookup); } var expected = verifyServiceQueryResult.GetExpectedQueryValue(preActionQueryValueResult, queryValueParametersLookup.Values.ToArray()); HttpStatusCode expectedStatusCode = CalculateExpectedStatusCode(functionSegment); string expectedETag = null; SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, expectedBindingEntitySet.Name)); expectedETag = this.VerifyExpected(request, response, expected, expectedStatusCode, expectedETag); ETagHeaderVerifier etagHeaderVerifier = new ETagHeaderVerifier(); etagHeaderVerifier.Verify(expectedETag, request, response); }
private void ExecuteAndCatchErrors(ODataRequest request, ODataResponse response, Action action) { try { action(); } catch (Exception ex) { request.WriteToLog(this.Logger, LogLevel.Verbose); response.WriteToLog(this.Logger, LogLevel.Verbose); #if !SILVERLIGHT if (this.Synchronizer != null) { EntitySet entitySet; if (request.Uri.TryGetExpectedEntitySet(out entitySet)) { try { SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, entitySet.Name)); } catch (Exception syncException) { this.Logger.WriteLine(LogLevel.Error, "Failed to synchronize set '{0}'", entitySet.Name); this.Logger.WriteLine(LogLevel.Error, syncException.ToString()); } } } #endif throw new AssertionFailedException("Failed to deserialize response body", ex); } }
/// <summary> /// Gets the pre and post update representations of the entity updated by the given request /// </summary> /// <param name="request">The request</param> /// <param name="beforeUpdate">The entity before the update</param> /// <param name="afterUpdate">The entity after the update</param> public void GetUpdatedEntity(ODataRequest request, out QueryStructuralValue beforeUpdate, out QueryStructuralValue afterUpdate) { ExceptionUtilities.CheckArgumentNotNull(request, "request"); ExceptionUtilities.Assert(this.requestsBegun.Contains(request), "Cannot use GetUpdatedEntity before calling Begin"); ExceptionUtilities.Assert(request.GetEffectiveVerb().IsUpdateVerb(), "Cannot use GetUpdatedEntity on non update requests"); KeyValuePair <QueryStructuralValue, QueryStructuralValue> beforeAndAfter; if (!this.updatedEntityCache.TryGetValue(request, out beforeAndAfter)) { var entityUri = request.Uri.ScopeToEntity(); var entity = (QueryStructuralValue)this.Evaluator.Evaluate(entityUri, false, false); beforeUpdate = this.QueryValueCopier.PerformDeepCopy(entity); SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntity(c, entity)); afterUpdate = entity; beforeAndAfter = new KeyValuePair <QueryStructuralValue, QueryStructuralValue>(beforeUpdate, afterUpdate); this.updatedEntityCache[request] = beforeAndAfter; } else { beforeUpdate = beforeAndAfter.Key; afterUpdate = beforeAndAfter.Value; } }
public static void ExecuteUriAndCompareSync <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError) { #if !SILVERLIGHT SyncHelpers.ExecuteActionAndWait(c => linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(c, false, query, uriString, expectedValue, dataContext, clientExpectedError)); #else throw new TaupoInvalidOperationException("Cannot execute in Silverlight"); #endif }
/// <summary> /// Executes SaveChanges on the specified context and with specified options and verifies the results. /// </summary> /// <param name="verifier">The verifier to use for verification.</param> /// <param name="contextData">The data for the context.</param> /// <param name="context">The context to verify SaveChanges on.</param> /// <param name="options">The options for saving changes.</param> /// <returns>The response from SaveChanges</returns> public static DSClient.DataServiceResponse VerifySaveChanges(this ISaveChangesVerifier verifier, DataServiceContextData contextData, DSClient.DataServiceContext context, SaveChangesOptions?options) { ExceptionUtilities.CheckArgumentNotNull(verifier, "verifier"); ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData"); ExceptionUtilities.CheckArgumentNotNull(context, "context"); DSClient.DataServiceResponse response = null; SyncHelpers.ExecuteActionAndWait(c1 => verifier.VerifySaveChanges(c1, contextData, context, options, (c2, r) => { response = r; c2.Continue(); })); return(response); }
/// <summary> /// Executes SaveChanges on the specified context and with specified options and verifies the results. /// </summary> /// <param name="verifier">The verifier to use for verification.</param> /// <param name="contextData">The data for the context.</param> /// <param name="context">The context to verify SaveChanges on.</param> /// <param name="options">The options for saving changes.</param> /// <returns>The response from SaveChanges</returns> public static DSClient.DataServiceResponse VerifySaveChanges(this ISaveChangesVerifier verifier, DataServiceContextData contextData, DSClient.DataServiceContext context, SaveChangesOptions? options) { #if SILVERLIGHT throw new TaupoNotSupportedException("Not supported in Silverlight"); #else ExceptionUtilities.CheckArgumentNotNull(verifier, "verifier"); ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData"); ExceptionUtilities.CheckArgumentNotNull(context, "context"); DSClient.DataServiceResponse response = null; SyncHelpers.ExecuteActionAndWait(c1 => verifier.VerifySaveChanges(c1, contextData, context, options, (c2, r) => { response = r; c2.Continue(); })); return response; #endif }
private QueryValue SynchronizeAndEvaluate(ODataUri entityUri, QueryStructuralValue beforeSync, bool synchronizeEntireSet) { var entityType = beforeSync.Type as QueryEntityType; ExceptionUtilities.CheckObjectNotNull(entityType, "Structural value was not an entity type"); // if an entity was deleted, synchronize the entire set. Otherwise just synchronize the entity if (synchronizeEntireSet) { SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, entityType.EntitySet.Name)); } else { SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntity(c, beforeSync)); } return(this.Evaluator.Evaluate(entityUri, false, false)); }
/// <summary> /// Gets the entity inserted by the given request. /// </summary> /// <param name="request">The request</param> /// <param name="response">The response</param> /// <returns>The inserted entity</returns> public QueryStructuralValue GetInsertedEntity(ODataRequest request, ODataResponse response) { ExceptionUtilities.CheckArgumentNotNull(request, "request"); ExceptionUtilities.CheckArgumentNotNull(response, "response"); ExceptionUtilities.Assert(this.requestsBegun.Contains(request), "Cannot use GetInsertedEntity before calling Begin"); ExceptionUtilities.Assert(request.GetEffectiveVerb() == HttpVerb.Post, "Cannot use GetInsertedEntity on non POST requests"); QueryStructuralValue insertedEntity; if (!this.insertedEntityCache.TryGetValue(request, out insertedEntity)) { EntitySet entitySet; ExceptionUtilities.Assert(request.Uri.TryGetExpectedEntitySet(out entitySet), "Could not infer entity set from URI"); var entitySetUri = new ODataUri(new EntitySetSegment(entitySet)); var beforeSync = this.Evaluator.Evaluate(entitySetUri, false, false) as QueryCollectionValue; ExceptionUtilities.CheckObjectNotNull(beforeSync, "Could not evaluate entity set '{0}' before syncing", entitySet.Name); // create a shallow copy beforeSync = beforeSync.Type.CreateCollectionWithValues(beforeSync.Elements); SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, entitySet.Name)); var afterSync = this.Evaluator.Evaluate(entitySetUri, false, false) as QueryCollectionValue; ExceptionUtilities.CheckObjectNotNull(afterSync, "Could not evaluate entity set '{0}' after syncing", entitySet.Name); // TODO: handle deep insert (using location header or response payload) var newElements = afterSync.Elements.Except(beforeSync.Elements).OfType <QueryStructuralValue>().ToList(); this.insertedEntityCache[request] = insertedEntity = newElements.Single(); // update the parent entity, if there is one var segments = request.Uri.Segments; var lastNavigationSegment = segments.OfType <NavigationSegment>().LastOrDefault(); if (lastNavigationSegment != null) { var segmentsBeforeNavigation = segments.TakeWhile(t => t != lastNavigationSegment); var parentEntity = (QueryStructuralValue)this.Evaluator.Evaluate(new ODataUri(segmentsBeforeNavigation), false, false); SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntity(c, parentEntity)); } } return(insertedEntity); }
public static void ExecuteUriAndCompareSync <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError) { SyncHelpers.ExecuteActionAndWait(c => linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(c, false, query, uriString, expectedValue, dataContext, clientExpectedError)); }