-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
RequiredAttributeTests.cs
54 lines (47 loc) · 1.32 KB
/
RequiredAttributeTests.cs
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
using System;
using System.ComponentModel.DataAnnotations;
using HotChocolate.Types.Descriptors;
using HotChocolate.Utilities;
using Snapshooter.Xunit;
using Xunit;
#nullable enable
namespace HotChocolate.Types
{
public class RequiredAttributeTests
{
[Fact]
public void Infer_RequiredAttribute_As_NonNull()
{
SchemaBuilder.New()
.AddQueryType<Foo>()
.Create()
.Print()
.MatchSnapshot();
}
[Fact]
public void Ignore_RequiredAttribute()
{
// arrange
var inspector = new DefaultTypeInspector(ignoreRequiredAttribute: true);
var services = new DictionaryServiceProvider(typeof(ITypeInspector), inspector);
// act & assert
SchemaBuilder.New()
.AddQueryType<Foo>()
.AddServices(services)
.Create()
.Print()
.MatchSnapshot();
}
public class Foo
{
[Required]
public string? SomeString { get; }
public string? AddFoo([Required] Bar? input) => throw new NotSupportedException();
}
public class Bar
{
[Required]
public string? Foo { get; set; }
}
}
}