示例#1
0
 public void Format_TransformStringAttributeThrowsException_ExceptionIsPropogated()
 {
     var record = new MockRecord()
     {
         StringFieldWithErroredTransformStringAttribute = "test"
     };
     var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.StringFieldWithErroredTransformStringAttribute));
     var formatter      = new TextRecordFieldFormatter();
     var formattedValue = formatter.Format(record.StringFieldWithErroredTransformStringAttribute, property);
 }
示例#2
0
        public void Format_NullStringFieldWithTransformAttribute_FormattedValueIsNull()
        {
            var record = new MockRecord()
            {
                StringFieldWithTransformAttribute = null
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.StringFieldWithTransformAttribute));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.StringFieldWithTransformAttribute, property);

            Assert.IsNull(formattedValue);
        }
示例#3
0
        public void Format_StringFieldWithNoAttributes_FieldIsNotFormatted()
        {
            var record = new MockRecord()
            {
                StringField = "test"
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.StringField));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.StringField, property);

            Assert.AreEqual(record.StringField, formattedValue);
        }
示例#4
0
        public void Format_NullStringFieldWithToStringAndTransformAttributes_FieldIsConvertedToStringViaAttributeAndFormatted()
        {
            var record = new MockRecord()
            {
                StringFieldWithToStringAndTransformAttributes = null
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.StringFieldWithToStringAndTransformAttributes));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.StringFieldWithToStringAndTransformAttributes, property);

            Assert.AreEqual($"|''|", formattedValue);
        }
示例#5
0
        public void Format_EmptyStringFieldWithToStringAttribute_FieldIsConvertedToStringViaAttribute()
        {
            var record = new MockRecord()
            {
                StringFieldWithToStringAttribute = String.Empty
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.StringFieldWithToStringAttribute));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.StringFieldWithToStringAttribute, property);

            Assert.AreEqual($"'{record.StringFieldWithToStringAttribute}'", formattedValue);
        }
示例#6
0
        public void Format_NullNullableIntFieldWithNullableTransformAttribute_FieldIsFormatted()
        {
            var record = new MockRecord()
            {
                NullableIntFieldWithNullableTransformAttribute = null
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.NullableIntFieldWithNullableTransformAttribute));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.NullableIntFieldWithNullableTransformAttribute, property);

            Assert.AreEqual($"|NULL|", formattedValue);
        }
示例#7
0
        public void Format_NonNullOrEmptyNullableIntFieldWithToStringAndTransformAttributes_FieldIsConvertedToStringViaAttributeAndFormatted()
        {
            var record = new MockRecord()
            {
                NullableIntFieldWithToStringAndTransformAttributes = 10
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.NullableIntFieldWithToStringAndTransformAttributes));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.NullableIntFieldWithToStringAndTransformAttributes, property);

            Assert.AreEqual($"|'{record.NullableIntFieldWithToStringAndTransformAttributes}'|", formattedValue);
        }
示例#8
0
        public void Format_NullableIntFieldWithNoAttributes_FieldIsConvertedToStringAndNotFormatted()
        {
            var record = new MockRecord()
            {
                NullableIntField = 10
            };
            var property       = typeof(MockRecord).GetProperty(nameof(MockRecord.NullableIntField));
            var formatter      = new TextRecordFieldFormatter();
            var formattedValue = formatter.Format(record.NullableIntField, property);

            Assert.AreEqual("10", formattedValue);
        }