Skip to content

Commit 2f90361

Browse files
author
Bart Koelman
committed
Use alternate public name for attribute, to improve test coverage
1 parent dd435c7 commit 2f90361

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task Cannot_create_resource_with_omitted_required_attribute()
5555
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
5656
error.Title.Should().Be("Input validation failed.");
5757
error.Detail.Should().Be("The Name field is required.");
58-
error.Source.Pointer.Should().Be("/data/attributes/name");
58+
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
5959
}
6060

6161
[Fact]
@@ -69,7 +69,7 @@ public async Task Cannot_create_resource_with_null_for_required_attribute_value(
6969
type = "systemDirectories",
7070
attributes = new
7171
{
72-
name = (string)null,
72+
directoryName = (string)null,
7373
isCaseSensitive = true
7474
}
7575
}
@@ -89,7 +89,7 @@ public async Task Cannot_create_resource_with_null_for_required_attribute_value(
8989
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
9090
error.Title.Should().Be("Input validation failed.");
9191
error.Detail.Should().Be("The Name field is required.");
92-
error.Source.Pointer.Should().Be("/data/attributes/name");
92+
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
9393
}
9494

9595
[Fact]
@@ -103,7 +103,7 @@ public async Task Cannot_create_resource_with_invalid_attribute_value()
103103
type = "systemDirectories",
104104
attributes = new
105105
{
106-
name = "!@#$%^&*().-",
106+
directoryName = "!@#$%^&*().-",
107107
isCaseSensitive = true
108108
}
109109
}
@@ -123,7 +123,7 @@ public async Task Cannot_create_resource_with_invalid_attribute_value()
123123
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
124124
error.Title.Should().Be("Input validation failed.");
125125
error.Detail.Should().Be("The field Name must match the regular expression '^[\\w\\s]+$'.");
126-
error.Source.Pointer.Should().Be("/data/attributes/name");
126+
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
127127
}
128128

129129
[Fact]
@@ -137,7 +137,7 @@ public async Task Can_create_resource_with_valid_attribute_value()
137137
type = "systemDirectories",
138138
attributes = new
139139
{
140-
name = "Projects",
140+
directoryName = "Projects",
141141
isCaseSensitive = true
142142
}
143143
}
@@ -152,7 +152,7 @@ public async Task Can_create_resource_with_valid_attribute_value()
152152
httpResponse.Should().HaveStatusCode(HttpStatusCode.Created);
153153

154154
responseDocument.Data.SingleValue.Should().NotBeNull();
155-
responseDocument.Data.SingleValue.Attributes["name"].Should().Be("Projects");
155+
responseDocument.Data.SingleValue.Attributes["directoryName"].Should().Be("Projects");
156156
responseDocument.Data.SingleValue.Attributes["isCaseSensitive"].Should().Be(true);
157157
}
158158

@@ -186,7 +186,7 @@ public async Task Cannot_create_resource_with_multiple_violations()
186186
error1.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
187187
error1.Title.Should().Be("Input validation failed.");
188188
error1.Detail.Should().Be("The Name field is required.");
189-
error1.Source.Pointer.Should().Be("/data/attributes/name");
189+
error1.Source.Pointer.Should().Be("/data/attributes/directoryName");
190190

191191
ErrorObject error2 = responseDocument.Errors[1];
192192
error2.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
@@ -237,7 +237,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
237237
type = "systemDirectories",
238238
attributes = new
239239
{
240-
name = "Projects",
240+
directoryName = "Projects",
241241
isCaseSensitive = true
242242
},
243243
relationships = new
@@ -285,7 +285,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
285285
httpResponse.Should().HaveStatusCode(HttpStatusCode.Created);
286286

287287
responseDocument.Data.SingleValue.Should().NotBeNull();
288-
responseDocument.Data.SingleValue.Attributes["name"].Should().Be("Projects");
288+
responseDocument.Data.SingleValue.Attributes["directoryName"].Should().Be("Projects");
289289
responseDocument.Data.SingleValue.Attributes["isCaseSensitive"].Should().Be(true);
290290
}
291291

