Beispiel #1
0
        public void BoolConverter()
        {
            var boolConverter = new BoolConverter();
            var trueResult    = boolConverter.Convert(true, typeof(string), null, CultureInfo.InvariantCulture);
            var falseResult   = boolConverter.Convert(false, typeof(string), null, CultureInfo.InvariantCulture);

            Assert.Equal("Yes", trueResult);
            Assert.Equal("No", falseResult);
        }
Beispiel #2
0
        public void BoolConverter_Convert()
        {
            IValueConverter converter;
            object          actualValue;
            Type            expectedType;

            converter    = new BoolConverter();
            expectedType = typeof(string);

            //
            // Test with null.
            //

            try
            {
                converter.Convert(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect type.
            //

            try
            {
                converter.Convert("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with true.
            //

            actualValue = converter.Convert(true);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("yes", actualValue, "Converted value is incorrect.");

            //
            // Test with false.
            //

            actualValue = converter.Convert(false);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("no", actualValue, "Converted value is incorrect.");
        }
        public void BoolConverter_Convert()
        {
            IValueConverter converter;
            object actualValue;
            Type expectedType;

            converter = new BoolConverter();
            expectedType = typeof(string);

            //
            // Test with null.
            //

            try
            {
                converter.Convert(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect type.
            //

            try
            {
                converter.Convert("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with true.
            //

            actualValue = converter.Convert(true);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("yes", actualValue, "Converted value is incorrect.");

            //
            // Test with false.
            //

            actualValue = converter.Convert(false);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("no", actualValue, "Converted value is incorrect.");
        }
Beispiel #4
0
        public void False()
        {
            var converter = new BoolConverter();
            var result    = converter.Convert(false);

            Assert.AreEqual(false, result);
        }
Beispiel #5
0
        public void TrueSByte()
        {
            var converter = new BoolConverter();
            var result    = converter.Convert((sbyte)1);

            Assert.AreEqual(true, result);
        }
Beispiel #6
0
        public void TrueUShort()
        {
            var converter = new BoolConverter();
            var result    = converter.Convert((ushort)1);

            Assert.AreEqual(true, result);
        }
Beispiel #7
0
        public void TrueULong()
        {
            var converter = new BoolConverter();
            var result    = converter.Convert(1ul);

            Assert.AreEqual(true, result);
        }
 public void Convert_ThrowsException_WhenNotBool()
 {
     var py = Python.Instance();
     var pyStr = py.Eval("\"omershelef\"");
     var converter = new BoolConverter();
     Assert.Throws<ConversionException>(() => converter.Convert(pyStr));
 }
 public void Convert_ReturnTrue_WhenTrue()
 {
     var py = Python.Instance();
     var pyBool = py.Eval("True");
     var converter = new BoolConverter();
     Assert.AreEqual(true, converter.Convert(pyBool));
 }
 public void Convert_ReturnFalse_WhenFalse()
 {
     var py = Python.Instance();
     var pyBool = py.Eval("False");
     var converter = new BoolConverter();
     Assert.AreEqual(false, converter.Convert(pyBool));
 }
Beispiel #11
0
        public void TrueString()
        {
            var converter = new BoolConverter();
            var result    = converter.Convert("  1");

            Assert.AreEqual(true, result);
        }
Beispiel #12
0
        public void IndefiniteString()
        {
            var converter = new BoolConverter();
            var result    = converter.Convert("  01");

            Assert.AreEqual(null, result);
        }
Beispiel #13
0
 public void BoolConverterTest()
 {
     Assert.That(BoolConverter.Convert("Y"), Is.EqualTo(true));
     Assert.That(BoolConverter.Convert("N"), Is.EqualTo(false));
     Assert.That(BoolConverter.Convert(true), Is.EqualTo("Y"));
     Assert.That(BoolConverter.Convert(false), Is.EqualTo("N"));
     Assert.Throws(typeof(FieldConvertError),
                   delegate { BoolConverter.Convert("Z"); });
 }
        public void Should_convert_to_true()
        {
            var registry = new LocalizationRegistry(new Cache());

            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Achievements, "en-ach");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Achievements, "fr-ach");
            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Yes, "yes");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Yes, "fr-yes");
            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.True, "true");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.True, "fr-true");
            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.No, "no");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.No, "fr-no");
            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.False, "false");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.False, "fr-false");

            var converter = new BoolConverter(registry);

            converter.Convert("en", "yes").Result.Should().BeTrue();
            converter.Convert("en", "fr-yes").Result.Should().BeTrue();
        }
Beispiel #15
0
        public static bool HasFlag(this XmlElement xml, string attribute)
        {
            if (!xml.HasAttribute(attribute))
            {
                return(false);
            }

            var has = false;

            return(BoolConverter.Convert(xml.Attributes[attribute], ref has) && has);
        }
Beispiel #16
0
        public void ConvertBoolean()
        {
            BoolConverter e = new BoolConverter();

            // COnvert the boolean
            bool convertedBool = (bool)e.Convert(trueValue, typeof(bool?), null, CultureInfo.InvariantCulture);

            // Assert type
            Assert.IsInstanceOfType(convertedBool, typeof(bool));

            // Assert value has been converted
            Assert.IsFalse(convertedBool);
        }
Beispiel #17
0
 public void ToApp(Message message, SessionID sessionId)
 {
     try
     {
         bool possDupFlag = false;
         if (message.Header.IsSetField(Tags.PossDupFlag))
         {
             possDupFlag = BoolConverter.Convert(
                 message.Header.GetString(Tags.PossDupFlag));
         }
         if (possDupFlag)
         {
             throw new DoNotSend();
         }
     }
     catch (FieldNotFoundException)
     { }
 }
Beispiel #18
0
 /// <summary>
 /// Gets the boolean value of a field
 /// </summary>
 /// <param name="tag">the FIX tag</param>
 /// <returns>the bool value</returns>
 /// <exception cref="FieldNotFoundException" />
 public bool GetBoolean(int tag)
 {
     try
     {
         Fields.IField fld = _fields[tag];
         if (fld.GetType() == typeof(BooleanField))
         {
             return(((BooleanField)fld).Obj);
         }
         else
         {
             return(BoolConverter.Convert(fld.ToString()));
         }
     }
     catch (System.Collections.Generic.KeyNotFoundException)
     {
         throw new FieldNotFoundException(tag);
     }
 }
        private void Convert_InputIsTrue_ReturnValueOfTrueValueProperty(
            object trueValue,
            object falseValue,
            object nullValue)
        {
            var sut = new BoolConverter()
            {
                TrueValue  = trueValue,
                FalseValue = falseValue,
                NullValue  = nullValue
            };

            const object nonBoolConverterParameter = null;
            CultureInfo  anyCulture = CultureInfo.CurrentCulture;

            var actualResult = sut.Convert(true, typeof(Visibility), nonBoolConverterParameter, anyCulture);

            Assert.AreEqual(sut.TrueValue, actualResult);
        }