Skip to content

Commit d004167

Browse files
author
Harro van der Kroft
committed
fix: make tests work
1 parent 2af4a26 commit d004167

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/Examples/GettingStarted/GettingStarted.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8+
<Folder Include="Properties\" />
89
<Folder Include="wwwroot\" />
910
</ItemGroup>
1011

src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public TodoItem()
3030
[Attr("updated-date")]
3131
public DateTime? UpdatedDate { get; set; }
3232

33-
[Attr("calculated-value")]
33+
[Attr("calculated-value", isImmutable: true)]
3434
public string CalculatedValue
3535
{
3636
get => "joe";

src/JsonApiDotNetCore/Formatters/IJsonApiReader.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
namespace JsonApiDotNetCore.Formatters
55
{
6+
/// <summary>
7+
/// The deserializer of the body, used in .NET core internally
8+
/// to process `FromBody`
9+
/// </summary>
610
public interface IJsonApiReader
711
{
812
Task<InputFormatterResult> ReadAsync(InputFormatterContext context);
913
}
10-
}
14+
}

src/JsonApiDotNetCore/Formatters/JsonApiReader.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
namespace JsonApiDotNetCore.Formatters
1212
{
13+
/// <inheritdoc />
1314
public class JsonApiReader : IJsonApiReader
1415
{
1516
private readonly IJsonApiDeSerializer _deSerializer;
1617
private readonly IJsonApiContext _jsonApiContext;
1718
private readonly ILogger<JsonApiReader> _logger;
1819

19-
2020
public JsonApiReader(IJsonApiDeSerializer deSerializer, IJsonApiContext jsonApiContext, ILoggerFactory loggerFactory)
2121
{
2222
_deSerializer = deSerializer;
@@ -37,13 +37,21 @@ public Task<InputFormatterResult> ReadAsync(InputFormatterContext context)
3737
{
3838
var body = GetRequestBody(context.HttpContext.Request.Body);
3939

40-
var model = _jsonApiContext.IsRelationshipPath ?
41-
_deSerializer.DeserializeRelationship(body) :
42-
_deSerializer.Deserialize(body);
40+
object model =null;
41+
42+
if (_jsonApiContext.IsRelationshipPath)
43+
{
44+
model = _deSerializer.DeserializeRelationship(body);
45+
}
46+
else
47+
{
48+
model = _deSerializer.Deserialize(body);
49+
}
4350

4451
if (model == null)
52+
{
4553
_logger?.LogError("An error occurred while de-serializing the payload");
46-
54+
}
4755
return InputFormatterResult.SuccessAsync(model);
4856
}
4957
catch (Exception ex)

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/UpdatingDataTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public async Task Response400IfUpdatingNotSettableAttribute()
7070
var response = await client.SendAsync(request);
7171

7272
// Assert
73+
var body = await response.Content.ReadAsStringAsync();
7374
Assert.Equal(422, Convert.ToInt32(response.StatusCode));
7475
}
7576

0 commit comments

Comments
 (0)