示例#1
0
        public void FalseCountIsDefaultValue()
        {
            foreach (var mimeType in mimeTypes)
            {
                var url            = "/Computer";
                var requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.OriginalString + url, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);

                var defaultResponsestring = this.GetResponseContent(requestMessage);

                url            = "/Computer?$count=false";
                requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.OriginalString + url, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);

                var responseString = this.GetResponseContent(requestMessage);

                if (mimeType == MimeTypes.ApplicationAtomXml)
                {
                    // resulting atom payloads with/without model should be the same except for the updated time stamps
                    const string pattern     = @"<updated>([A-Za-z0-9\-\:]{20})\</updated>";
                    const string replacement = "<updated>0000-00-00T00:00:00Z</updated>";
                    defaultResponsestring = Regex.Replace(defaultResponsestring, pattern, (match) => replacement);
                    responseString        = Regex.Replace(responseString, pattern, (match) => replacement);
                }

                Assert.AreEqual(defaultResponsestring, responseString);
            }
        }
示例#2
0
        public void CountPayloadVerification()
        {
            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.OriginalString + "/Customer?$count=true", UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);

                var responseString = this.GetResponseContent(requestMessage);

                if (mimeType.Contains(MimeTypes.ApplicationJson))
                {
                    if (mimeType.Contains(MimeTypes.ODataParameterIEEE754Compatible))
                    {
                        Assert.IsTrue(responseString.Contains("\"@odata.count\":\"10\""));
                    }
                    else
                    {
                        Assert.IsTrue(responseString.Contains("\"@odata.count\":10"));
                    }
                }
                else
                {
                    Assert.IsTrue(responseString.Contains("<m:count>10</m:count>"));
                }
            }
        }
        /// <summary>
        /// Specifically use to query single entry or multi entries(query with $expand)
        /// </summary>
        /// <param name="requestUri"></param>
        /// <param name="mimeType"></param>
        /// <returns></returns>
        public List<ODataEntry> QueryEntries(string requestUri, string mimeType)
        {
            List<ODataEntry> entries = new List<ODataEntry>();

            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = baseUri };
            var requestMessage = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + requestUri, UriKind.Absolute));
            requestMessage.SetHeader("Accept", mimeType);
            var responseMessage = requestMessage.GetResponse();
            Assert.AreEqual(200, responseMessage.StatusCode);

            if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
            {
                using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, model))
                {
                    var reader = messageReader.CreateODataEntryReader();

                    while (reader.Read())
                    {
                        if (reader.State == ODataReaderState.EntryEnd)
                        {
                            entries.Add(reader.Item as ODataEntry);
                        }
                    }
                    Assert.AreEqual(ODataReaderState.Completed, reader.State);
                }
            }
            return entries;
        }
示例#4
0
        private string GetResponseContent(HttpWebRequestMessage requestMessage)
        {
            var response     = requestMessage.GetResponse();
            var stream       = response.GetStream();
            var streamReader = new StreamReader(stream);

            return(streamReader.ReadToEnd());
        }
        public static IEdmModel GetServiceModel(Uri uri)
        {
            HttpWebRequestMessage message = new HttpWebRequestMessage(uri);
            message.SetHeader("Accept", MimeTypes.ApplicationXml);

            using (var messageReader = new ODataMessageReader(message.GetResponse()))
            {
                return messageReader.ReadMetadataDocument();
            }
        }
