public void op_ToString_when404() { var expected = new StringBuilder(); expected.AppendLine("HTTP/1.1 404 Not Found"); expected.AppendLine("Content-Length: 4"); expected.AppendLine("Content-Type: text/plain; charset=UTF-8"); expected.AppendLine(string.Empty); expected.Append("text"); string actual; try { var locator = new Mock <IServiceLocator>(); locator .Setup(e => e.GetInstance <IMediaType>("text/plain")) .Returns(new TextPlain()) .Verifiable(); ServiceLocator.SetLocatorProvider(() => locator.Object); actual = HttpResponse.FromString(expected.ToString()).ToString(); locator.VerifyAll(); } finally { ServiceLocator.SetLocatorProvider(null); } Assert.Equal(expected.ToString(), actual); }
public void op_FromString_string_whenStatusLine() { const string line = "HTTP/1.1 201 Created"; var obj = HttpResponse.FromString(line); Assert.Equal(line, obj.Line); Assert.Empty(obj.Headers.ToList()); Assert.Null(obj.Body); }
public void op_ToString_when201() { var expected = new StringBuilder(); expected.AppendLine("HTTP/1.1 201 Created"); expected.AppendLine(string.Empty); var actual = HttpResponse.FromString(expected.ToString()).ToString(); Assert.Equal(expected.ToString(), actual); }
public void op_FromString_string_when201() { StatusLine statusLine = "HTTP/1.1 201 Created"; var expected = new StringBuilder(); expected.AppendLine(statusLine); var obj = HttpResponse.FromString(expected.ToString()); Assert.Equal <string>(statusLine, obj.StatusLine); Assert.Equal(0, obj.Headers.Count); Assert.Null(obj.Body); }
public void op_Write_TextWriter_when404() { var expected = new StringBuilder(); expected.AppendLine("HTTP/1.1 404 Not Found"); expected.AppendLine("Content-Length: 4"); expected.AppendLine("Content-Type: text/plain; charset=UTF-8"); expected.AppendLine(string.Empty); expected.Append("text"); HttpResponse obj; try { var locator = new Mock <IServiceLocator>(); locator .Setup(e => e.GetInstance <IMediaType>("text/plain")) .Returns(new TextPlain()) .Verifiable(); ServiceLocator.SetLocatorProvider(() => locator.Object); obj = HttpResponse.FromString(expected.ToString()); locator.VerifyAll(); } finally { ServiceLocator.SetLocatorProvider(null); } using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { obj.Write(writer); writer.Flush(); stream.Position = 0; using (var reader = new StreamReader(stream)) { Assert.Equal(expected.ToString(), reader.ReadToEnd()); } } } }
public void op_FromString_string_whenHeaders() { const string line = "HTTP/1.1 204 No Content"; HttpHeader control = "Cache-Control: no-cache"; HttpHeader length = "Content-Length: 0"; var buffer = new StringBuilder(); buffer.AppendLine(line); buffer.AppendLine(control); buffer.AppendLine(length); var obj = HttpResponse.FromString(buffer.ToString()); Assert.Equal(line, obj.Line); Assert.Equal(control, obj.Headers.First()); Assert.Equal(length, obj.Headers.Last()); Assert.Null(obj.Body); }
public void op_FromString_string_when404() { StatusLine statusLine = "HTTP/1.1 404 Not Found"; HttpHeader contentLength = "Content-Length: 4"; HttpHeader contentType = "Content-Type: text/plain; charset=UTF-8"; var expected = new StringBuilder(); expected.AppendLine(statusLine); expected.AppendLine(contentLength); expected.AppendLine(contentType); expected.AppendLine(string.Empty); expected.Append("text"); HttpResponse obj; try { var locator = new Mock <IServiceLocator>(); locator .Setup(e => e.GetInstance <IMediaType>("text/plain")) .Returns(new TextPlain()) .Verifiable(); ServiceLocator.SetLocatorProvider(() => locator.Object); obj = HttpResponse.FromString(expected.ToString()); locator.VerifyAll(); } finally { ServiceLocator.SetLocatorProvider(null); } Assert.Equal <string>(statusLine, obj.StatusLine); Assert.True(obj.Headers.Contains(contentLength)); Assert.True(obj.Headers.Contains(contentType)); Assert.Equal("text", ((TextPlain)obj.Body).Value); }
public void op_FromString_string_whenHeadersAndBody() { const string line = "HTTP/1.1 200 OK"; HttpHeader type = "Content-Type: text/plain"; HttpHeader length = "Content-Length: 7"; var buffer = new StringBuilder(); buffer.AppendLine(line); buffer.AppendLine(type); buffer.AppendLine(length); buffer.AppendLine(string.Empty); buffer.Append("example"); var obj = HttpResponse.FromString(buffer.ToString()); Assert.Equal(line, obj.Line); Assert.Equal(type, obj.Headers.First()); Assert.Equal(length, obj.Headers.Last()); Assert.Equal("example", ((TextBody)obj.Body).Text); }
public void op_Write_TextWriter_when201() { var expected = new StringBuilder(); expected.AppendLine("HTTP/1.1 201 Created"); expected.AppendLine(string.Empty); var obj = HttpResponse.FromString(expected.ToString()); using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { obj.Write(writer); writer.Flush(); stream.Position = 0; using (var reader = new StreamReader(stream)) { Assert.Equal(expected.ToString(), reader.ReadToEnd()); } } } }
public void op_FromString_stringNull() { Assert.Throws <ArgumentNullException>(() => HttpResponse.FromString(null)); }
public void op_FromString_stringEmpty() { Assert.Throws <ArgumentOutOfRangeException>(() => HttpResponse.FromString(string.Empty)); }