Exemple #1
0
        public void GetClrTypeNameShouldReturnSystemNullableStructureTemplate()
        {
            var edmPrimitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.DateTimeOffset);
            IEdmTypeReference edmTypeReference = new EdmTypeReferenceForTest(edmPrimitiveType, true);

            ODataT4CodeGenerator.Utils.GetClrTypeName(edmTypeReference, false, template, context).Should().Be("global::System.Nullable<global::System.DateTimeOffset>");
        }
Exemple #2
0
        public void GetClrTypeNameShouldReturnPrimitiveTypeNameForNullableIEdmPrimitiveType()
        {
            var edmPrimitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.String);
            IEdmTypeReference edmTypeReference = new EdmTypeReferenceForTest(edmPrimitiveType, true);

            ODataT4CodeGenerator.Utils.GetClrTypeName(edmTypeReference, false, template, context).Should().Be("string");
        }
Exemple #3
0
        public void GetPropertyInitializationValueShouldNotThrowOnPropertyNotInCollectionType()
        {
            var primitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.String);
            IEdmTypeReference edmTypeReference = new EdmTypeReferenceForTest(primitiveType, false);
            var property = new EdmPropertyForTest(new EdmStructruedTypeForTest(), "propertyName", edmTypeReference);

            ODataT4CodeGenerator.Utils.GetPropertyInitializationValue(property, false, template, context).Should().BeNull();
        }
Exemple #4
0
        public void GetClrTypeNameShouldReturnObjectModelCollectionStructureTemplate()
        {
            var primitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.String);
            IEdmTypeReference  elementTypeReference    = new EdmTypeReferenceForTest(primitiveType, false);
            IEdmCollectionType collectionType          = new EdmCollectionType(elementTypeReference);
            IEdmTypeReference  collectionTypeReference = new EdmTypeReferenceForTest(collectionType, false);

            ODataT4CodeGenerator.Utils.GetClrTypeName(collectionTypeReference, false, template, context).Should().Be("global::System.Collections.ObjectModel.Collection<string>");
        }
Exemple #5
0
        public void GetPropertyInitializationValueShouldReturnConstructorWithNoParametersForElementsInPrimitiveType()
        {
            var primitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.String);
            IEdmTypeReference           elementTypeReference    = new EdmTypeReferenceForTest(primitiveType, false);
            IEdmCollectionType          collectionType          = new EdmCollectionType(elementTypeReference);
            IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType);
            var property = new EdmPropertyForTest(new EdmStructruedTypeForTest(), "propertyName", collectionTypeReference);

            ODataT4CodeGenerator.Utils.GetPropertyInitializationValue(property, false, template, context).Should().Be("new global::System.Collections.ObjectModel.Collection<string>()");
        }
Exemple #6
0
        public void GetClrTypeNameShouldReturnUnderlyingTypeForTypeDefinition(EdmPrimitiveTypeKind primitiveTypeKind, bool isReferenceType)
        {
            var underlyingType                  = new EdmPrimitiveType(primitiveTypeKind);
            var typeDefinition                  = new EdmTypeDefinition("namespace", "Field", underlyingType);
            var typeDefinitionReference         = new EdmTypeDefinitionReference(typeDefinition, false);
            var nullableTypeDefinitionReference = new EdmTypeDefinitionReference(typeDefinition, true);

            var underlyingTypeName = ODataT4CodeGenerator.Utils.GetClrTypeName(underlyingType, template);
            var nullableName       = isReferenceType ? underlyingTypeName : $"global::System.Nullable<{underlyingTypeName}>";

            ODataT4CodeGenerator.Utils.GetClrTypeName(typeDefinitionReference, false, template, context).Should().Be(underlyingTypeName);
            ODataT4CodeGenerator.Utils.GetClrTypeName(nullableTypeDefinitionReference, false, template, context).Should().Be(nullableName);
        }