示例#6
0
        /// <summary>
        /// Get the metadata document from the test service as an IEdmModel
        /// </summary>
        protected IEdmModel RetrieveServiceEdmModel()
        {
            Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage message = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + "$metadata", UriKind.Absolute));
            message.SetHeader("Accept", MimeTypes.ApplicationXml);

            using (var messageReader = new ODataMessageReader(message.GetResponse()))
            {
                return(messageReader.ReadMetadataDocument());
            }
        }
        public override void CustomTestInitialize()
        {
            // retrieve IEdmModel of the test service
            HttpWebRequestMessage message = new HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + "$metadata", UriKind.Absolute));
            message.SetHeader("Accept", MimeTypes.ApplicationXml);

            using (var messageReader = new ODataMessageReader(message.GetResponse()))
            {
                this.model = messageReader.ReadMetadataDocument();
            }
        }
        private void PrimitiveValueInFilterInURL(string filterQuery)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings()
            {
                BaseUri = this.ServiceUri
            };

            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + filterQuery, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);
                var responseMessage = requestMessage.GetResponse();
                Assert.AreEqual(200, responseMessage.StatusCode);

                if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, RetrieveServiceEdmModel()))
                    {
                        var reader = messageReader.CreateODataFeedReader();

                        while (reader.Read())
                        {
                            if (reader.State == ODataReaderState.EntryEnd)
                            {
                                string pattern = filterQuery.Substring(0, filterQuery.IndexOf("?")) + @"\(" + dataPattern + @"\)$";
                                Regex  rgx     = new Regex(pattern, RegexOptions.IgnoreCase);

                                ODataEntry entry = reader.Item as ODataEntry;
                                Assert.IsTrue(rgx.Match(entry.Id.ToString()).Success, "Expected : Entry's Id doesn't contain trailing when Key is Int64/float/double/decimal");
                                if (mimeType.Equals(MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata))
                                {
                                    Assert.IsTrue(rgx.Match(entry.EditLink.ToString()).Success, "Expected : Entry's EditLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                    Assert.IsTrue(rgx.Match(entry.ReadLink.ToString()).Success, "Expected : Entry's ReadLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                }
                            }
                            else if (reader.State == ODataReaderState.FeedEnd)
                            {
                                //TODO: Nextlink is appened by data service. So whether L|F|D|M could be returned in nextLink
                                var       pattern = filterQuery.Substring(0, filterQuery.IndexOf("?")) + @"\?\$filter=Id\sge\s" + dataPattern + @"(L|F|D|M)?&\$skiptoken=\d+$";
                                Regex     rgx     = new Regex(pattern, RegexOptions.IgnoreCase);
                                ODataFeed feed    = reader.Item as ODataFeed;
                                Assert.IsTrue(rgx.Match(feed.NextPageLink.ToString()).Success, "Expected : Feed's NextLink doesn't contain trailing when Key is Int64/float/double/decimal");
                            }
                        }
                        Assert.AreEqual(ODataReaderState.Completed, reader.State);
                    }
                }
            }
        }
        private void PrimitiveValueInSkipTokenInURL(string skipTokenQuery)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings()
            {
                BaseUri = this.ServiceUri
            };

            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + skipTokenQuery, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);
                var responseMessage = requestMessage.GetResponse();
                Assert.AreEqual(200, responseMessage.StatusCode);

                if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, RetrieveServiceEdmModel()))
                    {
                        var reader = messageReader.CreateODataResourceSetReader();

                        while (reader.Read())
                        {
                            if (reader.State == ODataReaderState.ResourceEnd)
                            {
                                string pattern = skipTokenQuery.Substring(0, skipTokenQuery.IndexOf("?")) + "/" + dataPattern + "$";
                                Regex  rgx     = new Regex(pattern, RegexOptions.IgnoreCase);

                                ODataResource entry = reader.Item as ODataResource;
                                Assert.IsTrue(rgx.Match(entry.Id.ToString()).Success, "Expected : Entry's Id doesn't contain trailing when Key is Int64/float/double/decimal");
                                if (mimeType.Equals(MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata))
                                {
                                    Assert.IsTrue(rgx.Match(entry.EditLink.ToString()).Success, "Expected : Entry's EditLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                    Assert.IsTrue(rgx.Match(entry.ReadLink.ToString()).Success, "Expected : Entry's ReadLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                }
                            }
                            else if (reader.State == ODataReaderState.ResourceSetEnd)
                            {
                                var              pattern = skipTokenQuery.Substring(0, skipTokenQuery.IndexOf("?")) + @"\?\$skiptoken=" + dataPattern + "$";
                                Regex            rgx     = new Regex(pattern, RegexOptions.IgnoreCase);
                                ODataResourceSet feed    = reader.Item as ODataResourceSet;
                                Assert.IsTrue(rgx.Match(feed.NextPageLink.ToString()).Success, "Expected : Feed's NextLink doesn't contain trailing when Key is Int64/float/double/decimal");
                            }
                        }
                        Assert.AreEqual(ODataReaderState.Completed, reader.State);
                    }
                }
            }
        }
示例#10
0
        public void ValidServiceDocument()
        {
            var metadataMessage = new HttpWebRequestMessage(new Uri(ServiceUri + "$metadata"));
            metadataMessage.SetHeader("Accept", MimeTypes.ApplicationXml);

            var metadataMessageReader = new ODataMessageReader(metadataMessage.GetResponse());
            var model = metadataMessageReader.ReadMetadataDocument();

            var message = new HttpWebRequestMessage(ServiceUri);
            message.SetHeader("Accept", MimeTypes.ApplicationJson);
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = ServiceUri };

            using (var messageReader = new ODataMessageReader(message.GetResponse(), readerSettings, model))
            {
                var workspace = messageReader.ReadServiceDocument();
                Assert.AreEqual(21, workspace.EntitySets.Count(e => e.Name.StartsWith("EF")));
                Assert.AreEqual(24, workspace.EntitySets.Count(e => !e.Name.StartsWith("EF")));
            }
        }
