コード例 #1
0
        public void ApplyTransform_IntField_ExceptionIsThrown()
        {
            var record = new MockRecord()
            {
                IntField = 10
            };
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.IntField));
            var trimEndAttribute = new TrimEndAttribute();

            trimEndAttribute.ApplyTransform(property, record);
        }
コード例 #2
0
        public void ApplyTransform_StringFieldWithSpacesOnLeftAndRight_TextIsTrimmedAtEnd()
        {
            var record = new MockRecord()
            {
                StringField = "  test  "
            };
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.StringField));
            var trimEndAttribute = new TrimEndAttribute();

            trimEndAttribute.ApplyTransform(property, record);

            Assert.AreEqual("  test", record.StringField);
        }
コード例 #3
0
        public void ApplyTransform_StringFieldWithOnlySpaces_ValueIsTrimmedToEmpty()
        {
            var record = new MockRecord()
            {
                StringField = "   "
            };
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.StringField));
            var trimEndAttribute = new TrimEndAttribute();

            trimEndAttribute.ApplyTransform(property, record);

            Assert.AreEqual("", record.StringField);
        }
コード例 #4
0
        public void ApplyTransform_StringFieldWithNullValue_ValueIsUnchanged()
        {
            var record = new MockRecord()
            {
                StringField = null
            };
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.StringField));
            var trimEndAttribute = new TrimEndAttribute();

            trimEndAttribute.ApplyTransform(property, record);

            Assert.IsNull(record.StringField);
        }
コード例 #5
0
        public void ApplyTransform_StringFieldWithCustomTrimCharsOnLeftAndRight_TextIsTrimmed()
        {
            var trimChars = new char[] { 'X', 'Y' };
            var record    = new MockRecord()
            {
                StringField = "XYtestXY"
            };
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.StringField));
            var trimEndAttribute = new TrimEndAttribute(trimChars);

            trimEndAttribute.ApplyTransform(property, record);

            Assert.AreEqual("XYtest", record.StringField);
        }