Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
 private void ShouldThrowArgumentNullExceptionWhenGettingMetadata(
     StringMetaProvider sut
     )
 {
     Assert.Throws <ArgumentNullException>(() => sut.GetMetadata(null).ToArray());
 }