Exemplo n.º 1
0
        public static void TestMethodParameters()
        {
            // Check default parameters
            var ra = new ClassA();
            int r = ra.Method5(5);

            Assert.AreEqual(r, 5, "r 5");
            r = ra.Method5(i: 15);
            Assert.AreEqual(r, 15, "r 15");
            r = ra.Method5(5, 6);
            Assert.AreEqual(r, 11, "r 11");
            r = ra.Method5(k: 6);
            Assert.AreEqual(r, -44, "r -44");

            // Check referencing did not change data
            var a = new ClassA();
            var b = a.Method1();
            var c = b.Related;

            a.Method2(b);
            Assert.True(b != null, "b not null");
            Assert.AreEqual(b.Number, 2, "b Number 2");
            Assert.True(b.Related != null, "b.Related not null");
            Assert.AreEqual(b.Related.Number, 2, "b.Related Number 2");

            Assert.True(c != null, "c not null");
            Assert.AreEqual(c.Number, 1, "c Number 1");
            Assert.True(c.Related == null, "c.Related null");

            // Check value local parameter
            var input = 1;
            var result = a.Method4(input, 4);

            Assert.AreEqual(input, 1, "input 1");
            Assert.AreEqual(result, 5, "result 5");

            // TEST
            // [#86]
            var di = ClassA.GetDefaultInt();
            Assert.AreEqual(di, 0, "di 0");

            // TEST
            // Check  "out parameter"
            // [#85]
            int i;
            var tryResult = ClassA.TryParse("", out i);

            Assert.True(tryResult, "tryResult");
            Assert.AreEqual(i, 3, "i 3");
        }
Exemplo n.º 2
0
 public static void TestConstructor2Failure()
 {
     var t = new ClassA(new object[2]);
 }
Exemplo n.º 3
0
        public static void TestInstanceConstructorsAndMethods()
        {
            // Check parameterless constructor
            var a = new ClassA();

            // TEST
            Assert.AreEqual(a.NumberA, 10, "NumberA 10");
            Assert.AreEqual(a.StringA, "Str", "StringA Str");
            Assert.AreEqual(a.BoolA, true, "BoolA true");
            Assert.True(a.DoubleA == Double.PositiveInfinity, "DoubleA Double.PositiveInfinity");
            Assert.AreDeepEqual(a.DecimalA, -1m, "DecimalA Decimal.MinusOne");
            Assert.True(a.Data != null, "Data not null");
            Assert.AreEqual(a.Data.Number, 700, "Data.Number 700");

            // TEST
            // Check constructor with parameter
            Assert.Throws(TestSet1FailureHelper.TestConstructor1Failure, "Related should not be null", "Related should not be null");

            // TEST
            // Check constructor with parameter
            Assert.Throws(TestSet1FailureHelper.TestConstructor2Failure, "Should pass six parameters", "Should pass six parameters");

            a = new ClassA(150, "151", true, 1.53d, 1.54m, new ClassA.Aux1()
            {
                Number = 155
            });

            Assert.AreEqual(a.NumberA, 150, "NumberA 150");
            Assert.AreEqual(a.StringA, "151", "StringA 151");
            Assert.AreEqual(a.BoolA, true, "BoolA true");
            Assert.AreEqual(a.DoubleA, 1.53, "DoubleA Double.PositiveInfinity");
            Assert.AreDeepEqual(a.DecimalA, 1.54m, "DecimalA 154");
            Assert.True(a.Data != null, "Data not null");
            Assert.AreEqual(a.Data.Number, 155, "Data.Number 155");

            // TEST
            // Check instance methods
            var b = a.Method1();

            Assert.True(b != null, "b not null");
            Assert.AreEqual(b.Number, 2, "b Number 2");
            Assert.True(b.Related != null, "b.Related not null");
            Assert.AreEqual(b.Related.Number, 1, "b.Related Number 1");

            a.Data = b;
            Assert.AreEqual(a.Method3(), "2 Has related 1", "Method3 2 Has related 1");
            a.Data = null;
            Assert.AreEqual(a.Method3(), "no data", "Method3 no data");

            // TEST
            // Check [#68]
            var c68 = new Class68();

            Assert.AreEqual(c68.x, 0, "c68.x 0");
            Assert.AreEqual(c68.y, 1, "c68.y 1");

            // TEST
            // Check local vars do not get overridden by fields
            c68.Test();

            Assert.AreEqual(c68.x, 0, "c68.x 0");
            Assert.AreEqual(c68.y, 1, "c68.y 1");
        }
Exemplo n.º 4
0
 public void Method2(ClassA.Aux1 a)
 {
     a.Related = a;
 }
Exemplo n.º 5
0
 public static void StaticMethod2Failure()
 {
     ClassA.StaticMethod2("1", "some string", "345.345435");
 }
Exemplo n.º 6
0
 public static void TestConstructor2Failure()
 {
     var t = new ClassA(new object[2]);
 }
Exemplo n.º 7
0
        public static void TestInstanceConstructorsAndMethods()
        {
            // Check parameterless constructor
            var a = new ClassA();

            // TEST
            Assert.AreEqual(a.NumberA, 10, "NumberA 10");
            Assert.AreEqual(a.StringA, "Str", "StringA Str");
            Assert.AreEqual(a.BoolA, true, "BoolA true");
            Assert.True(a.DoubleA == Double.PositiveInfinity, "DoubleA Double.PositiveInfinity");
            Assert.AreDeepEqual(a.DecimalA, -1m, "DecimalA Decimal.MinusOne");
            Assert.True(a.Data != null, "Data not null");
            Assert.AreEqual(a.Data.Number, 700, "Data.Number 700");

            // TEST
            // Check constructor with parameter
            Assert.Throws(TestSet1FailureHelper.TestConstructor1Failure, "Related should not be null", "Related should not be null");

            // TEST
            // Check constructor with parameter
            Assert.Throws(TestSet1FailureHelper.TestConstructor2Failure, "Should pass six parameters", "Should pass six parameters");

            a = new ClassA(150, "151", true, 1.53d, 1.54m, new ClassA.Aux1()
            {
                Number = 155
            });

            Assert.AreEqual(a.NumberA, 150, "NumberA 150");
            Assert.AreEqual(a.StringA, "151", "StringA 151");
            Assert.AreEqual(a.BoolA, true, "BoolA true");
            Assert.AreEqual(a.DoubleA, 1.53, "DoubleA Double.PositiveInfinity");
            Assert.AreDeepEqual(a.DecimalA, 1.54m, "DecimalA 154");
            Assert.True(a.Data != null, "Data not null");
            Assert.AreEqual(a.Data.Number, 155, "Data.Number 155");

            // TEST
            // Check instance methods
            var b = a.Method1();

            Assert.True(b != null, "b not null");
            Assert.AreEqual(b.Number, 2, "b Number 2");
            Assert.True(b.Related != null, "b.Related not null");
            Assert.AreEqual(b.Related.Number, 1, "b.Related Number 1");

            a.Data = b;
            Assert.AreEqual(a.Method3(), "2 Has related 1", "Method3 2 Has related 1");
            a.Data = null;
            Assert.AreEqual(a.Method3(), "no data", "Method3 no data");

            // TEST
            // Check [#68]
            var c68 = new Class68();

            Assert.AreEqual(c68.x, 0, "c68.x 0");
            Assert.AreEqual(c68.y, 1, "c68.y 1");

            // TEST
            // Check local vars do not get overridden by fields
            c68.Test();

            Assert.AreEqual(c68.x, 0, "c68.x 0");
            Assert.AreEqual(c68.y, 1, "c68.y 1");
        }