Exemple #1
0
        private void ShouldGetTypeCodeFromTypeCodeExtractor(
            [Frozen] Mock <ITypeCodeExtractor> typeMock,
            FieldGenerationContext fieldGenerationContext,
            StringMetaProvider sut)
        {
            var _ = sut.GetMetadata(fieldGenerationContext)
                    .ToArray();

            typeMock.Verify(t => t.GetTypeCode(fieldGenerationContext.FieldDescriptor.PropertyType), Times.Once);
        }
Exemple #2
0
        private void ShouldGetDataTypeAttributeFromDataTypeAttributeExtractor(
            [Frozen] Mock <ITypeCodeExtractor> typeMock,
            [Frozen] Mock <IDataTypeAttributeExtractor> dataTypeMock,
            FieldGenerationContext fieldGenerationContext,
            StringMetaProvider sut)
        {
            typeMock.Setup(t => t.GetTypeCode(It.IsAny <System.Type>()))
            .Returns(TypeCode.String);

            var _ = sut.GetMetadata(fieldGenerationContext)
                    .ToArray();

            dataTypeMock.Verify(t => t.GetDataTypeAttribute(fieldGenerationContext.FieldDescriptor.CustomAttributes), Times.Once);
        }
Exemple #3
0
        private void ShouldReturnEmptyMetadata(
            TypeCode typeCode,
            FieldGenerationContext fieldGenerationContext,
            [Frozen] Mock <ITypeCodeExtractor> typeMock,
            StringMetaProvider sut)
        {
            typeMock.Setup(t => t.GetTypeCode(It.IsAny <System.Type>()))
            .Returns(typeCode);

            var meta = sut.GetMetadata(fieldGenerationContext)
                       .ToArray();

            Assert.Empty(meta);
        }
Exemple #4
0
 private void ShouldCreateInstance(
     IStringPropertyTypeMap stringPropertyTypeMap,
     ITypeCodeExtractor typeCodeExtractor,
     IDataTypeAttributeExtractor dataTypeAttributeExtractor
     )
 {
     try
     {
         var _ = new StringMetaProvider(stringPropertyTypeMap, typeCodeExtractor, dataTypeAttributeExtractor);
     }
     catch
     {
         Assert.True(false, "Exception was thrown when none was expected!");
     }
 }
Exemple #5
0
        private void ShouldPassDataTypeToStringPropertyTypeMap(
            [Frozen] Mock <ITypeCodeExtractor> typeMock,
            [Frozen] Mock <IDataTypeAttributeExtractor> dataTypeMock,
            [Frozen] Mock <IStringPropertyTypeMap> stringPropertyTypeMap,
            FieldGenerationContext fieldGenerationContext,
            StringMetaProvider sut,
            DataTypeAttribute expectedDataTypeAttribute)
        {
            typeMock.Setup(t => t.GetTypeCode(It.IsAny <System.Type>()))
            .Returns(TypeCode.String);
            dataTypeMock.Setup(t => t.GetDataTypeAttribute(fieldGenerationContext.FieldDescriptor.CustomAttributes))
            .Returns(expectedDataTypeAttribute);

            var _ = sut.GetMetadata(fieldGenerationContext)
                    .ToArray();

            stringPropertyTypeMap.Verify(m => m.MapDataType(expectedDataTypeAttribute.DataType), Times.Once);
        }
Exemple #6
0
        private void ShouldFallbackToTypeText(
            [Frozen] Mock <ITypeCodeExtractor> typeMock,
            [Frozen] Mock <IDataTypeAttributeExtractor> dataTypeMock,
            FieldGenerationContext fieldGenerationContext,
            StringMetaProvider sut)
        {
            typeMock.Setup(t => t.GetTypeCode(It.IsAny <System.Type>()))
            .Returns(TypeCode.String);
            dataTypeMock.Setup(t => t.GetDataTypeAttribute(fieldGenerationContext.FieldDescriptor.CustomAttributes))
            .Returns(null as DataTypeAttribute);

            var meta = sut.GetMetadata(fieldGenerationContext)
                       .ToArray();

            Assert.Equal(new[]
            {
                new KeyValuePair <string, object>("type", "text")
            }, meta);
        }
Exemple #7
0
        private void ShouldReturnMetadataFromTypeMap(
            [Frozen] Mock <ITypeCodeExtractor> typeMock,
            [Frozen] Mock <IDataTypeAttributeExtractor> dataTypeMock,
            [Frozen] Mock <IStringPropertyTypeMap> stringPropertyTypeMap,
            FieldGenerationContext fieldGenerationContext,
            StringMetaProvider sut,
            DataTypeAttribute expectedDataTypeAttribute,
            string type)
        {
            typeMock.Setup(t => t.GetTypeCode(It.IsAny <System.Type>()))
            .Returns(TypeCode.String);
            dataTypeMock.Setup(t => t.GetDataTypeAttribute(fieldGenerationContext.FieldDescriptor.CustomAttributes))
            .Returns(expectedDataTypeAttribute);
            stringPropertyTypeMap.Setup(m => m.MapDataType(expectedDataTypeAttribute.DataType))
            .Returns(type);

            var meta = sut.GetMetadata(fieldGenerationContext)
                       .ToArray();

            Assert.Equal(new[]
            {
                new KeyValuePair <string, object>("type", type)
            }, meta);
        }
Exemple #8
0
 private void ShouldThrowArgumentNullExceptionWhenGettingMetadata(
     StringMetaProvider sut
     )
 {
     Assert.Throws <ArgumentNullException>(() => sut.GetMetadata(null).ToArray());
 }