示例#11
0
        public void ValidMetadata()
        {
            var message = new HttpWebRequestMessage(new Uri(ServiceUri + "$metadata"));

            message.SetHeader("Accept", MimeTypes.ApplicationXml);

            using (var messageReader = new ODataMessageReader(message.GetResponse()))
            {
                var model     = messageReader.ReadMetadataDocument();
                var container = model.EntityContainer;

                // Verify all the entities are exposed
                var entities = container.Elements.Where(e => e is IEdmEntitySet).ToArray();
                Assert.AreEqual(24, entities.Count());

                // Verify all the service operations are exposed
                var functions = container.Elements.Where(e => e is IEdmOperationImport).ToArray();
                Assert.AreEqual(3, functions.Count());
            }
        }
        private void PrimitiveValueAsKeyInURL(string keySegment)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings()
            {
                BaseUri = this.ServiceUri
            };

            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + keySegment, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);
                var responseMessage = requestMessage.GetResponse();
                Assert.AreEqual(200, responseMessage.StatusCode);

                if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, RetrieveServiceEdmModel()))
                    {
                        var reader = messageReader.CreateODataEntryReader();

                        while (reader.Read())
                        {
                            if (reader.State == ODataReaderState.EntryEnd)
                            {
                                var        expectedKeySegment = keySegment.Substring(0, keySegment.IndexOf("(")) + "(1)";
                                ODataEntry entry = reader.Item as ODataEntry;
                                Assert.IsTrue(entry.Id.ToString().Contains(expectedKeySegment), "Expected : Entry's Id doesn't contain trailing when Key is Int64/float/double/decimal");
                                if (mimeType.Equals(MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata))
                                {
                                    Assert.IsTrue(entry.EditLink.ToString().Contains(expectedKeySegment), "Expected : Entry's EditLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                    Assert.IsTrue(entry.ReadLink.ToString().Contains(expectedKeySegment), "Expected : Entry's ReadLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                }
                            }
                        }
                        Assert.AreEqual(ODataReaderState.Completed, reader.State);
                    }
                }
            }
        }
        private void PrimitiveValueAsKeyInURL(string keySegment)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = this.ServiceUri };
            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + keySegment, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);
                var responseMessage = requestMessage.GetResponse();
                Assert.AreEqual(200, responseMessage.StatusCode);

                if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, RetrieveServiceEdmModel()))
                    {
                        var reader = messageReader.CreateODataEntryReader();

                        while (reader.Read())
                        {
                            if (reader.State == ODataReaderState.EntryEnd)
                            {
                                var expectedKeySegment = keySegment.Substring(0, keySegment.IndexOf("(")) + "(1)";
                                ODataEntry entry = reader.Item as ODataEntry;
                                Assert.IsTrue(entry.Id.ToString().Contains(expectedKeySegment), "Expected : Entry's Id doesn't contain trailing when Key is Int64/float/double/decimal");
                                if (mimeType.Equals(MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata))
                                {
                                    Assert.IsTrue(entry.EditLink.ToString().Contains(expectedKeySegment), "Expected : Entry's EditLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                    Assert.IsTrue(entry.ReadLink.ToString().Contains(expectedKeySegment), "Expected : Entry's ReadLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                }
                            }
                        }
                        Assert.AreEqual(ODataReaderState.Completed, reader.State);
                    }
                }
            }
        }
        public ODataProperty QueryProperty(string requestUri, string mimeType)
        {
            ODataProperty property = null;

            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = baseUri };
            var requestMessage = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + requestUri, UriKind.Absolute));

            requestMessage.SetHeader("Accept", mimeType);

            var responseMessage = requestMessage.GetResponse();
            Assert.AreEqual(200, responseMessage.StatusCode);

            if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
            {
                using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, model))
                {
                    property = messageReader.ReadProperty();
                }
            }
            return property;
        }
        public ODataFeed QueryInnerFeed(string requestUri, string mimeType)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = baseUri };
            var requestMessage = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + requestUri, UriKind.Absolute));
            requestMessage.SetHeader("Accept", mimeType);
            var responseMessage = requestMessage.GetResponse();
            Assert.AreEqual(200, responseMessage.StatusCode);

            if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
            {
                using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, model))
                {
                    var reader = messageReader.CreateODataEntryReader();

                    while (reader.Read())
                    {
                        if (reader.State == ODataReaderState.FeedEnd)
                        {
                            return (reader.Item as ODataFeed);
                        }
                    }

                }
            }
            return null;
        }
