示例#1
0
        public void ScalarAllowAuthorization()
        {
            var backend = new AuthBackend
            {
                IsAuthorized = true
            };
            var server = new ScalarAuthModel()
                         .CreateServer(services => services.AddSingleton(backend));

            var result = server.Execute <JObject>(@"{
                child {
                    value1
                    protected
                    value3
                }
            }");

            var data = result["child"];

            data.Should().BeEquivalentTo(new JObject(
                                             new JProperty("value1", "hello"),
                                             new JProperty("protected", "world"),
                                             new JProperty("value3", 654)
                                             ));
        }
示例#2
0
        public void ScalarDenyAuthorization()
        {
            var backend = new AuthBackend
            {
                IsAuthorized = false
            };
            var server = new ScalarAuthModel()
                         .CreateServer(services => services.AddSingleton(backend));

            var result = server.Execute <JObject>(@"{
                child {
                    value1
                    protected
                    value3
                }
            }", throwOnError: false);

            var data = result["data"]["child"];

            data.Should().BeEquivalentTo(new JObject(
                                             new JProperty("value1", "hello"),
                                             new JProperty("protected", null),
                                             new JProperty("value3", 654)
                                             ));

            var errs = (JArray)result["errors"];

            errs.Count.Should().Be(1);
            errs[0]["Message"].Value <string>().Should().Be("Not authorized");
        }