public void TestProcessingGetRequestWithConsignmentMessageWithSignature() { string content = File.ReadAllText("BigJsonExample.json"); string TestConsignmentWithSignatureRequest = $"GET /description HTTP/1.1\r\nHost: localhost\r\nContent-Length: {content.Length}\r\n\r\n{content}"; MockRequestBroker broker = new MockRequestBroker(); Mock <IConfigurationManager> config = new Mock <IConfigurationManager>(); Mock <IContainerFacade> container = new Mock <IContainerFacade>(); const int port = 8883; config.Setup(conf => conf.Get("Port", It.IsAny <int>())).Returns(port); Mock <ILogger> logger = new Mock <ILogger>(); NanoHttp nanoHttp = new NanoHttp(new[] { broker }, config.Object, logger.Object, container.Object); try { nanoHttp.Start(); Socket client = new Socket(SocketType.Stream, ProtocolType.IP) { ReceiveBufferSize = 1024, LingerState = new LingerOption(false, 0), NoDelay = true }; client.Connect("127.0.0.1", port); byte[] bytes = Encoding.ASCII.GetBytes(TestConsignmentWithSignatureRequest); client.Send(bytes); broker.WaitHandle.WaitOne(); client.Shutdown(SocketShutdown.Both); client.Dispose(); } finally { nanoHttp.Stop(); } Assert.AreEqual(HttpVerb.Get, broker.Verb); Assert.AreEqual(Environment.NewLine == "\r\n" ? 13575 : 13515, broker.Body.Length); Assert.AreEqual(123, broker.Body[0]); Assert.AreEqual(Environment.NewLine == "\r\n" ? 34 : 46, broker.Body[1999]); }
public void TestProcessingGetRequestWithHugeContent() { MockRequestBroker broker = new MockRequestBroker(); Mock <IConfigurationManager> config = new Mock <IConfigurationManager>(); Mock <IContainerFacade> container = new Mock <IContainerFacade>(); const int port = 8882; config.Setup(conf => conf.Get("Port", It.IsAny <int>())).Returns(port); Mock <ILogger> logger = new Mock <ILogger>(); NanoHttp nanoHttp = new NanoHttp(new[] { broker }, config.Object, logger.Object, container.Object); try { nanoHttp.Start(); Socket client = new Socket(SocketType.Stream, ProtocolType.IP) { ReceiveBufferSize = 1024, LingerState = new LingerOption(false, 0), NoDelay = true }; client.Connect("127.0.0.1", port); byte[] bytes = Encoding.ASCII.GetBytes(TestRequestHugeContent); client.Send(bytes); broker.WaitHandle.WaitOne(); client.Shutdown(SocketShutdown.Both); client.Dispose(); } finally { nanoHttp.Stop(); } Assert.AreEqual(HttpVerb.Get, broker.Verb); Assert.AreEqual(2000, broker.Body.Length); Assert.AreEqual(48, broker.Body[0]); Assert.AreEqual(57, broker.Body[1999]); }