示例#16
0
        public void ValidServiceDocument()
        {
            var metadataMessage = new HttpWebRequestMessage(new Uri(ServiceUri + "$metadata"));
            metadataMessage.SetHeader("Accept", MimeTypes.ApplicationXml);

            var metadataMessageReader = new ODataMessageReader(metadataMessage.GetResponse());
            var model = metadataMessageReader.ReadMetadataDocument();

            var message = new HttpWebRequestMessage(ServiceUri);
            message.SetHeader("Accept", MimeTypes.ApplicationJson);
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = ServiceUri };

            using (var messageReader = new ODataMessageReader(message.GetResponse(), readerSettings, model))
            {
                var workspace = messageReader.ReadServiceDocument();
                Assert.AreEqual(21, workspace.EntitySets.Count(e => e.Name.StartsWith("EF")));
                Assert.AreEqual(24, workspace.EntitySets.Count(e => !e.Name.StartsWith("EF")));
            }
        }
示例#17
0
        public void ValidMetadata()
        {
            var message = new HttpWebRequestMessage(new Uri(ServiceUri + "$metadata"));
            message.SetHeader("Accept", MimeTypes.ApplicationXml);

            using (var messageReader = new ODataMessageReader(message.GetResponse()))
            {
                var model = messageReader.ReadMetadataDocument();
                var container = model.EntityContainer;
                var entities = container.Elements.Where(e => e is IEdmEntitySet).ToArray();

                // Verify all the ef entities are exposed
                Assert.AreEqual(21, entities.Count(e => e.Name.StartsWith("EF")));

                // Verify all the reflection entities are exposed
                Assert.AreEqual(24, entities.Count(e => !e.Name.StartsWith("EF")));

                // Verify all the service operations are exposed
                var functions = container.Elements.Where(e => e is IEdmOperationImport).ToArray();
                Assert.AreEqual(6, functions.Count());
            }
        }
示例#18
0
        public void FalseCountIsDefaultValue()
        {
            foreach (var mimeType in mimeTypes)
            {
                var url = "/Computer";
                var requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.OriginalString + url, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);

                var defaultResponsestring = this.GetResponseContent(requestMessage);

                url = "/Computer?$count=false";
                requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.OriginalString + url, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);

                var responseString = this.GetResponseContent(requestMessage);

                if (mimeType == MimeTypes.ApplicationAtomXml)
                {
                    // resulting atom payloads with/without model should be the same except for the updated time stamps
                    const string pattern = @"<updated>([A-Za-z0-9\-\:]{20})\</updated>";
                    const string replacement = "<updated>0000-00-00T00:00:00Z</updated>";
                    defaultResponsestring = Regex.Replace(defaultResponsestring, pattern, (match) => replacement);
                    responseString = Regex.Replace(responseString, pattern, (match) => replacement);
                }

                Assert.AreEqual(defaultResponsestring, responseString);
            }
        }
示例#19
0
        public ODataEntityReferenceLinks QueryReferenceLinks(string uri, string mimeType)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = baseUri };

            var queryRequestMessage = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + uri, UriKind.Absolute));
            queryRequestMessage.SetHeader("Accept", mimeType);

            var queryResponseMessage = queryRequestMessage.GetResponse();
            Assert.AreEqual(200, queryResponseMessage.StatusCode);
            ODataEntityReferenceLinks item = null;
            if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
            {
                using (var messageReader = new ODataMessageReader(queryResponseMessage, readerSettings, model))
                {
                    item = messageReader.ReadEntityReferenceLinks();
                }
            }

            return item;
        }
