public void Parse_PropertyAsAnObject_SetsReturnTypeCorrectly()
        {
            var obj = new Mock <IObjectGraphTypeTemplate>();

            obj.Setup(x => x.Route).Returns(new GraphFieldPath("[type]/Item0"));
            obj.Setup(x => x.InternalFullName).Returns("Item0");

            var parent   = obj.Object;
            var propInfo = typeof(SimplePropertyObject).GetProperty(nameof(SimplePropertyObject.Hair));
            var template = new PropertyGraphFieldTemplate(parent, propInfo, TypeKind.OBJECT);

            template.Parse();
            template.ValidateOrThrow();

            Assert.AreEqual(typeof(SimplePropertyObject.HairData), template.ObjectType);
        }
        public void Parse_DescriptionAttribute_SetsValue()
        {
            var obj = new Mock <IObjectGraphTypeTemplate>();

            obj.Setup(x => x.Route).Returns(new GraphFieldPath("[type]/Item0"));
            obj.Setup(x => x.InternalFullName).Returns("Item0");

            var parent   = obj.Object;
            var propInfo = typeof(SimplePropertyObject).GetProperty(nameof(SimplePropertyObject.Address1));
            var template = new PropertyGraphFieldTemplate(parent, propInfo, TypeKind.OBJECT);

            template.Parse();
            template.ValidateOrThrow();

            Assert.AreEqual("A Prop Description", template.Description);
        }
        public void Parse_SecurityPolices_AreAdded()
        {
            var obj = new Mock <IObjectGraphTypeTemplate>();

            obj.Setup(x => x.Route).Returns(new GraphFieldPath("[type]/Item0"));
            obj.Setup(x => x.InternalFullName).Returns("Item0");

            var parent   = obj.Object;
            var propInfo = typeof(SimplePropertyObject).GetProperty(nameof(SimplePropertyObject.LastName));
            var template = new PropertyGraphFieldTemplate(parent, propInfo, TypeKind.OBJECT);

            template.Parse();
            template.ValidateOrThrow();

            Assert.AreEqual(1, template.SecurityPolicies.Count());
        }
        public void Parse_InvalidName_ThrowsException()
        {
            var obj = new Mock <IObjectGraphTypeTemplate>();

            obj.Setup(x => x.Route).Returns(new GraphFieldPath("[type]/Item0"));
            obj.Setup(x => x.InternalFullName).Returns("Item0");

            var parent   = obj.Object;
            var propInfo = typeof(SimplePropertyObject).GetProperty(nameof(SimplePropertyObject.City));
            var template = new PropertyGraphFieldTemplate(parent, propInfo, TypeKind.OBJECT);

            template.Parse();

            Assert.Throws <GraphTypeDeclarationException>(() =>
            {
                template.ValidateOrThrow();
            });
        }
예제 #5
0
        public void Parse_DefaultValuesCheck()
        {
            var server = new TestServerBuilder().Build();

            var obj = new Mock <IObjectGraphTypeTemplate>();

            obj.Setup(x => x.Route).Returns(new GraphFieldPath("[type]/Item0"));
            obj.Setup(x => x.InternalFullName).Returns("Item0");

            var parent   = obj.Object;
            var propInfo = typeof(SimplePropertyObject).GetProperty(nameof(SimplePropertyObject.Name));
            var template = new PropertyGraphFieldTemplate(parent, propInfo, TypeKind.OBJECT);

            template.Parse();
            template.ValidateOrThrow();

            var field = this.MakeGraphField(template);

            Assert.IsNotNull(field);
            Assert.AreEqual(Constants.ScalarNames.STRING, field.TypeExpression.TypeName);
            CollectionAssert.AreEqual(TypeExpressions.None.ToTypeWrapperSet(), field.TypeExpression.Wrappers);
        }