@@ -398,7 +398,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
398398
id = directory.StringId,
399399
attributes = new
400400
{
401-
name = (string)null
401+
directoryName = (string)null
402402
}
403403
}
404404
};
@@ -417,7 +417,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
417417
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
418418
error.Title.Should().Be("Input validation failed.");
419419
error.Detail.Should().Be("The Name field is required.");
420-
error.Source.Pointer.Should().Be("/data/attributes/name");
420+
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
421421
}
422422

423423
[Fact]
@@ -444,7 +444,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
444444
id = directory.StringId,
445445
attributes = new
446446
{
447-
name = "!@#$%^&*().-"
447+
directoryName = "!@#$%^&*().-"
448448
}
449449
}
450450
};
@@ -463,7 +463,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
463463
error.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
464464
error.Title.Should().Be("Input validation failed.");
465465
error.Detail.Should().Be("The field Name must match the regular expression '^[\\w\\s]+$'.");
466-
error.Source.Pointer.Should().Be("/data/attributes/name");
466+
error.Source.Pointer.Should().Be("/data/attributes/directoryName");
467467
}
468468

469469
[Fact]
@@ -490,7 +490,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
490490
id = "-1",
491491
attributes = new
492492
{
493-
name = "Repositories"
493+
directoryName = "Repositories"
494494
},
495495
relationships = new
496496
{
@@ -556,7 +556,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
556556
id = directory.StringId,
557557
attributes = new
558558
{
559-
name = "Repositories"
559+
directoryName = "Repositories"
560560
}
561561
}
562562
};
@@ -634,7 +634,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
634634
id = directory.StringId,
635635
attributes = new
636636
{
637-
name = "Project Files"
637+
directoryName = "Project Files"
638638
},
639639
relationships = new
640640
{
@@ -707,7 +707,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
707707
id = directory.StringId,
708708
attributes = new
709709
{
710-
name = "Project files"
710+
directoryName = "Project files"
711711
},
712712
relationships = new
713713
{
@@ -766,7 +766,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
766766
id = directory.StringId,
767767
attributes = new
768768
{
769-
name = "Project files"
769+
directoryName = "Project files"
770770
},
771771
relationships = new
772772
{

test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/NoModelStateValidationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public async Task Can_create_resource_with_invalid_attribute_value()
3333
type = "systemDirectories",
3434
attributes = new
3535
{
36-
name = "!@#$%^&*().-",
36+
directoryName = "!@#$%^&*().-",
3737
isCaseSensitive = false
3838
}
3939
}
@@ -48,7 +48,7 @@ public async Task Can_create_resource_with_invalid_attribute_value()
4848
httpResponse.Should().HaveStatusCode(HttpStatusCode.Created);
4949

5050
responseDocument.Data.SingleValue.Should().NotBeNull();
51-
responseDocument.Data.SingleValue.Attributes["name"].Should().Be("!@#$%^&*().-");
51+
responseDocument.Data.SingleValue.Attributes["directoryName"].Should().Be("!@#$%^&*().-");
5252
}
5353

5454
[Fact]
@@ -75,7 +75,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
7575
id = directory.StringId,
7676
attributes = new
7777
{
78-
name = "!@#$%^&*().-"
78+
directoryName = "!@#$%^&*().-"
7979
}
8080
}
8181
};

test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/SystemDirectory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed class SystemDirectory : Identifiable<int>
1515
[RegularExpression("^[0-9]+$")]
1616
public override int Id { get; set; }
1717

18-
[Attr]
18+
[Attr(PublicName = "directoryName")]
1919
[Required]
2020
[RegularExpression(@"^[\w\s]+$")]
2121
public string Name { get; set; }

0 commit comments

Comments
 (0)