Exemplo n.º 1
0
        public void ApplyTransform_InvalidType_ExceptionIsThrown()
        {
            var record = new MockRecord()
            {
                StringField = "Test"
            };
            var decimals         = 0;
            var midpointRounding = MidpointRounding.AwayFromZero;
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.StringField));
            var roundToAttribute = new RoundToAttribute(decimals, midpointRounding);

            roundToAttribute.ApplyTransform(property, record);
        }
Exemplo n.º 2
0
        public void ApplyTransform_NullableDoubleFieldWithValue_ValueIsRounded()
        {
            var record = new MockRecord()
            {
                NullableDoubleField = 10.5d
            };
            var decimals         = 0;
            var midpointRounding = MidpointRounding.ToEven;
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.NullableDoubleField));
            var roundToAttribute = new RoundToAttribute(decimals, midpointRounding);

            roundToAttribute.ApplyTransform(property, record);

            Assert.AreEqual(10d, record.NullableDoubleField);
        }
Exemplo n.º 3
0
        public void ApplyTransform_DecimalFieldMidwayValueWithAwayFromZeroRounding_ValueIsRoundedUp()
        {
            var record = new MockRecord()
            {
                DecimalField = 10.5m
            };
            var decimals         = 0;
            var midpointRounding = MidpointRounding.AwayFromZero;
            var property         = typeof(MockRecord).GetProperty(nameof(MockRecord.DecimalField));
            var roundToAttribute = new RoundToAttribute(decimals, midpointRounding);

            roundToAttribute.ApplyTransform(property, record);

            Assert.AreEqual(11m, record.DecimalField);
        }