Skip to content

Commit

Permalink
Added tests for sending cookies in integration testing (closes #263)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylokenov committed Sep 5, 2016
1 parent cd89f35 commit ee1efae
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 4 deletions.
Binary file removed documentation/MyTested.WebApi.1.2.4.nupkg
Binary file not shown.
Binary file added documentation/MyTested.WebApi.1.2.5.nupkg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public void OwinTestsShouldWorkCorrectlyWithGlobalTestServer()
.AndAlso()
.WithResponseModel(new { id = 1 });

MyWebApi
.Server()
.Working()
.WithHttpRequestMessage(req => req
.WithMethod(HttpMethod.Get)
.WithRequestUri("/cookies")
.WithHeader(HttpHeader.Cookie, "cookiename=cookievalue;anothercookie=anothervalue"))
.ShouldReturnHttpResponseMessage()
.WithStringContent("cookiename+cookievalue!anothercookie+anothervalue");

MyWebApi
.Server()
.Working()
Expand Down Expand Up @@ -92,6 +102,18 @@ public void HttpTestsShouldWorkCorrectlyWithGlobalTestServer()
.WithResponseModelOfType<int>()
.Passing(m => m == 5);

MyWebApi
.Server()
.Working()
.WithHttpRequestMessage(req => req
.WithMethod(HttpMethod.Post)
.WithRequestUri("api/NoAttributes/WithCookies")
.WithHeader(HttpHeader.Cookie, "cookiename=cookievalue;anothercookie=anothervalue"))
.ShouldReturnHttpResponseMessage()
.WithStatusCode(HttpStatusCode.OK)
.AndAlso()
.WithStringContent("\"cookiename+cookievalue!anothercookie+anothervalue\"");

MyWebApi
.Server()
.Working()
Expand Down
4 changes: 2 additions & 2 deletions src/MyTested.WebApi.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
[assembly: ComVisible(false)]
[assembly: Guid("29f6a15e-c6d1-4c93-83c8-18ff839950e8")]

[assembly: AssemblyVersion("1.2.4.0")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: AssemblyVersion("1.2.5.0")]
[assembly: AssemblyFileVersion("1.2.5.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
namespace MyTested.WebApi.Tests.Setups.Controllers
{
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

public class NoAttributesController : ApiController
Expand All @@ -13,6 +16,11 @@ public IHttpActionResult WithParameter(int id)
return this.Ok(id);
}

public IHttpActionResult WithCookies()
{
return this.Ok(string.Join("!", this.Request.Headers.GetCookies().SelectMany(c => c.Cookies.Select(ic => string.Format("{0}+{1}", ic.Name, ic.Value)))));
}

public void VoidAction()
{
}
Expand Down
7 changes: 7 additions & 0 deletions src/MyTested.WebApi.Tests/Setups/CustomStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
namespace MyTested.WebApi.Tests.Setups
{
using System.Linq;
using Owin;

public class CustomStartup
Expand All @@ -12,6 +13,12 @@ public void Configuration(IAppBuilder app)
{
app.Run(context =>
{
if (context.Request.Method == "GET" && context.Request.Uri.OriginalString.EndsWith("/cookies"))
{
context.Response.StatusCode = 200;
return context.Response.WriteAsync(string.Join("!", context.Request.Cookies.Select(c => string.Format("{0}+{1}", c.Key, c.Value))));
}
if (context.Request.Method == "POST" && context.Request.Uri.OriginalString.EndsWith("/test"))
{
context.Response.StatusCode = 302;
Expand Down
10 changes: 10 additions & 0 deletions src/MyTested.WebApi/HttpHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public static class HttpHeader
/// </summary>
public const string ConnectionClose = "Connection-Close";

/// <summary>
/// Represents Cookie header name.
/// </summary>
public const string Cookie = "Cookie";

/// <summary>
/// Represents Date header name.
/// </summary>
Expand Down Expand Up @@ -154,6 +159,11 @@ public static class HttpHeader
/// </summary>
public const string Server = "Server";

/// <summary>
/// Represents SetCookie header name.
/// </summary>
public const string SetCookie = "Set-Cookie";

/// <summary>
/// Represents TE header name.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/MyTested.WebApi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
[assembly: ComVisible(false)]
[assembly: Guid("9e8264b0-67bf-4981-86fd-321f003c1d67")]

[assembly: AssemblyVersion("1.2.4.0")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: AssemblyVersion("1.2.5.0")]
[assembly: AssemblyFileVersion("1.2.5.0")]

0 comments on commit ee1efae

Please sign in to comment.