diff options
Diffstat (limited to 'Timeline.Tests')
-rw-r--r-- | Timeline.Tests/Helpers/ResponseAssertions.cs | 25 | ||||
-rw-r--r-- | Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs | 6 |
2 files changed, 28 insertions, 3 deletions
diff --git a/Timeline.Tests/Helpers/ResponseAssertions.cs b/Timeline.Tests/Helpers/ResponseAssertions.cs index 6d764c68..301ceef6 100644 --- a/Timeline.Tests/Helpers/ResponseAssertions.cs +++ b/Timeline.Tests/Helpers/ResponseAssertions.cs @@ -2,11 +2,13 @@ using FluentAssertions.Execution;
using FluentAssertions.Formatting;
using FluentAssertions.Primitives;
-using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using Timeline.Models.Converters;
using Timeline.Models.Http;
namespace Timeline.Tests.Helpers
@@ -88,8 +90,25 @@ namespace Timeline.Tests.Helpers return new AndWhichConstraint<HttpResponseMessageAssertions, T>(this, null);
}
- var result = JsonConvert.DeserializeObject<T>(body); // TODO! catch and throw on bad format
- return new AndWhichConstraint<HttpResponseMessageAssertions, T>(this, result);
+
+ try
+ {
+ var options = new JsonSerializerOptions
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase
+ };
+ options.Converters.Add(new JsonStringEnumConverter());
+ options.Converters.Add(new JsonDateTimeConverter());
+
+ var result = JsonSerializer.Deserialize<T>(body, options);
+
+ return new AndWhichConstraint<HttpResponseMessageAssertions, T>(this, result);
+ }
+ catch (JsonException e)
+ {
+ a.FailWith("Expected response body of {context:HttpResponseMessage} to be json string{reason}, but failed to deserialize it. Exception is {0}.", e);
+ return new AndWhichConstraint<HttpResponseMessageAssertions, T>(this, null);
+ }
}
}
diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs index 483499fb..c5d0addd 100644 --- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs @@ -169,6 +169,12 @@ namespace Timeline.Tests.IntegratedTests { const string userUrl = "users/user/timeline/posts"; const string adminUrl = "users/admin/timeline/posts"; + { + using var client = await CreateClientAsUser(); + var res = await client.PostAsync("users/user/timeline/op/property", + new StringContent(@"{""visibility"":""abcdefg""}", System.Text.Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json)); + res.Should().BeInvalidModel(); + } { // default visibility is registered { using var client = await CreateClientWithNoAuth(); |