private string GetAtom(ODataOperation operation) { StringBuilder sb = new StringBuilder(); if (operation is ODataAction) { sb.Append("<action"); } else if (operation is ODataFunction) { sb.Append("<function"); } else { throw new ArgumentException(); } sb.Append(" metadata=\""); sb.Append(TestUriUtils.ToEscapedUriString(operation.Metadata)); sb.Append("\" title=\""); sb.Append(operation.Title); sb.Append("\" target=\""); sb.Append(operation.Target.OriginalString); sb.Append("\" xmlns=\""); sb.Append(TestAtomConstants.ODataMetadataNamespace); sb.Append("\" />"); return(sb.ToString()); }
/// <summary> /// Helper method to create the expected result callback for a URI test. /// </summary> /// <param name="uri">The URI that is the expected result.</param> /// <param name="testCase">The <see cref="UriTestCase"/> to create the result callback for.</param> /// <returns>The expected result callback for a URI test.</returns> private PayloadWriterTestDescriptor.WriterTestExpectedResultCallback CreateUriTestCaseExpectedResultCallback( Uri baseUri, Uri uri, UriTestCase testCase) { return((testConfiguration) => { if (testConfiguration.Format == ODataFormat.Json) { // In JSON we always expect an absolute URI string absoluteEscapedUri = TestUriUtils.ToAbsoluteUriString(uri, baseUri); return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = "\"" + absoluteEscapedUri + "\"", FragmentExtractor = json => testCase.JsonExtractor(testConfiguration, json) }; } else { throw new NotSupportedException("Unsupported format " + testConfiguration.Format.ToString() + " found."); } }); }
private static void CreateResultTemplates( string baseUri, string workspaceName, IEnumerable <CollectionInfo> collections, IEnumerable <SingletonInfo> singletons, out string xmlResultTemplate, out string[] jsonLightResultTemplate) { Debug.Assert(baseUri != null, "baseUri != null"); List <string> xmlLines = new List <string>(); List <string> jsonLightLines = new List <string>(); xmlLines.Add(@"<service xml:base=""" + baseUri + @""" xmlns=""http://www.w3.org/2007/app"" xmlns:atom=""http://www.w3.org/2005/Atom"">"); xmlLines.Add(@"$(Indent)<serviceDocument>"); jsonLightLines.Add("{"); jsonLightLines.Add(@"$(Indent)""" + JsonLightConstants.ODataContextAnnotationName + @""":""" + TestUriUtils.ToEscapedUriString(JsonLightConstants.DefaultMetadataDocumentUri) + @""",""value"":["); if (workspaceName == null) { workspaceName = TestAtomConstants.AtomWorkspaceDefaultTitle; } xmlLines.Add(@"$(Indent)$(Indent)<atom:title type='text'>" + workspaceName + "</atom:title>"); StringBuilder jsonLightBuilder = new StringBuilder(); if (collections != null) { foreach (var collection in collections) { xmlLines.Add(@"$(Indent)$(Indent)<collection href=""" + collection.Url + @""">"); if (collection.Name != null || collection.TitleAnnotation != null) { string titleValue = collection.TitleAnnotation ?? collection.Name; xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title type='text'>" + titleValue + @"</atom:title>"); } else { xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title />"); } xmlLines.Add(@"$(Indent)$(Indent)</collection>"); if (jsonLightBuilder.Length > 0) { jsonLightBuilder.Append(","); } jsonLightBuilder.Append("{"); jsonLightBuilder.Append("$(NL)"); jsonLightBuilder.Append(@"$(Indent)$(Indent)$(Indent)""name"":""" + collection.Name + "\","); jsonLightBuilder.Append(@"""url"":""" + collection.Url + "\""); jsonLightBuilder.Append(@"$(NL)"); jsonLightBuilder.Append("$(Indent)$(Indent)}"); } jsonLightLines.Add("$(Indent)$(Indent)" + jsonLightBuilder.ToString()); } else { jsonLightLines.Add("$(Indent)$(Indent)"); } if (singletons != null) { foreach (var singleton in singletons) { xmlLines.Add(@"$(Indent)$(Indent)<singleton href=""" + singleton.Url + @""">"); if (singleton.Name != null || singleton.TitleAnnotation != null) { string titleValue = singleton.TitleAnnotation ?? singleton.Name; xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title type='text'>" + titleValue + @"</atom:title>"); } else { xmlLines.Add(@"$(Indent)$(Indent)$(Indent)<atom:title />"); } xmlLines.Add(@"$(Indent)$(Indent)</collection>"); if (jsonLightBuilder.Length > 0) { jsonLightBuilder.Append(","); } jsonLightBuilder.Append("{"); jsonLightBuilder.Append("$(NL)"); jsonLightBuilder.Append(@"$(Indent)$(Indent)$(Indent)""name"":""" + singleton.Name + "\","); jsonLightBuilder.Append(@"""url"":""" + singleton.Url + "\""); jsonLightBuilder.Append(@"$(NL)"); jsonLightBuilder.Append("$(Indent)$(Indent)}"); } jsonLightLines.Add("$(Indent)$(Indent)" + jsonLightBuilder.ToString()); } else { jsonLightLines.Add("$(Indent)$(Indent)"); } xmlLines.Add(@"$(Indent)</serviceDocument>"); xmlLines.Add(@"</service>"); jsonLightLines.Add("$(Indent)]"); jsonLightLines.Add("}"); xmlResultTemplate = string.Join("$(NL)", xmlLines); jsonLightResultTemplate = jsonLightLines.ToArray(); }