示例#20
0
 private string GetResponseContent(HttpWebRequestMessage requestMessage)
 {
     var response = requestMessage.GetResponse();
     var stream = response.GetStream();
     var streamReader = new StreamReader(stream);
     return streamReader.ReadToEnd();
 }
        private void PrimitiveValueInSkipTokenInURL(string skipTokenQuery)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = this.ServiceUri };

            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new Microsoft.Test.OData.Tests.Client.Common.HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + skipTokenQuery, UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);
                var responseMessage = requestMessage.GetResponse();
                Assert.AreEqual(200, responseMessage.StatusCode);

                if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
                {
                    using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, RetrieveServiceEdmModel()))
                    {
                        var reader = messageReader.CreateODataFeedReader();

                        while (reader.Read())
                        {
                            if (reader.State == ODataReaderState.EntryEnd)
                            {
                                string pattern = skipTokenQuery.Substring(0, skipTokenQuery.IndexOf("?")) + @"\(" + dataPattern + @"\)$";
                                Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);

                                ODataEntry entry = reader.Item as ODataEntry;
                                Assert.IsTrue(rgx.Match(entry.Id.ToString()).Success, "Expected : Entry's Id doesn't contain trailing when Key is Int64/float/double/decimal");
                                if (mimeType.Equals(MimeTypes.ApplicationJson + MimeTypes.ODataParameterFullMetadata))
                                {
                                    Assert.IsTrue(rgx.Match(entry.EditLink.ToString()).Success, "Expected : Entry's EditLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                    Assert.IsTrue(rgx.Match(entry.ReadLink.ToString()).Success, "Expected : Entry's ReadLink doesn't contain trailing when Key is Int64/float/double/decimal");
                                }
                            }
                            else if (reader.State == ODataReaderState.FeedEnd)
                            {
                                var pattern = skipTokenQuery.Substring(0, skipTokenQuery.IndexOf("?")) + @"\?\$skiptoken=" + dataPattern + "$";
                                Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
                                ODataFeed feed = reader.Item as ODataFeed;
                                Assert.IsTrue(rgx.Match(feed.NextPageLink.ToString()).Success, "Expected : Feed's NextLink doesn't contain trailing when Key is Int64/float/double/decimal");
                            }
                        }
                        Assert.AreEqual(ODataReaderState.Completed, reader.State);
                    }
                }
            }
        }
示例#22
0
        public void CountPayloadVerification()
        {
            foreach (var mimeType in mimeTypes)
            {
                var requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.OriginalString + "/Customer?$count=true", UriKind.Absolute));
                requestMessage.SetHeader("Accept", mimeType);

                var responseString = this.GetResponseContent(requestMessage);

                if (mimeType.Contains(MimeTypes.ApplicationJson))
                {
                    if (mimeType.Contains(MimeTypes.ODataParameterIEEE754Compatible))
                    {
                        Assert.IsTrue(responseString.Contains("\"@odata.count\":\"10\""));
                    }
                    else
                    {
                        Assert.IsTrue(responseString.Contains("\"@odata.count\":10"));
                    }
                }
                else
                {
                    Assert.IsTrue(responseString.Contains("<m:count>10</m:count>"));
                }
            }
        }
        private void VerifyActionInEntityPayload(string queryUri, List<Tuple<string, string>> expectedActions, string acceptMimeType)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings();
            var requestMessage = new HttpWebRequestMessage(new Uri(this.ServiceUri.AbsoluteUri + queryUri, UriKind.Absolute));
            requestMessage.SetHeader("Accept", acceptMimeType);

            var responseMessage = requestMessage.GetResponse();

            ODataEntry entry = null;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, this.model))
            {
                var reader = messageReader.CreateODataEntryReader();

                while (reader.Read())
                {
                    if (reader.State == ODataReaderState.EntryEnd)
                    {
                        entry = (ODataEntry)reader.Item;
                    }
                }
            }

            // Verify the expected action metadata and target against the actual ODataActions in the ODataEntry.
            Assert.AreEqual(expectedActions.Count, entry.Actions.Count());
            foreach (var expected in expectedActions)
            {
                var actions = entry.Actions.Where(a => a.Metadata.AbsoluteUri == this.ServiceUri + expected.Item1);
                bool matched = false;
                foreach (var action in actions)
                {
                    if (this.ServiceUri + expected.Item2 == action.Target.AbsoluteUri)
                    {
                        matched = true;
                    }
                }
                Assert.IsTrue(matched);
            }
        }
        private static IODataResponseMessage GetResponseMessge(Uri uri, string format)
        {
            var requestMessage = new HttpWebRequestMessage(uri);
            requestMessage.SetHeader("Accept", format);

            // We set the prefer odata.include-annotations header to always get instance annotations, 
            // since WCF DS Server does not write instance annotations on responses with DSV< V3
            requestMessage.SetHeader("Prefer", "odata.include-annotations=*");

            return requestMessage.GetResponse();
        }