public void FindConcreteTypes_UnionType_IsExpandedCorrectly() { var server = new TestServerBuilder().Build(); var collection = new SchemaTypeCollection(); var unionTypeMaker = new UnionGraphTypeMaker(server.Schema); var unionType = unionTypeMaker.CreateGraphType(new PersonUnionData(), TypeKind.OBJECT); var personType = this.MakeGraphType(typeof(PersonData), TypeKind.OBJECT) as IObjectGraphType; var employeeType = this.MakeGraphType(typeof(EmployeeData), TypeKind.OBJECT) as IObjectGraphType; collection.EnsureGraphType(personType, typeof(PersonData)); collection.EnsureGraphType(employeeType, typeof(EmployeeData)); collection.EnsureGraphType(unionType); // extract all hte possible concrete types for the interface, should be person and employee var types = collection.FindConcreteTypes(unionType); Assert.IsNotNull(types); Assert.AreEqual(2, types.Count()); CollectionAssert.Contains(types, typeof(PersonData)); CollectionAssert.Contains(types, typeof(EmployeeData)); }
public void AnalyzeRuntimeConcreteType_UnionTypeResolve_ReturnsInvalidType_TypeIsNotReturned() { var server = new TestServerBuilder().Build(); var collection = new SchemaTypeCollection(); var unionTypeMaker = new UnionGraphTypeMaker(server.Schema); var unionType = unionTypeMaker.CreateGraphType(new InvalidUnionForAnalysis(), TypeKind.OBJECT); var addressType = this.MakeGraphType(typeof(AddressData), TypeKind.OBJECT) as IObjectGraphType; var countryType = this.MakeGraphType(typeof(CountryData), TypeKind.OBJECT) as IObjectGraphType; collection.EnsureGraphType(addressType, typeof(AddressData)); collection.EnsureGraphType(countryType, typeof(CountryData)); collection.EnsureGraphType(unionType); // the union always returns address data var result = collection.AnalyzeRuntimeConcreteType(unionType, typeof(EmployeeData)); Assert.IsNotNull(result); Assert.AreEqual(typeof(EmployeeData), result.CheckedType); Assert.False(result.ExactMatchFound); Assert.AreEqual(0, result.FoundTypes.Length); }
public void ActionTemplate_CreateUnionType_PropertyCheck() { var schema = new GraphSchema(); schema.SetNoAlterationConfiguration(); var action = TemplateHelper.CreateActionMethodTemplate <UnionTestController>(nameof(UnionTestController.TwoTypeUnion)); var union = new UnionGraphTypeMaker(schema).CreateGraphType(action.UnionProxy, TypeKind.OBJECT); Assert.IsNotNull(union); Assert.IsTrue(union is UnionGraphType); Assert.AreEqual("FragmentData", union.Name); Assert.IsNull(union.Description); Assert.AreEqual(2, union.PossibleGraphTypeNames.Count()); Assert.AreEqual(2, union.PossibleConcreteTypes.Count()); Assert.IsTrue(union.PossibleGraphTypeNames.Contains(nameof(UnionDataA))); Assert.IsTrue(union.PossibleGraphTypeNames.Contains(nameof(UnionDataB))); Assert.IsTrue(union.PossibleConcreteTypes.Contains(typeof(UnionDataA))); Assert.IsTrue(union.PossibleConcreteTypes.Contains(typeof(UnionDataB))); }