private void SendBody(HttpListenerResponse aspNetResponse, IDictionary <string, string> wireResponse) { using (var stream = aspNetResponse.OutputStream) { var formParams = new FormParams.Of(wireResponse); if (formParams.Count > 0) { using (var body = new InputOf( new Yaapii.Atoms.Text.Joined("&", new Mapped <KeyValuePair <string, string>, string>(kvp => $"{kvp.Key}={kvp.Value}", formParams ) ) ).Stream() ) { body.CopyTo(stream); } } else if (new Body.Exists(wireResponse).Value()) { using (var body = new Body.Of(wireResponse).Stream()) { body.CopyTo(stream); } } } }
public void ResetsStreamAfterUpdate() { using (var cell = new RamCell("my-cell")) { var content = new InputOf("its so hot outside"); cell.Update(content); Assert.Equal(0, content.Stream().Position); } }
public void ResetsStreamAfterUpdate() { using (var tmp = new TempDirectory()) { using (var cell = new FileCell(Path.Combine(tmp.Value().FullName, "test.txt"))) { var content = new InputOf("its so hot outside"); cell.Update(content); Assert.Equal(0, content.Stream().Position); } } }
/// <summary> /// The body of a request or response. /// </summary> public Of(IDictionary <string, string> input) : this( new ScalarOf <IInput>(() => { IInput result = new DeadInput(); if (input.ContainsKey(Body.KEY)) { result = new InputOf( new Base64Bytes( new BytesOf( input[KEY] ) ) ); } return(result); } ) ) { }
public void TransmitsRawZipFile() { var port = new AwaitedPort(new TestPort()).Value(); IInput result = new DeadInput(); using (var server = new MockServer( port, "{}", (req, res, prm) => result = new InputOf( new BytesOf( new InputOf(req.InputStream) ).AsBytes() ), "localhost" ) ) { new AspNetCoreWire( new AspNetCoreClients() ).Response( new Post($"http://localhost:{port}/", new Body( new ResourceOf( "Assets/test.zip", this.GetType().Assembly ) ) ) ).Wait(30000); } Assert.Equal( "this is a test", // content of test.txt in Assets/test.zip new TextOf( new UnzippedFile(result, "test.txt") ).AsString() ); }