|
| 1 | +using System; |
| 2 | +using FluentAssertions; |
| 3 | +using GraphQL.Language.AST; |
| 4 | +using Our.Umbraco.GraphQL.Adapters.Types; |
| 5 | +using Our.Umbraco.GraphQL.Types; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace Our.Umbraco.GraphQL.Tests.Adapters.Types |
| 9 | +{ |
| 10 | + public class IdGraphTypeTests |
| 11 | + { |
| 12 | + [Fact] |
| 13 | + public void Serialize_WithId_ReturnsValueToString() |
| 14 | + { |
| 15 | + var idGraphType = new IdGraphType(); |
| 16 | + var value = "05087385-5095-448D-AA90-4B9AD3C1CA3F"; |
| 17 | + var id = new Id(value); |
| 18 | + |
| 19 | + var serialized = idGraphType.Serialize(id); |
| 20 | + |
| 21 | + serialized.Should().BeOfType<string>().Which.Should().Be(value); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void Serialize_WithNull_ReturnsNull() |
| 26 | + { |
| 27 | + var idGraphType = new IdGraphType(); |
| 28 | + |
| 29 | + var serialized = idGraphType.Serialize(null); |
| 30 | + |
| 31 | + serialized.Should().BeNull(); |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public void ParseValue_WithValue_ReturnsId() |
| 36 | + { |
| 37 | + var idGraphType = new IdGraphType(); |
| 38 | + var value = "BF389740-3EEE-4F2E-BBB1-1C4758B5CE11"; |
| 39 | + |
| 40 | + var parsed = idGraphType.ParseValue(value); |
| 41 | + |
| 42 | + parsed.Should().BeOfType<Id>().Which.Value.Should().Be(value); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public void ParseValue_WithNull_ReturnsNull() |
| 47 | + { |
| 48 | + var idGraphType = new IdGraphType(); |
| 49 | + |
| 50 | + var parsed = idGraphType.ParseValue(null); |
| 51 | + |
| 52 | + parsed.Should().BeNull(); |
| 53 | + } |
| 54 | + |
| 55 | + [Fact] |
| 56 | + public void ParseLiteral_WithStringValue_ReturnsId() |
| 57 | + { |
| 58 | + var idGraphType = new IdGraphType(); |
| 59 | + var value = "BDCE0B55-8D23-47A4-9C66-C94F7D6D8C2A"; |
| 60 | + |
| 61 | + var parsed = idGraphType.ParseLiteral(new StringValue(value)); |
| 62 | + |
| 63 | + parsed.Should().BeOfType<Id>().Which.Value.Should().Be(value); |
| 64 | + } |
| 65 | + |
| 66 | + [Fact] |
| 67 | + public void ParseLiteral_WithIntValue_ReturnsId() |
| 68 | + { |
| 69 | + var idGraphType = new IdGraphType(); |
| 70 | + var value = 43; |
| 71 | + |
| 72 | + var parsed = idGraphType.ParseLiteral(new IntValue(value)); |
| 73 | + |
| 74 | + parsed.Should().BeOfType<Id>().Which.Value.Should().Be(value.ToString()); |
| 75 | + } |
| 76 | + |
| 77 | + [Fact] |
| 78 | + public void ParseLiteral_WithNull_ReturnsNull() |
| 79 | + { |
| 80 | + var idGraphType = new IdGraphType(); |
| 81 | + |
| 82 | + var parsed = idGraphType.ParseLiteral(null); |
| 83 | + |
| 84 | + parsed.Should().BeNull(); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments