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); }
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); }
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); }
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!"); } }
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); }
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); }
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); }
private void ShouldThrowArgumentNullExceptionWhenGettingMetadata( StringMetaProvider sut ) { Assert.Throws <ArgumentNullException>(() => sut.GetMetadata(null).ToArray()); }