Exemplo n.º 1
0
    public void ConvertTheory(string stringToConvert, double expected)
    {
        var converter = new StringToDoubleConverter();
        var result    = (double)converter.Convert(stringToConvert, typeof(double), null, CultureInfo.CurrentCulture);

        Assert.Equal(expected, result);
    }
Exemplo n.º 2
0
    public void ConvertBackTheory(double doubleToConvert, string expected)
    {
        var converter = new StringToDoubleConverter();
        var result    = (string)converter.ConvertBack(doubleToConvert, typeof(string), null, CultureInfo.CurrentCulture);

        Assert.Equal(expected, result);
    }
Exemplo n.º 3
0
        public void When_TwoWay_And_ConvertBack_Normal_Binding()
        {
            var dp1 = new MyDP();
            var dp2 = new MyDP();

            var conv    = new StringToDoubleConverter();
            var binding = new Binding
            {
                Source    = dp1,
                Path      = new PropertyPath(nameof(MyDP.MyDouble)),
                Mode      = BindingMode.TwoWay,
                Converter = conv
            };

            BindingOperations.SetBinding(dp2, MyDP.MyStringProperty, binding);

            Assert.AreEqual("¤0.00", dp2.MyString);
            Assert.AreEqual(1, conv.ConvertCount);
            Assert.AreEqual(0, conv.ConvertBackCount);

            dp2.MyString = "42";

            // For normal bindings, the source update through the converter
            // is ignored. Therefore, only the ConvertBack method is invoked as
            // the UpdateSource method is ignored because a two-way binding is
            // in progress. This behavior is different with x:Bind.
            Assert.AreEqual("42", dp2.MyString);
            Assert.AreEqual(42, dp1.MyDouble);
            Assert.AreEqual(1, conv.ConvertCount);
            Assert.AreEqual(1, conv.ConvertBackCount);
        }
Exemplo n.º 4
0
    public void ConvertBackNotSupportedType()
    {
        const int intToConvert = 1;
        var       converter    = new StringToDoubleConverter();

        Assert.Throws <InvalidOperationException>(() => converter.ConvertBack(intToConvert, typeof(string), null,
                                                                              CultureInfo.CurrentCulture));
    }
Exemplo n.º 5
0
 public void ValidateStringToDoubleConverter()
 {
     StringToDoubleConverter stdconverter = new StringToDoubleConverter();
     string str = stdconverter.ConvertBackward(1.234);
     Assert.AreEqual("1.234", str);
     double doubleVal = stdconverter.ConvertForward("1.234");
     Assert.AreEqual(1.234d, doubleVal);
 }
Exemplo n.º 6
0
        public void DoubleToStringConverter(double value, string expectedResult)
        {
            var doubletostring = new StringToDoubleConverter();

            var result = doubletostring.ConvertBack(value, typeof(StringToDoubleConverter_tests), null,
                                                    CultureInfo.CurrentCulture);

            Assert.Equal(result, expectedResult);
        }
Exemplo n.º 7
0
        public void StringToDoubleConverter(string value, double expectedResult)
        {
            var stringToDoubleConverter = new StringToDoubleConverter();

            var result = stringToDoubleConverter.Convert(value, typeof(StringToDoubleConverter_tests), null,
                                                         CultureInfo.CurrentCulture);

            Assert.Equal(result, expectedResult);
        }
Exemplo n.º 8
0
        public void ValidateStringToDoubleConverter()
        {
            StringToDoubleConverter stdconverter = new StringToDoubleConverter();
            string str = stdconverter.ConvertBackward(1.234);

            Assert.AreEqual("1.234", str);
            double doubleVal = stdconverter.ConvertForward("1.234");

            Assert.AreEqual(1.234d, doubleVal);
        }
Exemplo n.º 9
0
        public double ReadDouble()
        {
            SkipWhiteSpace();
            var v = StringToDoubleConverter.ToDouble(_bytes, _offset, out var readCount);

            if (readCount == 0)
            {
                throw CreateParsingException("Number Token");
            }

            _offset += readCount;
            return(v);
        }
Exemplo n.º 10
0
        public System.Double ReadDouble()
        {
            SkipWhiteSpace();
            int readCount;
            var v = StringToDoubleConverter.ToDouble(bytes, offset, out readCount);

            if (readCount == 0)
            {
                throw CreateParsingException("Number Token");
            }
            offset += readCount;
            return(v);
        }
Exemplo n.º 11
0
        public void When_TwoWay_And_ConvertBack_Normal_xBind()
        {
            var dp1 = new MyDP();
            var dp2 = new MyDP();

            var conv    = new StringToDoubleConverter();
            var binding = new Binding
            {
                Path           = new PropertyPath(nameof(MyDP.MyDouble)),
                Mode           = BindingMode.TwoWay,
                Converter      = conv,
                CompiledSource = dp1,
            };

            BindingOperations.SetBinding(dp2, MyDP.MyStringProperty, binding);

            dp2.ApplyXBind();

            Assert.AreEqual("¤0.00", dp2.MyString);
            Assert.AreEqual(1, conv.ConvertCount);
            Assert.AreEqual(0, conv.ConvertBackCount);

            dp2.MyString = "42";

            // For x:Bind, the source update through the converter raises
            // a property change, which is in turn sent back to the target
            // after another Convert invocation.
            //
            // There is no loop happening because the binding engine is ignoring
            // the UpdateSource invocation as a two-way binding is still happening.
            //
            // This behavior is different with a normal binding.
            Assert.AreEqual("¤42.00", dp2.MyString);
            Assert.AreEqual(42, dp1.MyDouble);
            Assert.AreEqual(2, conv.ConvertCount);
            Assert.AreEqual(1, conv.ConvertBackCount);
        }
 public static double ReadDouble(byte[] bytes, int offset, out int readCount)
 {
     return(StringToDoubleConverter.ToDouble(bytes, offset, out readCount));
 }
        public void InValidConverterValuesThrowArgumenException(object value)
        {
            var stringToDoubleConverter = new StringToDoubleConverter();

            Assert.Throws <ArgumentException>(() => stringToDoubleConverter.Convert(value, typeof(StringToIntConverter_tests), null, CultureInfo.CurrentCulture));
        }
Exemplo n.º 14
0
        public static double GetDoubleValue(this DoubleUpDown comboBox)
        {
            var converter = new StringToDoubleConverter();

            return((double)converter.ConvertBack(comboBox.Text, typeof(double), null, CultureInfo.InvariantCulture));
        }
Exemplo n.º 15
0
 public static float ReadSingle(byte[] bytes, int offset, out int readCount) => StringToDoubleConverter.ToSingle(bytes, offset, out readCount);