Skip to content

Commit

Permalink
complex type test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
VarunSaiTeja committed Jun 19, 2022
1 parent 556af9d commit b5e8574
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchUrl": "graphql",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
8 changes: 8 additions & 0 deletions Shared/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ public class Query
public string CheckDuplicateEmail([EmailAddress, Required][DuplicateEmailValidtor] string email) => "You are good to go, this email not registred yet.";

public string ArgIsInput(MyInput input) => input.Email;

public string CheckPass(Student student)
{
if (student.ScoreCard.TotalScore > 30)
return $"{student.FirstName} at {student.ScoreCard.School} is passed";
else
return $"{student.FirstName} at {student.ScoreCard.School} is failed";
}
}
}
23 changes: 23 additions & 0 deletions Shared/Student.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Graph.ArgumentValidator;
using System.ComponentModel.DataAnnotations;

namespace Shared
{
[Validatable]
public class Student
{
[Required(AllowEmptyStrings = false)]
public string FirstName { get; set; }
[Required]
public ScoreCardInfo ScoreCard { get; set; }

public class ScoreCardInfo
{
[Required]
public int TotalScore { get; set; }

[Required(AllowEmptyStrings = false)]
public string School { get; set; }
}
}
}
16 changes: 16 additions & 0 deletions test/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,21 @@ public async Task Ensure_Validation_Works_On_NonDuplicateEmail()

result.MatchSnapshot();
}

[Fact]
public async Task Ensure_Validation_Works_On_StudentWithScoreCard()
{
var result = await ExecuteRequest("query{checkPass(student: { firstName: \"Varun\",scoreCard: { school: \"Gayatri\",totalScore: 85} })}");

result.MatchSnapshot();
}

[Fact]
public async Task Ensure_Validation_Works_On_StudentWithOutScoreCard()
{
var result = await ExecuteRequest("query{checkPass(student: { firstName: \"Varun\"})}");

result.MatchSnapshot();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"errors": [
{
"message": "\u0060scoreCard\u0060 is a required field and cannot be null.",
"locations": [
{
"line": 1,
"column": 26
}
],
"path": [
"checkPass"
],
"extensions": {
"field": "scoreCard",
"specifiedBy": "http://spec.graphql.org/October2021/#sec-Input-Object-Required-Fields"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"checkPass": "Varun at Gayatri is passed"
}
}

0 comments on commit b5e8574

Please sign in to comment.