示例#1
0
        private void QueryAndVerify(string query, string preferHeader)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings()
            {
                BaseUri = serviceFixture.ServiceBaseUri
            };
            var requestMessage = new HttpWebRequestMessage(new Uri(serviceFixture.ServiceBaseUri.AbsoluteUri + query, UriKind.Absolute));

            if (!String.IsNullOrEmpty(preferHeader))
            {
                requestMessage.SetHeader("Prefer", preferHeader);
            }

            var responseMessage = requestMessage.GetResponse();

            Assert.Equal(200, responseMessage.StatusCode);
        }
示例#2
0
        public void ResetDataSource()
        {
            ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings()
            {
                BaseUri = serviceFixture.ServiceBaseUri
            };

            writerSettings.ODataUri = new ODataUri()
            {
                ServiceRoot = serviceFixture.ServiceBaseUri
            };
            var requestMessage = new HttpWebRequestMessage(new Uri(serviceFixture.ServiceBaseUri.AbsoluteUri + "ResetDataSource", UriKind.Absolute));

            requestMessage.Method        = "POST";
            requestMessage.ContentLength = 0;
            var responseMessage = requestMessage.GetResponse();

            Assert.Equal(204, responseMessage.StatusCode);
        }
示例#3
0
        public void DeleteEntity()
        {
            int RequestsPerIteration = 100;
            int PersonIdBase         = 1;


            for (int i = 0; i < RequestsPerIteration; i++)
            {
                ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings()
                {
                    BaseUri = serviceFixture.ServiceBaseUri
                };
                writerSettings.ODataUri = new ODataUri()
                {
                    ServiceRoot = serviceFixture.ServiceBaseUri
                };
                var requestMessage = new HttpWebRequestMessage(new Uri(serviceFixture.ServiceBaseUri.AbsoluteUri + "SimplePeopleSet(" + (PersonIdBase++) + ")", UriKind.Absolute));
                requestMessage.Method = "DELETE";
                var responseMessage = requestMessage.GetResponse();
                Assert.Equal(204, responseMessage.StatusCode);
            }
        }
示例#4
0
        public void PatchEntity()
        {
            int RequestsPerIteration = 100;
            int PersonIdBase         = 1;

            for (int i = 0; i < RequestsPerIteration; i++)
            {
                ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings()
                {
                    BaseUri = serviceFixture.ServiceBaseUri
                };
                writerSettings.ODataUri = new ODataUri()
                {
                    ServiceRoot = serviceFixture.ServiceBaseUri
                };
                var requestMessage = new HttpWebRequestMessage(new Uri(serviceFixture.ServiceBaseUri.AbsoluteUri + "SimplePeopleSet(" + (PersonIdBase++) + ")", UriKind.Absolute));
                requestMessage.Method = "PATCH";

                var peopleEntry = new ODataResource()
                {
                    Properties = new[]
                    {
                        new ODataProperty {
                            Name = "MiddleName", Value = "NewMiddleName"
                        }
                    },
                };

                using (var messageWriter = new ODataMessageWriter(requestMessage, writerSettings))
                {
                    var odataWriter = messageWriter.CreateODataResourceWriter();
                    odataWriter.WriteStart(peopleEntry);
                    odataWriter.WriteEnd();
                }
                var responseMessage = requestMessage.GetResponse();
                Assert.Equal(204, responseMessage.StatusCode);
            }
        }
示例#5
0
        public void PostEntity()
        {
            int RequestsPerIteration = 100;

            foreach (var iteration in Benchmark.Iterations)
            {
                int PersonIdBase = 100;

                ResetDataSource();

                using (iteration.StartMeasurement())
                {
                    for (int i = 0; i < RequestsPerIteration; i++)
                    {
                        ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings()
                        {
                            BaseUri = serviceFixture.ServiceBaseUri
                        };
                        writerSettings.ODataUri = new ODataUri()
                        {
                            ServiceRoot = serviceFixture.ServiceBaseUri
                        };
                        var requestMessage =
                            new HttpWebRequestMessage(
                                new Uri(serviceFixture.ServiceBaseUri.AbsoluteUri + "SimplePeopleSet", UriKind.Absolute));
                        requestMessage.Method = "POST";

                        var peopleEntry = new ODataResource()
                        {
                            EditLink   = new Uri("/SimplePeopleSet(" + (PersonIdBase++) + ")", UriKind.Relative),
                            Id         = new Uri("/SimplePeopleSet(" + PersonIdBase + ")", UriKind.Relative),
                            TypeName   = NameSpacePrefix + "Person",
                            Properties = new[]
                            {
                                new ODataProperty {
                                    Name = "PersonID", Value = PersonIdBase
                                },
                                new ODataProperty {
                                    Name = "FirstName", Value = "PostEntity"
                                },
                                new ODataProperty {
                                    Name = "LastName", Value = "PostEntity"
                                },
                                new ODataProperty {
                                    Name = "MiddleName", Value = "PostEntity"
                                }
                            },
                        };

                        using (var messageWriter = new ODataMessageWriter(requestMessage, writerSettings))
                        {
                            var odataWriter = messageWriter.CreateODataResourceWriter();
                            odataWriter.WriteStart(peopleEntry);
                            odataWriter.WriteEnd();
                        }

                        var responseMessage = requestMessage.GetResponse();
                        Assert.Equal(201, responseMessage.StatusCode);
                    }
                }
            }
        }