public void CreateTypeNameExpression_ReturnsConditionalExpression_IfTypeHasDerivedTypes() { // Arrange IEdmEntityType baseType = new EdmEntityType("NS", "BaseType"); IEdmEntityType typeA = new EdmEntityType("NS", "A", baseType); IEdmEntityType typeB = new EdmEntityType("NS", "B", baseType); IEdmEntityType typeAA = new EdmEntityType("NS", "AA", typeA); IEdmEntityType typeAAA = new EdmEntityType("NS", "AAA", typeAA); IEdmEntityType[] types = new[] { baseType, typeA, typeAAA, typeB, typeAA }; EdmModel model = new EdmModel(); foreach (var type in types) { model.AddElement(type); model.SetAnnotationValue(type, new ClrTypeAnnotation(new MockType(type.Name, @namespace: type.Namespace))); } Expression source = Expression.Constant(42); // Act Expression result = SelectExpandBinder.CreateTypeNameExpression(source, baseType, model); // Assert Assert.Equal( @"IIF((42 Is AAA), ""NS.AAA"", IIF((42 Is AA), ""NS.AA"", IIF((42 Is B), ""NS.B"", IIF((42 Is A), ""NS.A"", ""NS.BaseType""))))", result.ToString()); }
public void CreateTypeNameExpression_ReturnsNull_IfTypeHasNoDerivedTypes() { // Arrange IEdmEntityType baseType = new EdmEntityType("NS", "BaseType"); EdmModel model = new EdmModel(); model.AddElement(baseType); Expression source = Expression.Constant(42); // Act Expression result = SelectExpandBinder.CreateTypeNameExpression(source, baseType, model); // Assert Assert.Null(result); }
public void CreateTypeNameExpression_ReturnsFullTypeName_IfTypeHasNoDerivedTypes() { // Arrange IEdmEntityType baseType = new EdmEntityType("NS", "BaseType"); EdmModel model = new EdmModel(); model.AddElement(baseType); Expression source = Expression.Constant(42); // Act Expression result = SelectExpandBinder.CreateTypeNameExpression(source, baseType, model); // Assert Assert.Equal(ExpressionType.Constant, result.NodeType); Assert.Equal(baseType.FullTypeName(), (result as ConstantExpression).Value); }