aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/ResponseExtensions.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-09 21:48:12 +0800
committerGitHub <noreply@github.com>2019-08-09 21:48:12 +0800
commit38ff45fcc0b58a95ad52ba43a8be4ff466694269 (patch)
treef1cf455b758e8bf0265d4db0e42a404e9877b321 /Timeline.Tests/Helpers/ResponseExtensions.cs
parente283a3e745bad05a55c572646d7b20fbaaeb522d (diff)
parentea8397bafe24b5c9ab814891eb3a293a07ca217e (diff)
downloadtimeline-38ff45fcc0b58a95ad52ba43a8be4ff466694269.tar.gz
timeline-38ff45fcc0b58a95ad52ba43a8be4ff466694269.tar.bz2
timeline-38ff45fcc0b58a95ad52ba43a8be4ff466694269.zip
Merge pull request #38 from crupest/null-request-field
Do 3 things.
Diffstat (limited to 'Timeline.Tests/Helpers/ResponseExtensions.cs')
-rw-r--r--Timeline.Tests/Helpers/ResponseExtensions.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/ResponseExtensions.cs b/Timeline.Tests/Helpers/ResponseExtensions.cs
index 155836fb..46c9e81d 100644
--- a/Timeline.Tests/Helpers/ResponseExtensions.cs
+++ b/Timeline.Tests/Helpers/ResponseExtensions.cs
@@ -1,11 +1,58 @@
using Newtonsoft.Json;
+using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
+using Timeline.Models.Http;
+using Xunit;
namespace Timeline.Tests.Helpers
{
public static class ResponseExtensions
{
+ public static void AssertOk(this HttpResponseMessage response)
+ {
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+ }
+
+ public static void AssertNotFound(this HttpResponseMessage response)
+ {
+ Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
+ }
+
+ public static void AssertBadRequest(this HttpResponseMessage response)
+ {
+ Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
+ }
+
+ public static async Task AssertIsPutCreated(this HttpResponseMessage response)
+ {
+ Assert.Equal(HttpStatusCode.Created, response.StatusCode);
+ var body = await response.ReadBodyAsJson<CommonResponse>();
+ Assert.Equal(CommonPutResponse.CreatedCode, body.Code);
+ }
+
+ public static async Task AssertIsPutModified(this HttpResponseMessage response)
+ {
+ response.AssertOk();
+ var body = await response.ReadBodyAsJson<CommonResponse>();
+ Assert.Equal(CommonPutResponse.ModifiedCode, body.Code);
+ }
+
+
+ public static async Task AssertIsDeleteDeleted(this HttpResponseMessage response)
+ {
+ response.AssertOk();
+ var body = await response.ReadBodyAsJson<CommonResponse>();
+ Assert.Equal(CommonDeleteResponse.DeletedCode, body.Code);
+ }
+
+ public static async Task AssertIsDeleteNotExist(this HttpResponseMessage response)
+ {
+ response.AssertOk();
+ var body = await response.ReadBodyAsJson<CommonResponse>();
+ Assert.Equal(CommonDeleteResponse.NotExistsCode, body.Code);
+ }
+
public static async Task<T> ReadBodyAsJson<T>(this HttpResponseMessage response)
{
return JsonConvert.DeserializeObject<T>(await response.Content.ReadAsStringAsync());