Exemplo n.º 1
0
        public void TestDecimalsMaximalFractionDigits()
        {
            var number = new FormatNumber();

            number.Value             = new MockAttribute(new Property("anumber"));
            number.MaxFractionDigits = new MockAttribute(new Constant("5"));
            _model.Model["anumber"]  = 1.23456789m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("1.23457"));
            _model.Model["anumber"] = 1.23m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("1.23"));
        }
Exemplo n.º 2
0
        public void TestDecimalsMinimalIntegerDigitsWithDefault()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.MinIntegerDigits = new MockAttribute(new Constant("10"));
            _model.Model["anumber"] = 12345m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("0,000,012,345.00"));
            _model.Model["anumber"] = 1234567890123m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("1,234,567,890,123.00"));
        }
Exemplo n.º 3
0
        public void TestDecimalsMaximalIntegerDigits()
        {
            var number = new FormatNumber();

            number.Value             = new MockAttribute(new Property("anumber"));
            number.MaxIntegerDigits  = new MockAttribute(new Constant("10"));
            number.GroupingUsed      = new MockAttribute(new Constant("false"));
            number.MaxFractionDigits = new MockAttribute(new Constant("0"));
            _model.Model["anumber"]  = 12345m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("12345"));
            _model.Model["anumber"] = 1234567890123m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("4567890123"));
        }
Exemplo n.º 4
0
        public void TestSimpleFormatOfIntWithGroupingDefault()
        {
            var number = new FormatNumber();

            number.Value = new MockAttribute(new Constant("1000"));
            Assert.That(number.Evaluate(_model), Is.EqualTo("1,000.00"));
        }
Exemplo n.º 5
0
        public void TestDecimalsRoundingUp()
        {
            var number = new FormatNumber();

            number.Value = new MockAttribute(new Constant("1.26789"));
            Assert.That(number.Evaluate(_model), Is.EqualTo("1.27"));
        }
Exemplo n.º 6
0
        public void TestSimpleFormatOfIntWithGroupingExplicitTrueBigNumberWithDecimals()
        {
            var number = new FormatNumber();

            number.Value        = new MockAttribute(new Constant("123456789.876543"));
            number.GroupingUsed = new MockAttribute(new Constant("true"));
            Assert.That(number.Evaluate(_model), Is.EqualTo("123,456,789.88"));
        }
Exemplo n.º 7
0
        public void TestSimpleFormatOfIntWithGroupingExplicitFalseBigNumber()
        {
            var number = new FormatNumber();

            number.Value        = new MockAttribute(new Constant("123456789"));
            number.GroupingUsed = new MockAttribute(new Constant("false"));
            Assert.That(number.Evaluate(_model), Is.EqualTo("123456789.00"));
        }
Exemplo n.º 8
0
        public void TestSimpleFormatOfString()
        {
            var number = new FormatNumber();

            number.Value = new MockAttribute(new Constant("1"));

            Assert.That(number.Evaluate(_model), Is.EqualTo("1.00"));
        }
Exemplo n.º 9
0
        public void TestSimpleFormatOfStringDifferentCultureInPageModel()
        {
            var number = new FormatNumber();

            number.Value = new MockAttribute(new Constant("1"));
            _model.Page[FormatConstants.LOCALE] = new CultureInfo("nl-NL");
            Assert.That(number.Evaluate(_model), Is.EqualTo("1,00"));
        }
Exemplo n.º 10
0
        public void TestSimpleFormatOfNegativeInt()
        {
            _model.Model["anumber"] = -1;
            var number = new FormatNumber();

            number.Value = new MockAttribute(new Property("anumber"));
            Assert.That(number.Evaluate(_model), Is.EqualTo("-1.00"));
        }
Exemplo n.º 11
0
        public void TestFormatOfPercentageWithDecimals()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.Type             = new MockAttribute(new Constant("Percentage"));
            _model.Model["anumber"] = 0.012m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("1.20%"));
        }
Exemplo n.º 12
0
        public void TestFormatOfPercentageNegative()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.Type             = new MockAttribute(new Constant("Percentage"));
            _model.Model["anumber"] = -0.12m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("-12.00%"));
        }
Exemplo n.º 13
0
        public void TestFormatOfNumberWithCustomPattern()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.Pattern          = new MockAttribute(new Constant("###,'abc',###.00000"));
            _model.Model["anumber"] = 123456.789;
            Assert.That(number.Evaluate(_model), Is.EqualTo("123,abc456.78900"));
        }
Exemplo n.º 14
0
        public void TestFormatOfNumberExplicit()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.Type             = new MockAttribute(new Constant("Number"));
            _model.Model["anumber"] = 12;
            Assert.That(number.Evaluate(_model), Is.EqualTo("12.00"));
        }
Exemplo n.º 15
0
        public void TestFormatOfNegativeCurrency()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.Type             = new MockAttribute(new Constant("Currency"));
            _model.Model["anumber"] = -12m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("($12.00)")); //Stupid us formatting
        }
Exemplo n.º 16
0
        public void TestDecimalsMinimalAndMaximalFractionDigitsNegative()
        {
            var number = new FormatNumber();

            number.Value             = new MockAttribute(new Property("anumber"));
            number.MinFractionDigits = new MockAttribute(new Constant("3"));
            number.MaxFractionDigits = new MockAttribute(new Constant("5"));
            _model.Model["anumber"]  = -1.23m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("-1.230"));
            _model.Model["anumber"] = -1.234m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("-1.234"));
            _model.Model["anumber"] = -1.2345m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("-1.2345"));
            _model.Model["anumber"] = -1.23456m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("-1.23456"));
            _model.Model["anumber"] = -1.234567m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("-1.23457"));
        }
Exemplo n.º 17
0
        public void TestFormatOfPercentageWithAlternativePattern()
        {
            var number = new FormatNumber();

            number.Value             = new MockAttribute(new Property("anumber"));
            number.Type              = new MockAttribute(new Constant("Percentage"));
            number.MinFractionDigits = new MockAttribute(new Constant("6"));
            _model.Model["anumber"]  = 0.12;
            Assert.That(number.Evaluate(_model), Is.EqualTo("12.000000%"));
        }
Exemplo n.º 18
0
        public void TestFormatOfCurrencyWithDifferentCurrencySymbol()
        {
            var number = new FormatNumber();

            number.Value            = new MockAttribute(new Property("anumber"));
            number.Type             = new MockAttribute(new Constant("Currency"));
            number.CurrencySymbol   = new MockAttribute(new Constant("@"));
            _model.Model["anumber"] = 12m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("@12.00"));
        }
Exemplo n.º 19
0
        public void TestFormatOfCurrencyWithDifferentCurrencySymbolOverridesCodeWithAlternativePattern()
        {
            var number = new FormatNumber();

            number.Value             = new MockAttribute(new Property("anumber"));
            number.Type              = new MockAttribute(new Constant("Currency"));
            number.CurrencySymbol    = new MockAttribute(new Constant("@"));
            number.CurrencyCode      = new MockAttribute(new Constant("RESL"));
            number.MinFractionDigits = new MockAttribute(new Constant("6"));
            _model.Model["anumber"]  = 12m;
            Assert.That(number.Evaluate(_model), Is.EqualTo("@12.000000"));
        }
Exemplo n.º 20
0
        public void TestEmpty()
        {
            var number = new FormatNumber();

            Assert.That(number.Evaluate(_model), Is.EqualTo(String.Empty));
        }