コード例 #1
0
        private static void TestParameterIs(IntegerParameter p, int val)
        {
            Assert.That(p.Value, Is.EqualTo(val));
            int  result;
            bool isInt;

            Assert.That(p.Corrupted, Is.False);
            Assert.That(p.ValueAsString(), Is.EqualTo(val.ToString(CultureInfo.InvariantCulture))); //Tempting to simply verify it will parse as the correct value but we need to be consistent with existing files
            using (TemporaryCulture.English())
            {
                isInt = int.TryParse(p.DisplayValue((a, b) => ""), out result);
                Assert.That(isInt);
                if (isInt)
                {
                    Assert.That(result, Is.EqualTo(val));
                }
            }
            using (TemporaryCulture.European())
            {
                isInt = int.TryParse(p.DisplayValue((a, b) => ""), out result);
                Assert.That(isInt);
                if (isInt)
                {
                    Assert.That(result, Is.EqualTo(val));
                }
            }
        }
コード例 #2
0
        private static void TestParameterIs(BooleanParameter p, bool val, string valueAsString = null)
        {
            Assert.That(p.Value, Is.EqualTo(val));
            bool result;
            bool isBool;

            if (valueAsString == null)
            {
                Assert.That(p.Corrupted, Is.False);
                Assert.That(p.ValueAsString(), Is.EqualTo(val.ToString())); //Tempting to simply verify it will parse as the correct value but we need to be consistent with existing files
            }
            else
            {
                Assert.That(p.Corrupted, Is.True);
                Assert.That(p.ValueAsString(), Is.EqualTo(valueAsString));
            }
            using (TemporaryCulture.English())
            {
                isBool = bool.TryParse(p.DisplayValue((a, b) => ""), out result);
                Assert.That(isBool);
                if (isBool)
                {
                    Assert.That(result, Is.EqualTo(val));
                }
            }
            using (TemporaryCulture.European())
            {
                isBool = bool.TryParse(p.DisplayValue((a, b) => ""), out result);
                Assert.That(isBool);
                if (isBool)
                {
                    Assert.That(result, Is.EqualTo(val));
                }
            }
        }