protected string CreateCanonicalUri(ResourceInstanceKey key) { UriQueryBuilder builder = new UriQueryBuilder(Workspace, Workspace.ServiceUri); builder.UseBinaryFormatForDates = false; builder.CleanUpSpecialCharacters = false; KeyExpression keyExpression = ResourceInstanceUtil.ConvertToKeyExpression(key, Workspace); if (keyExpression != null) { QueryNode query = ContainmentUtil.BuildCanonicalQuery(keyExpression); return builder.Build(query); } IEnumerable<ResourceInstanceSimpleProperty> properties = key.KeyProperties.OfType<ResourceInstanceSimpleProperty>(); string keyString = builder.CreateKeyString(properties.Select(p => p.Name).ToArray(), properties.Select(p => p.PropertyValue).ToArray()); string uri = Workspace.ServiceUri + "/" + key.ResourceSetName + "(" + keyString + ")"; return uri; }
public void VerifyClient(QueryModel qm) { WebDataCtxWrapper ctx = new WebDataCtxWrapper(new Uri(qm.Workspace.ServiceUri)); ctx.Credentials = CredentialCache.DefaultNetworkCredentials; try { UriQueryBuilder ub = new UriQueryBuilder(qm.Workspace, ""); string ruri = ub.Build(qm.QueryResult); string uriRel = ruri.Substring(ruri.LastIndexOf(".svc/") + 5); if ((ctx.BaseUri + "/" + uriRel).Length > 260) { return; } AstoriaTestLog.WriteLineIgnore(ctx.BaseUri + "/" + uriRel); ResolveClientType(qm.Workspace, ctx, qm.ResultType); object enumerable = ExecuteQuery(ctx, qm.ResultType, uriRel, "sync"); Verify(qm.Workspace, qm.QueryResult, (IEnumerable)enumerable, qm.ResType, null, qm.IsCount); } catch (Exception e) { AstoriaTestLog.FailAndContinue(e); } }
public static string CreateKeyString(KeyExpression keyExp, bool binaryFormat) { Workspace w = keyExp.ResourceContainer.Workspace; UriQueryBuilder builder = new UriQueryBuilder(w, w.ServiceUri); builder.UseBinaryFormatForDates = binaryFormat; builder.CleanUpSpecialCharacters = true; return builder.CreateKeyString(keyExp); }
public void VerifyServer(ExpNode q) { AstoriaTestLog.WriteLineIgnore("Verify server query"); try { UriQueryBuilder ub = new UriQueryBuilder(_workspace, ""); string ruri = ub.Build(q); AstoriaTestLog.WriteLineIgnore(ruri); AstoriaRequest request = _workspace.CreateRequest(q); request.Format = _kind; if (request.URI.Length > 260) { return; } AstoriaResponse response = request.GetResponse(); response.Verify(); } catch (Exception e) { AstoriaTestLog.WriteLineIgnore(e.ToString()); } }
public void QueryEntities() { string entitySetName = ""; object entity = null; ResourceContainer resContainer = null; while (resContainer == null) { entity = GetResource(out entitySetName, out resContainer); } QueryModel queryModel = new QueryModel(workSpace, SerializationFormatKind.Atom, null); queryModel.RunningUnderScenarioModel = true; queryModel.ResContainer = resContainer; ModelEngine engine = new ModelEngine(queryModel); engine.Options.WeightScheme = WeightScheme.Custom; engine.Options.Timeout = Timeout; engine.Run(); UriQueryBuilder ub = new UriQueryBuilder(workSpace, ""); string ruri = ub.Build(queryModel.QueryResult); string uriRel = ruri.Substring(ruri.LastIndexOf(".svc/") + 5); if ((Context.BaseUri + "/" + uriRel).Length > 260) { return; } AstoriaTestLog.WriteLineIgnore(Context.BaseUri + "/" + uriRel); ResolveClientType(workSpace, Context, queryModel.ResultType); object enumerable = ExecuteQuery(Context, queryModel.ResultType, uriRel, "sync"); }
private static bool compareKeyURI(string uriFound, KeyExpression keyExpected) { UriQueryBuilder builder = new UriQueryBuilder(keyExpected.ResourceContainer.Workspace, keyExpected.ResourceContainer.Workspace.ServiceUri); builder.EscapeUriValues = true; builder.CleanUpSpecialCharacters = false; builder.UseBinaryFormatForDates = false; switch (keyExpected.IncludeInUri.Count(i => i)) { case 0: AstoriaTestLog.FailAndThrow("Cannot compare KeyExpression to URI, key has no included values"); return false; case 1: // TODO: stop ignoring case QueryNode query = ContainmentUtil.BuildCanonicalQuery(keyExpected); string expected = builder.Build(query); expected = expected.Replace(".0f", "f"); //this is kinda a hack, but TypeData.FormatForKey is going to add the .0, so we need to remove it expected = expected.Replace(".0D", "D"); //this is kinda a hack, but TypeData.FormatForKey is going to add the .0, so we need to remove it bool match = uriFound.Equals(expected, StringComparison.InvariantCultureIgnoreCase); if (!match) AstoriaTestLog.WriteLineIgnore("Link did not match key, expected '" + expected + "'"); return match; default: QueryNode setQuery = ContainmentUtil.BuildCanonicalQuery(keyExpected, true); Workspace w = keyExpected.ResourceContainer.Workspace; string setUri = builder.Build(setQuery); string keySegment = uriFound.Substring(setUri.Length); string expectedKeySegment = "(" + UriQueryBuilder.CreateKeyString(keyExpected, false) + ")"; if (keySegment.Equals(expectedKeySegment, StringComparison.InvariantCultureIgnoreCase)) return true; // if not explicitely equal, need to make sure its not due to a re-ordering of the properties // List<KeyValuePair<string, int>> predicateLocations = new List<KeyValuePair<string, int>>(); for (int i = 0; i < keyExpected.Values.Length; i++) { string predicate = builder.CreateKeyStringPair(keyExpected.Properties[i].Name, keyExpected.Values[i].ClrValue); int offset = keySegment.IndexOf(predicate); if (offset < 0) return false; predicateLocations.Add(new KeyValuePair<string, int>(predicate, offset)); } predicateLocations.Sort(delegate(KeyValuePair<string, int> pair1, KeyValuePair<string, int> pair2) { return pair1.Value.CompareTo(pair2.Value); }); expectedKeySegment = "(" + String.Join(",", predicateLocations.Select(pair => pair.Key).ToArray()) + ")"; return keySegment.Equals(expectedKeySegment, StringComparison.InvariantCultureIgnoreCase); } }
protected virtual void RefreshURI() { if (Query_Internal != null) { UriQueryBuilder uriBuilder = new UriQueryBuilder(Workspace, Workspace.ServiceUri); URI_Internal = uriBuilder.Build(Query_Internal); } else URI_Internal = Workspace.ServiceUri; }
private static void UpdateErrorState(ContainmentQuery query, ContainmentQuerySuffix suffix, RequestVerb verb) { if (!MethodAllowed(query, suffix, verb)) { // TODO: set error identifier? query.ExpectedStatusCode = HttpStatusCode.MethodNotAllowed; switch (verb) { case RequestVerb.Post: query.ExpectedErrorIdentifier = SystemDataServicesResourceIdentifiers.BadRequest_InvalidUriForPostOperation; UriQueryBuilder builder = new UriQueryBuilder(query.Workspace, query.Workspace.ServiceEndPoint); query.ExpectedErrorArgs = new object[] { builder.Build(query.Query) }; break; } } }