-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathGraphQLStoredProcedureBuilderHelpersTests.cs
More file actions
59 lines (50 loc) · 2.35 KB
/
Copy pathGraphQLStoredProcedureBuilderHelpersTests.cs
File metadata and controls
59 lines (50 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json;
using Azure.DataApiBuilder.Service.GraphQLBuilder;
using HotChocolate.Language;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Azure.DataApiBuilder.Service.Tests.GraphQLBuilder.Sql
{
/// <summary>
/// Unit tests for the pure helper methods on <see cref="GraphQLStoredProcedureBuilder"/> that
/// shape stored-procedure results and default result fields.
/// </summary>
[TestClass]
public class GraphQLStoredProcedureBuilderHelpersTests
{
[TestMethod]
public void FormatStoredProcedureResultAsJsonList_Null_ReturnsEmptyList()
{
List<JsonDocument> result = GraphQLStoredProcedureBuilder.FormatStoredProcedureResultAsJsonList(null);
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void FormatStoredProcedureResultAsJsonList_EmptyArray_ReturnsEmptyList()
{
using JsonDocument input = JsonDocument.Parse("[]");
List<JsonDocument> result = GraphQLStoredProcedureBuilder.FormatStoredProcedureResultAsJsonList(input);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void FormatStoredProcedureResultAsJsonList_MultipleRows_ReturnsOneDocumentPerRow()
{
using JsonDocument input = JsonDocument.Parse(@"[{""id"":1,""title"":""A""},{""id"":2,""title"":""B""}]");
List<JsonDocument> result = GraphQLStoredProcedureBuilder.FormatStoredProcedureResultAsJsonList(input);
Assert.AreEqual(2, result.Count);
Assert.AreEqual(1, result[0].RootElement.GetProperty("id").GetInt32());
Assert.AreEqual("B", result[1].RootElement.GetProperty("title").GetString());
}
[TestMethod]
public void GetDefaultResultFieldForStoredProcedure_ReturnsResultStringField()
{
FieldDefinitionNode field = GraphQLStoredProcedureBuilder.GetDefaultResultFieldForStoredProcedure();
Assert.AreEqual("result", field.Name.Value);
Assert.AreEqual(0, field.Arguments.Count);
Assert.IsInstanceOfType(field.Type, typeof(NamedTypeNode));
Assert.AreEqual("String", ((NamedTypeNode)field.Type).Name.Value);
}
}
}