public void ConvertToCsvItemTest() { var c = new BoolConverter(); Assert.AreEqual("True", c.ConvertToCsvItem(CreateConvertToCsvItemContext(true))); Assert.AreEqual("False", c.ConvertToCsvItem(CreateConvertToCsvItemContext(false))); }
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 static void Main() { BoolConverter instance = new BoolConverter(); instance.ConvertBoolToString(true); instance.ConvertBoolToString(false); }
public void ReadsCorrectly() { // arrange var converter = new BoolConverter(); var reader1 = new Moq.Mock <JsonReader>(); reader1.SetupGet(x => x.Value).Returns(null); var reader2 = new Moq.Mock <JsonReader>(); reader2.SetupGet(x => x.Value).Returns("0"); var reader3 = new Moq.Mock <JsonReader>(); reader3.SetupGet(x => x.Value).Returns("1"); // act var object1 = converter.ReadJson(reader1.Object, typeof(bool), null, null); var object2 = converter.ReadJson(reader1.Object, typeof(bool?), null, null); var object3 = converter.ReadJson(reader2.Object, typeof(bool), null, null); var object4 = converter.ReadJson(reader3.Object, typeof(bool), null, null); // assert Assert.IsAssignableFrom <bool>(object1); Assert.IsFalse((bool)object1); Assert.IsNull(object2); Assert.IsFalse((bool)object3); Assert.IsTrue((bool)object4); }
static Converter() { BoolConverter.Initialize(); CharConverter.Initialize(); ByteConverter.Initialize(); SByteConverter.Initialize(); Int16Converter.Initialize(); UInt16Converter.Initialize(); Int32Converter.Initialize(); UInt32Converter.Initialize(); Int64Converter.Initialize(); UInt64Converter.Initialize(); SingleConverter.Initialize(); DoubleConverter.Initialize(); DecimalConverter.Initialize(); BigIntegerConverter.Initialize(); BytesConverter.Initialize(); CharsConverter.Initialize(); StringConverter.Initialize(); StringBuilderConverter.Initialize(); DateTimeConverter.Initialize(); TimeSpanConverter.Initialize(); GuidConverter.Initialize(); MemoryStreamConverter.Initialize(); StreamConverter.Initialize(); }
public void False() { var converter = new BoolConverter(); var result = converter.Convert(false); Assert.AreEqual(false, result); }
public void IndefiniteString() { var converter = new BoolConverter(); var result = converter.Convert(" 01"); Assert.AreEqual(null, 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 TrueSByte() { var converter = new BoolConverter(); var result = converter.Convert((sbyte)1); Assert.AreEqual(true, result); }
public void Convert_ReturnFalse_WhenFalse() { var py = Python.Instance(); var pyBool = py.Eval("False"); var converter = new BoolConverter(); Assert.AreEqual(false, converter.Convert(pyBool)); }
public void CanConvert_Should_RecognizeBooleanType(Type testType, bool expectedResult) { var boolConverter = new BoolConverter(); var result = boolConverter.CanConvert(testType); result.ShouldEqual(expectedResult); }
public void TrueUShort() { var converter = new BoolConverter(); var result = converter.Convert((ushort)1); Assert.AreEqual(true, result); }
public void TrueULong() { var converter = new BoolConverter(); var result = converter.Convert(1ul); Assert.AreEqual(true, result); }
public void TrueString() { var converter = new BoolConverter(); var result = converter.Convert(" 1"); Assert.AreEqual(true, result); }
private bool?ConvertToObjectItem(string csvItem) { var c = new BoolConverter(); Assert.IsTrue(c.TryConvertToObjectItem(CreateConvertToObjectItemContext(csvItem), out object?result, out string _)); return((bool?)result); }
/// <summary> /// Converts and sets a value on the target object for the property /// this converter is associated with /// </summary> /// <param name="target">Target object</param> /// <param name="value">Value to set as a string which will be converted</param> public override void SetValue(object target, string value) { if (string.IsNullOrWhiteSpace(value)) { return; } this.Setter((T)target, BoolConverter <bool> .ParseBool(value)); }
public static int NullableBoolToURI(char[] buf, int pos, bool?value) { if (value == null) { return(pos); } return(BoolConverter.SerializeURI(value.Value, buf, pos)); }
public void TryConvertToObjectItemFailureTest() { var c = new BoolConverter(); var context = CreateConvertToObjectItemContext("x"); Assert.IsFalse(c.TryConvertToObjectItem(context, out object?_, out string message)); Assert.AreEqual(CsvConfig.Current.ValidationMessage.GetBooleanConvertError(context), message); }
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 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); }
public void CanSerializeAndDeserialize() { bool value = false; BoolConverter converter = new BoolConverter(); byte[] bytes = converter.Serialize(value); bool valueFromBytes = converter.Deserialize(bytes); Assert.Equal(value, valueFromBytes); }
public static async Task <bool> WaitForBoolReplyAsync(this InteractivityExtension interactivity, DiscordChannel channel, DiscordUser user) { var conv = new BoolConverter(); bool response = false; InteractivityResult <DiscordMessage> mctx = await interactivity.WaitForMessageAsync( m => m.Channel == channel && m.Author == user && conv.TryConvert(m.Content, out response) ); return(!mctx.TimedOut && response); }
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); }
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_ConvertBack() { IValueConverter converter; object actualValue; Type expectedType; converter = new BoolConverter(); expectedType = typeof(bool); // // Test with null. // try { converter.ConvertBack(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (NotSupportedException) { } // // Test with incorrect value. // try { converter.ConvertBack("true"); Assert.Fail("Expected ArgumentException to be thrown."); } catch (NotSupportedException) { } // // Test with true. // actualValue = converter.ConvertBack("yes"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(true, actualValue, "Converted value is incorrect."); // // Test with false. // actualValue = converter.ConvertBack("no"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(false, actualValue, "Converted value is incorrect."); }
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); }
public void BoolConverterTest() { var c1 = new BoolConverter <bool>(); c1.Set(true).Should().Be(true); c1.Set(false).Should().Be(false); c1.Get(null).Should().BeFalse(); c1.Get(false).Should().BeFalse(); c1.Get(true).Should().BeTrue(); var c2 = new BoolConverter <bool?>(); c2.Set(true).Should().Be(true); c2.Set(false).Should().Be(false); c2.Set(null).Should().BeNull(); c2.Get(null).Should().BeNull(); c2.Get(false).Should().BeFalse(); c2.Get(true).Should().BeTrue(); var c3 = new BoolConverter <string>(); c3.Set("true").Should().Be(true); c3.Set("false").Should().Be(false); c3.Set("on").Should().Be(true); c3.Set("off").Should().Be(false); c3.Set(null).Should().BeNull(); c3.Get(null).Should().BeNull(); c3.Get(false).Should().Be("off"); c3.Get(true).Should().Be("on"); var c4 = new BoolConverter <int>(); c4.Set(1).Should().Be(true); c4.Set(0).Should().Be(false); c4.Get(null).Should().Be(0); c4.Get(false).Should().Be(0); c4.Get(true).Should().Be(1); var c5 = new BoolConverter <int?>(); c5.Set(17).Should().Be(true); c5.Set(-1).Should().Be(false); c5.Set(null).Should().BeNull(); c5.Get(null).Should().BeNull(); c5.Get(false).Should().Be(0); c5.Get(true).Should().Be(1); // non-convertable types will be handled without exceptions var c6 = new BoolConverter <DateTime>(); c6.Set(DateTime.Now).Should().Be(null); c6.Get(true).Should().Be(default(DateTime)); c6.Get(false).Should().Be(default(DateTime)); c6.Get(null).Should().Be(default(DateTime)); }
public void CanConvert() { // arrange var converter = new BoolConverter(); // act var result1 = converter.CanConvert(false.GetType()); var result2 = converter.CanConvert(typeof(bool?)); var result3 = converter.CanConvert("".GetType()); // assert Assert.IsTrue(result1); Assert.IsTrue(result2); Assert.IsFalse(result3); }
public bool onIsVibrate => isVibrate; //return to other class void Start() { boolConverter = GetComponent <BoolConverter>(); int tempIsMute = PlayerPrefs.GetInt(SOUND_SETTING, 0); int tempIsVibrate = PlayerPrefs.GetInt(VIBRATE_SETTING, 1); //convert 1 kpd true and vice versa isMute = boolConverter.intToBool(tempIsMute); isVibrate = boolConverter.intToBool(tempIsVibrate); SetInitialSettings(isMute, isVibrate); /* //debug * Debug.Log("isMute is " + isMute + ", isVibrate is " + isVibrate); * Debug.Log("onIsSound is " + onIsSound + ", oIsVibrate is " + onIsVibrate); */ }
public void BoolConverterTests() { var converter = new BoolConverter(); this.AssertConvertSuccess(converter, "t", true); this.AssertConvertSuccess(converter, "y", true); this.AssertConvertSuccess(converter, "Y", true); this.AssertConvertSuccess(converter, "yy", true); this.AssertConvertSuccess(converter, "yY", true); this.AssertConvertSuccess(converter, "Ye", true); this.AssertConvertSuccess(converter, "yA", true); this.AssertConvertSuccess(converter, "yEs", true); this.AssertConvertSuccess(converter, "yea", true); this.AssertConvertSuccess(converter, "yup", true); this.AssertConvertSuccess(converter, "yEe", true); this.AssertConvertSuccess(converter, "yeah", true); this.AssertConvertSuccess(converter, "true", true); this.AssertConvertSuccess(converter, "True", true); this.AssertConvertSuccess(converter, "On", true); this.AssertConvertSuccess(converter, "enable", true); this.AssertConvertSuccess(converter, "1", true); this.AssertConvertFail <BoolConverter, bool>(converter, "yq"); this.AssertConvertFail <BoolConverter, bool>(converter, "ohy"); this.AssertConvertFail <BoolConverter, bool>(converter, "4"); this.AssertConvertFail <BoolConverter, bool>(converter, "+"); this.AssertConvertSuccess(converter, "f", false); this.AssertConvertSuccess(converter, "n", false); this.AssertConvertSuccess(converter, "no", false); this.AssertConvertSuccess(converter, "nn", false); this.AssertConvertSuccess(converter, "nAh", false); this.AssertConvertSuccess(converter, "nope", false); this.AssertConvertSuccess(converter, "false", false); this.AssertConvertSuccess(converter, "False", false); this.AssertConvertSuccess(converter, "of", false); this.AssertConvertSuccess(converter, "off", false); this.AssertConvertSuccess(converter, "diSable", false); this.AssertConvertSuccess(converter, "0", false); this.AssertConvertFail <BoolConverter, bool>(converter, "nwh"); this.AssertConvertFail <BoolConverter, bool>(converter, "ohn"); this.AssertConvertFail <BoolConverter, bool>(converter, "-10"); this.AssertConvertFail <BoolConverter, bool>(converter, "-"); this.AssertConvertFail <BoolConverter, bool>(converter, "yesno"); }
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) { } }
public void ReadJson_Should_ReadBooleanValue(string testValue, bool expectedResult) { var boolConverter = new BoolConverter(); var jsonReaderMock = MockRepository.Create <JsonReader>(); jsonReaderMock.Setup(x => x.Value).Returns(testValue); var result = boolConverter.ReadJson( jsonReaderMock.Object, typeof(bool), null, null); jsonReaderMock.VerifyGet(x => x.Value, Times.Once); result.ShouldBeType <bool>(); result.ShouldEqual(expectedResult); }
/// <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); } }
public void WriteJson_Should_WriteBooleanValue(bool testValue) { int?writtenResult = null; var jsonWriterMock = MockRepository.Create <JsonWriter>(); jsonWriterMock .Setup(x => x .WriteValue(It.IsAny <int>())) .Callback <int>((val) => writtenResult = val); var boolConverter = new BoolConverter(); boolConverter.WriteJson(jsonWriterMock.Object, testValue, null); jsonWriterMock.Verify(x => x.WriteValue(It.IsAny <int>()), Times.Once); writtenResult.ShouldEqual(testValue ? 1 : 0); }
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); }
public static void Main() { BoolConverter boolConverter = new BoolConverter(); boolConverter.PrintBoolToString(true); }
public void ToObjectTest() { BoolConverter target = new BoolConverter(); Assert.AreEqual<bool>(false, target.ToObject("0000")); Assert.AreEqual<bool>(true, target.ToObject("0001")); }
public void ToObjectThrowsFormatExceptionTest() { BoolConverter target = new BoolConverter(); target.ToObject("0002"); }
private static string DemounterStatusStream3() { BoolConverter boolConverter = new BoolConverter(); IntHexConverter intConverter = new IntHexConverter(); string stream = "00FF" // station ID + pc ID + boolConverter.ToStream(false) // carrier plate arrival flag + boolConverter.ToStream(true) // IS error flag + boolConverter.ToStream(true) // carrier plate barcode read OK flag + boolConverter.ToStream(false) // carrier plate demount start flag + intConverter.ToStream(6) // carrier plate wafer size + intConverter.ToStream(7) // carrier plate wafer count + "0003" // demount cassette station + intConverter.ToStream(1) // wafer demount counter + boolConverter.ToStream(true) // CP demount complete + "0001" // empty CP routing + "000000000000000000000000" // ... some data ... + "0002" // remove cassette from demount station + intConverter.ToStream(6) // cassette wafer size + "0001" // destination station number of cassette + "0002" // cassette barcode read start flag + boolConverter.ToStream(true) // cassette barcode read OK flag + "00000000000000000000000000000000000000000000" // ... some data ... + boolConverter.ToStream(false) // spatula check flag + boolConverter.ToStream(true) // station 1 cassette sensor + boolConverter.ToStream(false) // station 2 cassette sensor + boolConverter.ToStream(true) // station 3 cassette sensor + boolConverter.ToStream(true) // station 4 cassette sensor + "0003" // demounter machine state + "\u0003" // ETX ; return stream; }
private static string StockerStatusStream3() { BoolConverter boolConverter = new BoolConverter(); IntHexConverter intConverter = new IntHexConverter(); string stream = "00FF" // station ID + pc ID + boolConverter.ToStream(true) // carrier plate arrival flag + boolConverter.ToStream(true) // IS Error Flag + "0001" // CP Routing + boolConverter.ToStream(false) // magazine full flag + boolConverter.ToStream(true) // operator magazine change request flag + boolConverter.ToStream(true) // IS magazine change flag + boolConverter.ToStream(true) // magazine change start flag + boolConverter.ToStream(true) // input magazine barcode OK Flag + "00000000000000000000000000000000" // ... some data ... + intConverter.ToStream(6) // wafer size requested + boolConverter.ToStream(false) // magazine request flag + "0002" // stocker inventory + boolConverter.ToStream(false) // output magazine arrive flag + "0002" // magazine selection + intConverter.ToStream(3) // polishline number + "\u0003" // ETX ; return stream; }
public static void Main() { BoolConverter instance = new BoolConverter(); instance.ConvertBoolToString(true); instance.ConvertBoolToString(false); }
public void ToStreamTest() { BoolConverter target = new BoolConverter(); Assert.AreEqual<string>("0000", target.ToStream(false)); Assert.AreEqual<string>("0001", target.ToStream(true)); }