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));
                }
            }
        }
Beispiel #2
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));
                }
            }
        }
        public static void Test()
        {
            string         name = "nameasd";
            Id <Parameter> id   = Id <Parameter> .Parse("C6AE15FF-0242-4289-AADD-F9F71F4CFEBB");

            ParameterType type = ParameterType.Parse("86EDCBA3-7807-4DD5-B0E8-0769C52BA0EB");

            DecimalParameter.Definition definition = new DecimalParameter.Definition(-100, 100);
            DecimalParameter            p          = new DecimalParameter(name, id, type, definition, "2");

            TestParameterIs(p, 2);

            //Test range checking
            Assert.That(() => p.SetValueAction(-100.1m), Throws.ArgumentException);
            TestParameterIs(p, 2);
            Assert.That(() => p.SetValueAction(100.1m), Throws.ArgumentException);
            TestParameterIs(p, 2);

            using (TemporaryCulture.European()) //To make sure we handle decimal separator properly
            {
                //Test undo/redo
                var actions = p.SetValueAction(12.4m);
                Assert.That(actions, Is.Not.Null);
                TestParameterIs(p, 2);
                actions.Value.Redo();
                TestParameterIs(p, 12.4m);
                actions.Value.Undo();
                TestParameterIs(p, 2);

                p.TryDeserialiseValue("shane");
                TestCorruptParameter(p, "shane");

                //Test what happens if we undo back to an invalid state
                var actions2 = p.SetValueAction(1.0m);
                actions2.Value.Redo();
                actions2.Value.Undo();
                TestCorruptParameter(p, "shane");

                p.TryDeserialiseValue("54.45");
                TestParameterIs(p, 54.45m);
            }
        }