Ejemplo n.º 1
0
    public void InvStringThousands()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert("1234.456");

        Assert.AreEqual(1234.456m, result);
    }
Ejemplo n.º 2
0
    public void InvStringThousandsTooBig()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert("123456789012345678901234567890.456");

        Assert.AreEqual(null, result);
    }
Ejemplo n.º 3
0
        public void Decimal_Converter_Test()
        {
            IConverter binaryConverter = new DecimalConverter(new DecimalNumber("123.456"));
            var        converted       = binaryConverter.Convert();

            converted.IntegerPart.Should().Be("123");
            converted.FloatPart.Should().Be("456");
            converted.Base.Should().Be(10);
            converted.ToString().Should().Be("123.456");

            binaryConverter = new DecimalConverter(new OctalNumber("123.456"));
            converted       = binaryConverter.Convert();
            converted.IntegerPart.Should().Be("83");
            converted.FloatPart.Should().Be("589844");
            converted.Base.Should().Be(10);
            converted.ToString().Should().Be("83.589844");

            binaryConverter = new DecimalConverter(new HexadecimalNumber("123.456"));
            converted       = binaryConverter.Convert();
            converted.IntegerPart.Should().Be("291");
            converted.FloatPart.Should().Be("270996");
            converted.Base.Should().Be(10);
            converted.ToString().Should().Be("291.270996");

            binaryConverter = new DecimalConverter(new BinaryNumber("101.111"));
            converted       = binaryConverter.Convert();
            converted.IntegerPart.Should().Be("5");
            converted.FloatPart.Should().Be("875");
            converted.Base.Should().Be(10);
            converted.ToString().Should().Be("5.875");
        }
Ejemplo n.º 4
0
    public void FromDecimal()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert(71m / 49m);

        Assert.AreEqual(71m / 49m, result);
    }
Ejemplo n.º 5
0
    public void InvString()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert("1.234");

        Assert.AreEqual(1.234m, result);
    }
Ejemplo n.º 6
0
    public void FromFloat()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert(4f / 5f);

        Assert.AreEqual((decimal)(4f / 5f), result);
    }
Ejemplo n.º 7
0
    public void FromUInt()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert(77u);

        Assert.AreEqual(77m, result);
    }
Ejemplo n.º 8
0
    public void FromUShort()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert((ushort)77);

        Assert.AreEqual(77m, result);
    }
Ejemplo n.º 9
0
    public void FromULong()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert(ulong.MaxValue);

        Assert.AreEqual((decimal)ulong.MaxValue, result);
    }
Ejemplo n.º 10
0
    public void FromByte()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert((byte)77);

        Assert.AreEqual(77m, result);
    }
Ejemplo n.º 11
0
    public void FromDouble()
    {
        var converter = new DecimalConverter();
        var result    = converter.Convert(4d / 5d);

        Assert.AreEqual((decimal)(4d / 5d), result);
    }
Ejemplo n.º 12
0
 public void DecimalConverterTest()
 {
     Assert.That(DecimalConverter.Convert(new Decimal(4.23322)), Is.EqualTo("4.23322"));
     Assert.That(DecimalConverter.Convert(new Decimal(-4.23322)), Is.EqualTo("-4.23322"));
     Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(new Decimal(4332.33)));
     Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("2.32a34"); });
     Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("+1.2"); });
     Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("(1.2)"); });
     Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(""); });
     Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(null); });
 }
Ejemplo n.º 13
0
        public override OpenOrderEntryModel RequestNewOrder(CreateOrderRequestBase orderNewRequest)
        {
            var order = new CreateOrderRequest(this)
            {
                Volume    = orderNewRequest.Amount,
                Price     = DecimalConverter.Convert(orderNewRequest.Price),
                OrderType = orderNewRequest.OrderType.Value,
                Type      = orderNewRequest.Side.Value,
                Pair      = orderNewRequest.Pair,
                Validate  = orderNewRequest.Validate,
            };

            var response = order.Request <CreateOrderResponse>();

            return(OnCreateOrder(response, response));
        }
