public void ParseResponseObject_ReturnsExpectedResult() { IDictionary <string, object> inputHeaders = new Dictionary <string, object>() { { "content-type", "text/plain" } }; dynamic responseObject = new ExpandoObject(); responseObject.body = "Test Body"; responseObject.headers = inputHeaders; responseObject.status = 202; responseObject.enableContentNegotiation = false; object content = null; int statusCode = StatusCodes.Status200OK; List <Tuple <string, string, CookieOptions> > cookies = null; HttpBinding.ParseResponseObject(responseObject, ref content, out IDictionary <string, object> headers, out statusCode, out cookies, out bool enableContentNegotiationResponse); Assert.Equal("Test Body", content); Assert.Same(headers, headers); Assert.Equal(StatusCodes.Status202Accepted, statusCode); Assert.False(enableContentNegotiationResponse); // No cookies found or set Assert.True(cookies == null || !cookies.Any()); // verify case insensitivity responseObject = new ExpandoObject(); responseObject.Body = "Test Body"; responseObject.Headers = inputHeaders; responseObject.StatusCode = "202"; // verify string works as well responseObject.Status = "404"; // verify that StatusCode takes precidence over Status if both are specified responseObject.enableContentNegotiation = true; content = null; headers = null; statusCode = StatusCodes.Status200OK; enableContentNegotiationResponse = false; HttpBinding.ParseResponseObject(responseObject, ref content, out headers, out statusCode, out cookies, out enableContentNegotiationResponse); Assert.Equal("Test Body", content); Assert.Same(headers, headers); Assert.Equal(StatusCodes.Status202Accepted, statusCode); Assert.True(enableContentNegotiationResponse); // No cookies found or set Assert.True(cookies == null || !cookies.Any()); }
public void ParseResponseObject_StatusWithNullBody_ReturnsExpectedResult() { dynamic responseObject = new ExpandoObject(); responseObject.body = null; responseObject.status = 202; object content = null; IDictionary <string, object> headers = null; int statusCode = StatusCodes.Status200OK; bool isRawResponse = false; HttpBinding.ParseResponseObject(responseObject, ref content, out headers, out statusCode, out isRawResponse); Assert.Equal(null, content); Assert.Equal(StatusCodes.Status202Accepted, statusCode); }
public void ParseResponseObject_StatusWithNullBody_ReturnsExpectedResult() { dynamic responseObject = new ExpandoObject(); responseObject.body = null; responseObject.status = 202; object content = null; IDictionary <string, object> headers = null; int statusCode = StatusCodes.Status200OK; bool enableContentNegotiationResponse = false; HttpBinding.ParseResponseObject(responseObject, ref content, out headers, out statusCode, out List <Tuple <string, string, CookieOptions> > cookies, out enableContentNegotiationResponse); Assert.Null(content); Assert.Equal(StatusCodes.Status202Accepted, statusCode); }
public void ParseResponseObject_ReturnsExpectedResult() { IDictionary <string, object> inputHeaders = new Dictionary <string, object>() { { "content-type", "text/plain" } }; dynamic responseObject = new ExpandoObject(); responseObject.body = "Test Body"; responseObject.headers = inputHeaders; responseObject.status = 202; responseObject.isRaw = false; object content = null; IDictionary <string, object> headers = null; HttpStatusCode statusCode = HttpStatusCode.OK; bool isRawResponse = false; HttpBinding.ParseResponseObject(responseObject, ref content, out headers, out statusCode, out isRawResponse); Assert.Equal("Test Body", content); Assert.Same(headers, headers); Assert.Equal(HttpStatusCode.Accepted, statusCode); Assert.False(isRawResponse); // verify case insensitivity responseObject = new ExpandoObject(); responseObject.Body = "Test Body"; responseObject.Headers = inputHeaders; responseObject.StatusCode = "202"; // verify string works as well responseObject.Status = "404"; // verify that StatusCode takes precidence over Status if both are specified responseObject.isRaw = true; content = null; headers = null; statusCode = HttpStatusCode.OK; isRawResponse = false; HttpBinding.ParseResponseObject(responseObject, ref content, out headers, out statusCode, out isRawResponse); Assert.Equal("Test Body", content); Assert.Same(headers, headers); Assert.Equal(HttpStatusCode.Accepted, statusCode); Assert.True(isRawResponse); }
public void ParseResponseObject_WithCookies_ReturnsExpectedResult() { var cookieProperties = new Tuple <string, string, CookieOptions>("hello", "world", new CookieOptions() { Domain = "/", MaxAge = TimeSpan.FromSeconds(60), HttpOnly = true }); IList <Tuple <string, string, CookieOptions> > cookieContents = new List <Tuple <string, string, CookieOptions> >() { cookieProperties }; dynamic responseObject = new ExpandoObject(); responseObject.Body = "Test Body"; responseObject.Cookies = cookieContents; responseObject.StatusCode = "202"; // verify string works as well object content = null; var statusCode = StatusCodes.Status200OK; HttpBinding.ParseResponseObject(responseObject, ref content, out IDictionary <string, object> headers, out statusCode, out List <Tuple <string, string, CookieOptions> > cookies, out bool enableContentNegotiationResponse); Assert.Equal("Test Body", content); Assert.Same(cookieContents, cookies); Assert.Equal(cookieContents.Count, cookies.Count); var firstCookie = cookies.First(); Assert.Same(cookieProperties, firstCookie); Assert.Same(cookieProperties.Item1, firstCookie.Item1); Assert.Same(cookieProperties.Item2, firstCookie.Item2); Assert.Same(cookieProperties.Item3, firstCookie.Item3); Assert.Equal(StatusCodes.Status202Accepted, statusCode); Assert.False(enableContentNegotiationResponse); Assert.Null(headers); }