public void Parse_WithClassLevelGraphSkipAttribute_ThrowsException() { Assert.Throws <GraphTypeDeclarationException>(() => { var template = new ObjectGraphTypeTemplate(typeof(ForcedSkippedObject)); template.Parse(); template.ValidateOrThrow(); }); }
public void Parse_FromAbstractClass_ThrowsException() { Assert.Throws <GraphTypeDeclarationException>(() => { var template = new ObjectGraphTypeTemplate(typeof(BaseItemTemplate)); template.Parse(); template.ValidateOrThrow(); }); }
public void Parse_DescriptionAttribute_SetsCorrectly() { var template = new ObjectGraphTypeTemplate(typeof(DescriptionObject)); template.Parse(); template.ValidateOrThrow(); Assert.IsNotNull(template); Assert.AreEqual("A valid description", template.Description); }
public void Parse_InvalidMethods_ThatAreNotExplicitlyDeclared_AreSkipped() { var template = new ObjectGraphTypeTemplate(typeof(ObjectWithInvalidNonDeclaredMethods)); template.Parse(); template.ValidateOrThrow(); // should have the declared method, the undeclared but valid method, the decalred property // the invalid undeclared method should be dropped silently Assert.AreEqual(3, template.FieldTemplates.Count); }
public void Parse_OverloadedMethodsWithNameClash_ThrowsException() { var template = new ObjectGraphTypeTemplate(typeof(TwoMethodsWithSameName)); template.Parse(); Assert.Throws <GraphTypeDeclarationException>(() => { template.ValidateOrThrow(); }); }
public void Parse_OverloadedMethodsWithNoNameClash_ParsesCorrectly() { var template = new ObjectGraphTypeTemplate(typeof(TwoMethodsWithSameNameWithAttributeDiff)); template.Parse(); template.ValidateOrThrow(); Assert.IsNotNull(template); Assert.AreEqual(2, template.FieldTemplates.Count()); Assert.IsTrue(template.FieldTemplates.ContainsKey($"[type]/{nameof(TwoMethodsWithSameNameWithAttributeDiff)}/{nameof(TwoMethodsWithSameNameWithAttributeDiff.Method1)}")); Assert.IsTrue(template.FieldTemplates.ContainsKey($"[type]/{nameof(TwoMethodsWithSameNameWithAttributeDiff)}/MethodA")); }
public void Parse_PropertiesAreCapturedAsExplictOrImplicitCorrectly() { var template = new ObjectGraphTypeTemplate(typeof(OneMarkedProperty)); template.Parse(); template.ValidateOrThrow(); var totalProps = typeof(OneMarkedProperty).GetProperties().Length; Assert.IsTrue(totalProps == template.FieldTemplates.Count); Assert.AreEqual(1, template.FieldTemplates.Count(x => x.Value.IsExplicitDeclaration)); Assert.AreEqual(1, template.FieldTemplates.Count(x => !x.Value.IsExplicitDeclaration)); }
public void Parse_MethodsAreCapturedAsExplictOrImplicitCorrectly() { var template = new ObjectGraphTypeTemplate(typeof(OneMarkedMethod)); template.Parse(); template.ValidateOrThrow(); var totalMethods = typeof(OneMarkedMethod) .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Count(x => !x.IsSpecialName); Assert.IsTrue(totalMethods == template.FieldTemplates.Count); Assert.AreEqual(1, template.FieldTemplates.Count(x => x.Value.IsExplicitDeclaration)); Assert.AreEqual(1, template.FieldTemplates.Count(x => !x.Value.IsExplicitDeclaration)); }
public void Parse_GeneralPropertySettings_SetCorrectly() { var template = new ObjectGraphTypeTemplate(typeof(SimpleObjectNoMethods)); template.Parse(); template.ValidateOrThrow(); Assert.IsNotNull(template); Assert.AreEqual("[type]/SimpleObjectNoMethods", template.Route.Path); Assert.AreEqual(null, template.Description); Assert.AreEqual(typeof(SimpleObjectNoMethods), template.ObjectType); Assert.AreEqual(0, template.FieldTemplates.Count()); Assert.AreEqual("SimpleObjectNoMethods", template.Name); }