Ejemplo n.º 14
0
        public override OpenOrderEntryModel RequestNewOrder(CreateOrderRequestBase orderNewRequest)
        {
            var order = new CreateOrderRequest(this)
            {
                Amount   = DecimalConverter.Convert(orderNewRequest.Amount),
                Price    = DecimalConverter.Convert(orderNewRequest.Price),
                IsHidden = orderNewRequest.IsHidden,
                Exchange = orderNewRequest.ExchangeType.Value,
                Type     = orderNewRequest.OrderType.Value,
                Side     = orderNewRequest.Side.Value,
                Symbol   = orderNewRequest.Pair
            };

            var response = order.Request <CreateOrderResponse>();

            return(OnCreateOrder(response, response));
        }
Ejemplo n.º 15
0
        public void Conversion()
        {
            // Arrange
            IConverter converter     = new DecimalConverter();
            var        value         = "42,1";
            var        expectedValue = (Decimal)42.1;

            // Act
            using (new LangageSwitcher("fr-fr"))
            {
                var actualValue = converter.Convert(value, converter.TargetType);

                // Assert
                Assert.NotNull(actualValue);
                Assert.IsType <decimal>(actualValue);
                Assert.Equal(expectedValue, (Decimal)actualValue);
            }
        }
Ejemplo n.º 16
0
        public void DecimalConverterTest()
        {
            Assert.That(DecimalConverter.Convert(new Decimal(4.23322)), Is.EqualTo("4.23322"));
            Assert.That(DecimalConverter.Convert(new Decimal(-4.23322)), Is.EqualTo("-4.23322"));
            Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(new Decimal(4332.33)));
            Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("2.32a34"); });
            Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("+1.2"); });
            Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("(1.2)"); });
            Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(""); });
            Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(null); });

            // check for a different culture than en-XX
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("tr-TR");
            Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(new Decimal(4332.33)));
            Assert.That(DecimalConverter.Convert("-2.33"), Is.EqualTo(new Decimal(-2.33)));
            Assert.That(DecimalConverter.Convert(new Decimal(4.23322)), Is.EqualTo("4.23322"));
            Assert.That(DecimalConverter.Convert(new Decimal(-4.23322)), Is.EqualTo("-4.23322"));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Gets the decimal value of a field
 /// </summary>
 /// <param name="tag">the FIX tag</param>
 /// <returns>the decimal value</returns>
 /// <exception cref="FieldNotFoundException" />
 public Decimal GetDecimal(int tag)
 {
     try
     {
         Fields.IField fld = _fields[tag];
         if (fld.GetType() == typeof(DecimalField))
         {
             return(((DecimalField)fld).Obj);
         }
         else
         {
             return(DecimalConverter.Convert(fld.ToString()));
         }
     }
     catch (System.Collections.Generic.KeyNotFoundException)
     {
         throw new FieldNotFoundException(tag);
     }
 }
Ejemplo n.º 18
0
 public void DecimalConverter_WithoutLeadingTrailingZeros()
 {
     Assert.That(DecimalConverter.Convert("23."), Is.EqualTo(new Decimal(23)));
     Assert.That(DecimalConverter.Convert(".23"), Is.EqualTo(new Decimal(0.23)));
     Assert.That(DecimalConverter.Convert("-.23"), Is.EqualTo(new Decimal(-0.23)));
 }
Ejemplo n.º 19
0
        public void BadValueConversion()
        {
            // Arrange
            IConverter converter = new DecimalConverter();
            var        value     = "Hello";
            var        expectedExceptionMessage      = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(decimal));
            var        expectedInnerExceptionMessage = "Input string was not in a correct format.";

            // Act
            using (new LangageSwitcher("en-us"))
            {
                var actualException = Assert.Throws <CommandLineParserException>(() => converter.Convert(value, converter.TargetType));

                // Assert
                Assert.Equal(expectedExceptionMessage, actualException.Message);
                Assert.NotNull(actualException.InnerException);
                var actualInnerExecption = Assert.IsAssignableFrom <FormatException>(actualException.InnerException);
                Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message);
            }
        }