public static void TestInstanceConstructorsAndMethods() { // Check parameterless constructor var a = new ClassA(); // TEST Assert.AreEqual(10, a.NumberA, "NumberA 10"); Assert.AreEqual("Str", a.StringA, "StringA Str"); Assert.AreEqual(true, a.BoolA, "BoolA true"); Assert.True(a.DoubleA == Double.PositiveInfinity, "DoubleA Double.PositiveInfinity"); Assert.AreDeepEqual(-1m, a.DecimalA, "DecimalA Decimal.MinusOne"); Assert.True(a.Data != null, "Data not null"); Assert.AreEqual(700, a.Data.Number, "Data.Number 700"); // TEST // Check constructor with parameter Assert.Throws <Exception>(TestSet1FailureHelper.TestConstructor1Failure, "Related should not be null"); // TEST // Check constructor with parameter Assert.Throws <Exception>(TestSet1FailureHelper.TestConstructor2Failure, "Should pass six parameters"); a = new ClassA(150, "151", true, 1.53d, 1.54m, new ClassA.Aux1() { Number = 155 }); Assert.AreEqual(150, a.NumberA, "NumberA 150"); Assert.AreEqual("151", a.StringA, "StringA 151"); Assert.AreEqual(true, a.BoolA, "BoolA true"); Assert.AreEqual(1.53, a.DoubleA, "DoubleA Double.PositiveInfinity"); Assert.AreDeepEqual(1.54m, a.DecimalA, "DecimalA 154"); Assert.True(a.Data != null, "Data not null"); Assert.AreEqual(155, a.Data.Number, "Data.Number 155"); // TEST // Check instance methods var b = a.Method1(); Assert.True(b != null, "b not null"); Assert.AreEqual(2, b.Number, "b Number 2"); Assert.True(b.Related != null, "b.Related not null"); Assert.AreEqual(1, b.Related.Number, "b.Related Number 1"); a.Data = b; Assert.AreEqual("2 Has related 1", a.Method3(), "Method3 2 Has related 1"); a.Data = null; Assert.AreEqual("no data", a.Method3(), "Method3 no data"); // TEST // Check [#68] var c68 = new Class68(); Assert.AreEqual(0, c68.x, "c68.x 0"); Assert.AreEqual(1, c68.y, "c68.y 1"); // TEST // Check local vars do not get overridden by fields c68.Test(); Assert.AreEqual(0, c68.x, "c68.x 0"); Assert.AreEqual(1, c68.y, "c68.y 1"); }
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"); }