public void TestDefaultMimeType()
        {
            ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl());

            //obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting
            IHttpTransfer wire = server;


            MemoryStream input  = new MemoryStream(new SearchRequest.Builder().AddCriteria("Test").Build().ToByteArray());
            MemoryStream output = new MemoryStream();

            //With this default set, any invalid/unknown mime-type will be mapped to use that format
            server.Options.DefaultContentType = MessageFormatOptions.ContentTypeProtoBuffer;

            wire.Execute("Search",
                         "foo", input,
                         "bar", output
                         );

            SearchResponse result = SearchResponse.ParseFrom(output.ToArray());

            Assert.AreEqual(1, result.ResultsCount);
            Assert.AreEqual("Test", result.ResultsList[0].Name);
            Assert.AreEqual("http://search.com", result.ResultsList[0].Url);
        }
        public void TestInvalidMimeType()
        {
            ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl());
            //obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting
            IHttpTransfer wire = server;

            MemoryStream input  = new MemoryStream();
            MemoryStream output = new MemoryStream();

            //Call the server
            wire.Execute("Search",
                         "bad/mime", input,
                         MessageFormatOptions.ContentTypeProtoBuffer, output
                         );
            Assert.Fail();
        }
            TMessage IRpcDispatch.CallMethod <TMessage, TBuilder>(string method, IMessageLite request,
                                                                  IBuilderLite <TMessage, TBuilder> response)
            {
                MemoryStream input  = new MemoryStream();
                MemoryStream output = new MemoryStream();

                //Write to _mimeType format
                Extensions.WriteTo(request, Options, _mimeType, input);

                input.Position = 0;
                _wire.Execute(method, _mimeType, input, _mimeType, output);

                //Read from _mimeType format
                output.Position = 0;
                Extensions.MergeFrom(response, Options, _mimeType, output);

                return(response.Build());
            }
        public void TestServerWithUriFormat()
        {
            ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl());
            //obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting
            IHttpTransfer wire = server;

            MemoryStream input  = new MemoryStream(Encoding.UTF8.GetBytes("?Criteria=Test&Criteria=Test+of%20URI"));
            MemoryStream output = new MemoryStream();

            //Call the server
            wire.Execute("Search",
                         MessageFormatOptions.ContentFormUrlEncoded, input,
                         MessageFormatOptions.ContentTypeProtoBuffer, output
                         );

            SearchResponse result = SearchResponse.ParseFrom(output.ToArray());

            Assert.AreEqual(2, result.ResultsCount);
            Assert.AreEqual("Test", result.ResultsList[0].Name);
            Assert.AreEqual("http://search.com", result.ResultsList[0].Url);

            Assert.AreEqual("Test of URI", result.ResultsList[1].Name);
            Assert.AreEqual("http://search.com", result.ResultsList[1].Url);
        }