public void ConvertsEmptyStringToZeroWhenAllowed () 
 {
     CustomNumberConverter verter
         = new CustomNumberConverter (typeof (int), null, true);
     int actual = (int) verter.ConvertFrom (
         null, CultureInfo.CurrentUICulture, string.Empty);
     Assert.AreEqual (0, actual);
 }
 public void ConvertFromNonSupportedOptionBails()
 {
     CustomNumberConverter verter
         = new CustomNumberConverter(typeof(int), null, false);
     object foo = verter.ConvertFrom(12);
 }
 public void ConvertFromNonSupportedNumericTypeOptionBails()
 {
     CustomNumberConverter verter
         = new CustomNumberConverter(typeof(char), null, false);
     object foo = verter.ConvertFrom("12");
 }
 public void ConvertFromSupportedNumericType () 
 {
     Type [] numTypes = new Type [] {
         typeof (int),
         typeof (uint),
         typeof (short),
         typeof (ushort),
         typeof (long),
         typeof (ulong),
         typeof (float),
         typeof (double),
     };
     int expected = 12;
     foreach (Type numType in numTypes) 
     {
         try 
         {
             CustomNumberConverter verter
                 = new CustomNumberConverter (numType, null, true);
             object actual = verter.ConvertFrom (
                 null, CultureInfo.CurrentUICulture, expected.ToString ());
             Assert.AreEqual (expected, actual);
         } 
         catch (Exception ex) 
         {
             Assert.Fail ("Bailed when converting type '" + numType + "' : " + ex);
         }
     }
 }
 public void ConvertFromNonSupportedNumericTypeOptionBails () 
 {
     CustomNumberConverter verter
         = new CustomNumberConverter (typeof (char), null, false);
     object foo = verter.ConvertFrom ("12");
 }
 public void ConvertFromNonSupportedOptionBails () 
 {
     CustomNumberConverter verter
         = new CustomNumberConverter (typeof (int), null, false);
     object foo = verter.ConvertFrom (12);
 } 
 public void BailsOnEmptyStringWhenNotAllowed () 
 {
     CustomNumberConverter verter
         = new CustomNumberConverter (typeof (int), null, false);
     verter.ConvertFrom (null, CultureInfo.CurrentUICulture, string.Empty);
 }
Example #8
0
        public void ConvertFromNonSupportedOptionBails()
        {
            CustomNumberConverter verter = new CustomNumberConverter(typeof(int), null, false);

            Assert.Throws <NotSupportedException>(() => verter.ConvertFrom(12));
        }
 public void ConvertFromNonSupportedOptionBails()
 {
     CustomNumberConverter verter = new CustomNumberConverter(typeof(int), null, false);
     Assert.Throws<NotSupportedException>(() => verter.ConvertFrom(12));
 }
 public void ConvertFromNonSupportedNumericTypeOptionBails()
 {
     CustomNumberConverter verter
         = new CustomNumberConverter(typeof(char), null, false);
     Assert.Throws<NotSupportedException>(() => verter.ConvertFrom("12"));
 }
 public void BailsOnEmptyStringWhenNotAllowed()
 {
     CustomNumberConverter verter
         = new CustomNumberConverter(typeof(int), null, false);
     Assert.Throws<FormatException>(() => verter.ConvertFrom(null, CultureInfo.CurrentUICulture, string.Empty));
 }