using System; using System.Text; using NUnit.Framework; using ServiceStack.Plugins.ProtoBuf; using ServiceStack.ServiceClient.Web; using ServiceStack.Text; namespace ServiceStack.WebHost.IntegrationTests.Tests { [TestFixture] public class BinarySerializedTests { private string RandomString(int Length) { var rnd = new Random(); var tmp = new StringBuilder(); for (Int64 i = 0; i < Length; i++) { tmp.Append(Convert.ToChar(((byte)rnd.Next(254))).ToString()); } return tmp.ToString(); } [Test] public void Can_call_cached_WebService_with_Protobuf() { var client = new ProtoBufServiceClient(Config.ServiceStackBaseUri); try { var fromEmail = RandomString(32); var response = client.Get("/cached/protobuf/?format=x-protobuf"); Console.WriteLine(response.Dump()); Assert.That(response.FromAddress, Is.EqualTo(fromEmail)); } catch (WebServiceException webEx) { Console.WriteLine(webEx.ResponseDto.Dump()); Assert.Fail(webEx.Message); } } [Test] public void Can_call_WebService_with_Protobuf() { //new ProtoBufServiceTests().Can_Send_ProtoBuf_request(); var client = new ProtoBufServiceClient(Config.ServiceStackBaseUri); try { var fromEmail = RandomString(32); var response = client.Get("/uncached/protobuf/?format=x-protobuf"); Console.WriteLine(response.Dump()); Assert.That(response.FromAddress, Is.EqualTo(fromEmail)); } catch (WebServiceException webEx) { Console.WriteLine(webEx.ResponseDto.Dump()); Assert.Fail(webEx.Message); } } } }