Exemplo n.º 1
0
        public void TestTwoCalc()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<TwoCalc>();
            assert.Class();
            assert.Implements<ICalc>();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("a"),
                new Param<int>("b")
            );

            assert.Field<int>(
                "_a",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).Private().ReadOnly();

            assert.Field<int>(
                "_b",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).Private().ReadOnly();

            assert.Method<int>(
                "Calculate",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Virtual();

            assert.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();

            dynamic calc;
            calc = assert.New(1, 2);
            Assert.AreEqual(5, calc.Calculate());
            Assert.AreEqual("1, 2", calc.ToString());
            calc = assert.New(-10, 4);
            Assert.AreEqual(-2, calc.Calculate());
            Assert.AreEqual("-10, 4", calc.ToString());
#if !DEBUG
    });
#endif
        }
Exemplo n.º 2
0
        public void TestCondo()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Condo>();
            assert.Extends<Home>();
            assert.Implements<IRental>();
            assert.NonAbstract();

            assert.Property<string>(
               "Address",
               BindingFlags.Instance |
               BindingFlags.Public |
               BindingFlags.GetProperty
            ).DeclaredIn<Home>();

            assert.Property<int>(
                "YearBuilt",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).DeclaredIn<Home>();

            assert.Property<decimal>(
                "Price",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).DeclaredIn<Home>();

            assert.Property<decimal>(
                "Fee",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty);

            assert.Property<string>(
                "UnitNumber",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            );

            assert.Property<bool>(
                "IsRental",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            );

            assert.NonConstructor(
                BindingFlags.Public |
                BindingFlags.Instance
            );

            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<string>("address"),
                new Param<int>("yearBuilt"),
                new Param<decimal>("price"),
                new Param<string>("unitNumber"),
                new Param<decimal>("fee"),
                new Param<bool>("isRental") { Default = false }
            );

            assert.NonConstructor(
                BindingFlags.Public |
                BindingFlags.Instance
            );

            assert.Property<decimal>(
                "TotalCost",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override().DeclaredIn<Condo>(); ;

            assert.Method<decimal>(
                "GetRate",
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("numberOfPeriods")
            ).Override().DeclaredIn<Condo>();

            assert.Method<decimal>(
                "GetMonthlyRate",
                BindingFlags.Public |
                BindingFlags.Instance
            );
#if !DEBUG
    });
#endif
        }
Exemplo n.º 3
0
        public void TestThreeCalc()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<ThreeCalc>();
            assert.Class();
            assert.Extends<TwoCalc>();
            assert.Implements<ICalc>();

            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("a"),
                new Param<int>("b"),
                new Param<int>("c")
            );

            assert.NonField<int>(
                "_a",
                BindingFlags.NonPublic |
                BindingFlags.Public |
                BindingFlags.Instance
            );

            assert.NonField<int>(
                "_b",
                BindingFlags.NonPublic |
                BindingFlags.Public |
                BindingFlags.Instance
            );

            assert.Field<int>(
                "_c",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).Private().ReadOnly();

            assert.Method<int>(
                "Calculate",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();

            assert.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();

            dynamic calc;
            calc = assert.New(1, 2, 3);
            Assert.AreEqual(14, calc.Calculate());
            Assert.AreEqual("1, 2, 3", calc.ToString());

            calc = assert.New(1, 3, 5);
            Assert.AreEqual(22, calc.Calculate());
            Assert.AreEqual("1, 3, 5", calc.ToString());

            calc = assert.New(-10, 4, -100);
            Assert.AreEqual(-302, calc.Calculate());
            Assert.AreEqual("-10, 4, -100", calc.ToString());
#if !DEBUG
});
#endif
        }