public void WhenNoConfigurationIsDoneThenRegularBoolConversionIsUsed()
        {
            var ba          = new DataColumnBooleanAttribute();
            var falseObject = ba.ConvertStringToType("False", typeof(bool), Thread.CurrentThread.CurrentCulture);

            Assert.IsFalse((bool)falseObject);

            var trueObject = ba.ConvertStringToType("True", typeof(bool), Thread.CurrentThread.CurrentCulture);

            Assert.IsTrue((bool)trueObject);
        }
 public void WhenConvertingNonBooleanValueThenExceptionIsThrown()
 {
     try
     {
         var ba = new DataColumnBooleanAttribute();
         ba.ConvertStringToType("dummy", typeof(int), Thread.CurrentThread.CurrentCulture);
     }
     catch (InvalidCastException e)
     {
         Assert.AreEqual("DataColumnBooleanAttribute can only be used on attributes of type System.Boolean.", e.Message);
         throw;
     }
 }
        public void TestConversionWhenOnlyTrueStringsAreConfigured()
        {
            var ba = new DataColumnBooleanAttribute();

            ba.TrueStrings = new string[] { "yes", "yupp", "y" };
            var o = ba.ConvertStringToType("nonsense", typeof(bool), Thread.CurrentThread.CurrentCulture);

            Assert.IsFalse((bool)o);
            o = ba.ConvertStringToType("yes", typeof(bool), Thread.CurrentThread.CurrentCulture);
            Assert.IsTrue((bool)o);
            o = ba.ConvertStringToType("yUpp", typeof(bool), Thread.CurrentThread.CurrentCulture);
            Assert.IsTrue((bool)o);
            o = ba.ConvertStringToType("Y", typeof(bool), Thread.CurrentThread.CurrentCulture);
            Assert.IsTrue((bool)o);
        }
 public void GivenBothFalseAndTrueStringConfiguredWhenConvertingAndNoMatchThenExceptionIsThrown()
 {
     try
     {
         var ba = new DataColumnBooleanAttribute();
         ba.TrueStrings  = new string[] { "yes" };
         ba.FalseStrings = new string[] { "no" };
         ba.ConvertStringToType("nonsense", typeof(bool), Thread.CurrentThread.CurrentCulture);
     }
     catch (InvalidCastException e)
     {
         Assert.AreEqual("No matching conversion was found for value nonsense.", e.Message);
         throw;
     }
 }
 public void GivenEqualFalseAndTrueStringConfigurationWhenConvertingThenExceptionIsThrown()
 {
     try
     {
         var ba = new DataColumnBooleanAttribute();
         ba.TrueStrings  = new string[] { "hey" };
         ba.FalseStrings = new string[] { "hey" };
         ba.ConvertStringToType("hey", typeof(bool), Thread.CurrentThread.CurrentCulture);
     }
     catch (InvalidCastException e)
     {
         Assert.AreEqual("Ambiguous configuration: Both true and false string contains the value hey.", e.Message);
         throw;
     }
 }
        public void WhenNoConfigurationIsDoneAndInvalidStringIsConvertedThenExceptionIsThrown()
        {
            var ba = new DataColumnBooleanAttribute();

            ba.ConvertStringToType("nonsense", typeof(bool), Thread.CurrentThread.CurrentCulture);
        }