|
| 1 | +using System; |
| 2 | +using HotChocolate.Execution; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace Core.Tests.Execution |
| 6 | +{ |
| 7 | + public class QueryResultTests |
| 8 | + { |
| 9 | + [Fact] |
| 10 | + public void Create_OnlyData_DataIsReadOnly() |
| 11 | + { |
| 12 | + // arrange |
| 13 | + var data = new OrderedDictionary(); |
| 14 | + Assert.False(data.IsReadOnly); |
| 15 | + |
| 16 | + // act |
| 17 | + var result = new QueryResult(data); |
| 18 | + |
| 19 | + // assert |
| 20 | + Assert.True(result.Data.IsReadOnly); |
| 21 | + Assert.True(data.IsReadOnly); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void ToJson_OnlyData_JsonStringNoIndentations() |
| 26 | + { |
| 27 | + // arrange |
| 28 | + var data = new OrderedDictionary(); |
| 29 | + var result = new QueryResult(data); |
| 30 | + |
| 31 | + // act |
| 32 | + string json = result.ToJson(false); |
| 33 | + |
| 34 | + |
| 35 | + // assert |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + [Fact] |
| 40 | + public void Create_OnlyData_ErrorIsNull() |
| 41 | + { |
| 42 | + // arrange |
| 43 | + var data = new OrderedDictionary(); |
| 44 | + |
| 45 | + // act |
| 46 | + var result = new QueryResult(data); |
| 47 | + |
| 48 | + // assert |
| 49 | + Assert.Null(result.Errors); |
| 50 | + } |
| 51 | + |
| 52 | + [Fact] |
| 53 | + public void Create_DataIsNull_ArgumentNullException() |
| 54 | + { |
| 55 | + // arrange |
| 56 | + // act |
| 57 | + Action a = () => new QueryResult((OrderedDictionary)null); |
| 58 | + |
| 59 | + // assert |
| 60 | + Assert.Throws<ArgumentNullException>(a); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void Create_OnlyError_ErrorIsReadOnly() |
| 65 | + { |
| 66 | + // arrange |
| 67 | + var data = new OrderedDictionary(); |
| 68 | + Assert.False(data.IsReadOnly); |
| 69 | + |
| 70 | + // act |
| 71 | + var result = new QueryResult(data); |
| 72 | + |
| 73 | + // assert |
| 74 | + Assert.True(result.Data.IsReadOnly); |
| 75 | + Assert.True(data.IsReadOnly); |
| 76 | + } |
| 77 | + |
| 78 | + [Fact] |
| 79 | + public void Create_WithOneError_ContainsOneError() |
| 80 | + { |
| 81 | + // arrange |
| 82 | + QueryError error = new QueryError("foo"); |
| 83 | + |
| 84 | + // act |
| 85 | + var result = new QueryResult(error); |
| 86 | + |
| 87 | + // assert |
| 88 | + Assert.Collection(result.Errors, |
| 89 | + t => Assert.Equal(error, t)); |
| 90 | + } |
| 91 | + |
| 92 | + [Fact] |
| 93 | + public void Create_OnlyError_DataIsNull() |
| 94 | + { |
| 95 | + // arrange |
| 96 | + QueryError error = new QueryError("foo"); |
| 97 | + |
| 98 | + // act |
| 99 | + var result = new QueryResult(error); |
| 100 | + |
| 101 | + // assert |
| 102 | + Assert.Null(result.Data); |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments