Exemplo n.º 1
0
        public void Money()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Money>();
            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<decimal>("money")
            );
            assert.Constructor(
                BindingFlags.Instance |
                 BindingFlags.Public,
                new Param<Money>("money")
            );
            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<int>("dollars"),
                new Param<int>("cents")
            );
            assert.Property<int>(
                "Dollars",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            );
            assert.Property<int>(
                "Cents",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            );
            assert.Method(
                "IncrementMoney",
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<Money>("money")
            );
            assert.Method(
                "DecrementMoney",
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<Money>("money")
            );

            assert.Method<string>(
                "ToString",
                BindingFlags.Instance |
                BindingFlags.Public
            ).Override();
#if !DEBUG
        });
#endif
        }
Exemplo n.º 2
0
        public void Student()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Student>();
            assert.Property<string>(
                "FirstName",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty);
            assert.Property<string>(
                "LastName",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty);
            assert.Property<string>(
                "StudentNumber",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty);
            assert.Property<decimal>(
                "GPA",
                 BindingFlags.Instance |
                 BindingFlags.Public |
                 BindingFlags.GetProperty |
                 BindingFlags.SetProperty);
            assert.Property<string>(
                "Major",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty);
            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<string>("firstName"),
                new Param<string>("lastName"),
                new Param<string>("studentNumber")
            );

            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<string>("firstName"),
                new Param<string>("lastName"),
                new Param<string>("studentNumber"),
                new Param<decimal>("gpa"),
                new Param<string>("major")
                );
#if !DEBUG
        });
#endif
        }
Exemplo n.º 3
0
        public void TestAggregatorClass()
        {
            var aggregator = new TypeAssert <Aggregator>();

            aggregator.Class();
            aggregator.NonAbstract();
            aggregator.PropertyOrField <int[]>("Numbers",
                                               BindingFlags.NonPublic |
                                               BindingFlags.Instance |
                                               BindingFlags.GetField |
                                               BindingFlags.GetProperty)?.Protected()?.ReadOnly();

            aggregator.Constructor(
                BindingFlags.NonPublic |
                BindingFlags.Instance,
                new Param <int[]>("numbers"))?.Protected();

            aggregator.Method <int>(
                "GetValue",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty,
                new Param <int>("n")
                )?.Virtual();

            aggregator.Method <string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.DeclaredOnly
                ).Override();
        }
Exemplo n.º 4
0
        public void TestAccountClass()
        {
#if !DEBUG
            Assert.Multiple(() => {
#endif

            var accountClass = new TypeAssert<Account>();

            var balanceField = accountClass.Field<decimal>("_balance",
               BindingFlags.NonPublic |
               BindingFlags.Instance |
               BindingFlags.GetField |
               BindingFlags.SetField
               ).NonPublic();

            var nameProperty = accountClass.Property<string>("Name",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty);

            var balanceProperty = accountClass.Property<decimal>("Balance",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty);

            balanceProperty.NotAutoImplemented();

            var constructor = accountClass.Constructor(
                BindingFlags.Public | BindingFlags.Instance,
                new Param<string>("name"),
                new Param<decimal>("balance"));

            accountClass.Method("Deposit",
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<decimal>("depositAmount"));

            accountClass.Method("Withdraw",
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<decimal>("withdrawAmount")
                );

            // testing

            dynamic account;

            account = accountClass.New("Darth Vader", -1.1m);
            Assert.AreEqual(0m, balanceField.GetValue(account));
            Assert.AreEqual("Darth Vader", account.Name);
            Assert.AreEqual(0m, account.Balance);

            account = accountClass.New("Padme Amidala", 1.49m);
            Assert.AreEqual(1.49m, balanceField.GetValue(account));
            Assert.AreEqual("Padme Amidala", account.Name);
            Assert.AreEqual(1.49m, account.Balance);
#if !DEBUG
            });
#endif
        }
        public void Constructor()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<CheckingAccount>();
            assert.Extends<Account>();
            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<decimal>("initialBalance"),
                new Param<decimal>("transactionFee")
            );

            assert.NonConstructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<decimal>("initialBalance")
            );
            // new CheckingAccount(11.5m, -0.05m);
            assert.Catch<ArgumentOutOfRangeException>(() => assert.New(11.5m, -0.05m));
#if !DEBUG
        });
#endif
        }
        public void TestSingleFamily()
        {
            var assert = new TypeAssert <SingleFamily>();

            assert.Extends <Home>();

            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.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param <string>("address"),
                new Param <int>("yearBuilt"),
                new Param <decimal>("price")
                );

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

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

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

            assert.Method <string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
                ).DeclaredIn <SingleFamily>().Override();
        }
        public void TestTwoDimensionalShapeClass()
        {
            var assert = new TypeAssert <TwoDimensionalShape>();

            assert.Extends <Shape>();
            assert.Constructor(
                BindingFlags.NonPublic |
                BindingFlags.Instance,
                new Param <int>("x"),
                new Param <int>("y"),
                new Param <int>("dimension1"),
                new Param <int>("dimension2")
                ).Protected();

            assert.Field <int>(
                "Dimension1",
                BindingFlags.Instance |
                BindingFlags.NonPublic
                ).Protected();

            assert.Field <int>(
                "Dimension2",
                BindingFlags.Instance |
                BindingFlags.NonPublic
                ).Protected();

            assert.Property <double>(
                "Area",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty
                ).Virtual();
        }
        public void TestCountClass()
        {
            var count = new TypeAssert <Count>();

            count.Class();
            count.NonAbstract();
            count.Extends <Aggregator>();
            count.NonPropertyAndField <int[]>("Numbers",
                                              BindingFlags.NonPublic |
                                              BindingFlags.Instance |
                                              BindingFlags.GetField |
                                              BindingFlags.GetProperty);

            count.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param <int[]>("numbers"))?.Public();

            count.Method <int>(
                "GetValue",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty,
                new Param <int>("n")
                )?.Override();
        }
        public void TestHomeClass()
        {
            var assert = new TypeAssert <Home>();

            assert.Constructor(
                BindingFlags.NonPublic |
                BindingFlags.Instance,
                new Param <string>("address"),
                new Param <int>("yearBuilt"),
                new Param <decimal>("price")
                ).Protected();

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

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

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

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

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

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

            assert.Method <string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
                ).Override();
        }
Exemplo n.º 10
0
        public void TestClass()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Square>();
            assert.Extends<Rectangle>();

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

            assert.NonConstructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<int>("width"),
                new Param<int>("height")
            );

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

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

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

            assert.Method<decimal>(
              "Area",
              BindingFlags.Instance |
              BindingFlags.Public)
                  .DeclaredIn<Rectangle>();

            assert.Method<decimal>(
              "Perimeter",
              BindingFlags.Instance |
              BindingFlags.Public)
                  .DeclaredIn<Rectangle>();
#if !DEBUG
        });
#endif
        }
Exemplo n.º 11
0
        public void TestCircleClass()
        {
            var assert = new TypeAssert <Circle>();

            assert.Extends <TwoDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param <int>("x"),
                new Param <int>("y"),
                new Param <int>("radius")
                );
            assert.ConstructorCount(1);

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

            assert.Property <double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
                ).Override();

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

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

            assert.Field <int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).DeclaredIn <TwoDimensionalShape>();

            assert.Field <int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).DeclaredIn <TwoDimensionalShape>();
        }
Exemplo n.º 12
0
        public void TestShape()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Shape>();

            assert.Abstract();

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

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

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

            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.NonPublic,
                new Param<int>("x"),
                new Param<int>("y")
            );

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

            assert.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();
#if !DEBUG
        });
#endif
        }
Exemplo n.º 13
0
        public void TestThreeDimensionalShape()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<ThreeDimensionalShape>();
            assert.Abstract();
            assert.Extends<Shape>();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.Instance,
                new Param<int>("x"),
                new Param<int>("y"),
                new Param<int>("dimension1"),
                new Param<int>("dimension2"),
                new Param<int>("dimension3")
            );

            assert.Field<int>(
                "Dimension1",
                BindingFlags.Instance |
                BindingFlags.NonPublic
            ).Protected();

            assert.Field<int>(
                "Dimension2",
                BindingFlags.Instance |
                BindingFlags.NonPublic
            ).Protected();

            assert.Field<int>(
                "Dimension3",
                BindingFlags.Instance |
                BindingFlags.NonPublic
            ).Protected();

            assert.Property<double>(
                "Area",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty
            ).Abstract();

            assert.Property<double>(
                "Volume",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty
            ).Abstract();
#if !DEBUG
});
#endif
        }
Exemplo n.º 14
0
        public void TestListCalcClass()
        {
            var assert = new TypeAssert <ListCalc>();

            assert.Extends <BaseCalc>();
            assert.Class();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param <List <BaseCalc> >("calculations")
                );

            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param <int[]>("values")
            {
                Params = true
            }
                );

            assert.Field <List <BaseCalc> >(
                "Calculations",
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).Protected().ReadOnly();

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

            assert.Method <string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
                ).Override();
        }
Exemplo n.º 15
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.º 16
0
        public void TestClass()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<EmptyTextShape>();
            assert.Property<int>(
                "Width",
                BindingFlags.Instance |
                 BindingFlags.Public |
                BindingFlags.GetProperty
            );
            assert.Property<int>(
                "Height",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty
            );
            assert.Property<string>(
                "Name",
                BindingFlags.Instance |
                BindingFlags.Public |
                BindingFlags.GetProperty);
            assert.Method(
                "Draw",
                 BindingFlags.Instance |
                 BindingFlags.Public
            );
            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param<int>("width"),
                new Param<int>("height")
            );
            assert.Method<decimal>(
                "Area",
                BindingFlags.Instance |
                BindingFlags.Public
            ).Virtual();

            assert.Method<decimal>(
                "Perimeter",
                BindingFlags.Instance |
                BindingFlags.Public
            ).Virtual();
#if !DEBUG
        });
#endif
        }
        public void Constructor()
        {
            var assert = new TypeAssert <Account>();

            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param <decimal>("balance")
                );
            dynamic account;

            // new Account(1000.5m);
            account = assert.New(1000.5m);
            Assert.AreEqual(1000.5m, account.Balance);
            assert.Catch <ArgumentOutOfRangeException>(() => account = assert.New(-0.5m));
        }
        public void TestBaseCalcClass()
        {
            var assert = new TypeAssert <BaseCalc>();

            assert.Constructor(
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).Protected();

            assert.Method <int>(
                "Calculate",
                BindingFlags.Public |
                BindingFlags.DeclaredOnly |
                BindingFlags.Instance
                ).Virtual();
        }
        public void TestShapeClass()
        {
            var assert = new TypeAssert <Shape>();

            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.NonPublic,
                new Param <int>("x"),
                new Param <int>("y")
                ).Protected();


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

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

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


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

            assert.Method <string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
                ).Override();
        }
        public void TestThreeCalcClass()
        {
            var assert = new TypeAssert <ThreeCalc>();

            assert.Class();
            assert.Extends <TwoCalc>();

            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();
        }
Exemplo n.º 21
0
        public void TestAggregator()
        {
#if !DEBUG
            Assert.Multiple(() =>
            {
#endif
            var aggregator = new TypeAssert<Aggregator>();
            aggregator.Class();
            aggregator.Abstract();
            aggregator.Field<List<int>>("Numbers",
                BindingFlags.NonPublic |
                BindingFlags.Instance |
                BindingFlags.GetField)?.Protected()?.ReadOnly();

            aggregator.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int[]>("numbers"));

            aggregator.Property<int>(
                "Value",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            )?.Abstract();

            aggregator.Method(
                "Append",
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<Aggregator>("aggregators")
            )?.Virtual();

            aggregator.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.DeclaredOnly
            );

#if !DEBUG
            });
#endif
        }
Exemplo n.º 22
0
        public void TestAverage()
        {
#if !DEBUG
            Assert.Multiple(() =>
            {
#endif
            var average = new TypeAssert<Average>();
            average.Extends<Sum>();
            average.Class();
            average.Field<List<int>>("_count",
                BindingFlags.NonPublic |
                BindingFlags.Instance |
                BindingFlags.GetField)?.Private()?.ReadOnly();

            average.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int[]>("numbers"));

            average.Property<int>(
                "Value",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            )?.Override();

            average.Property<decimal>(
                "DecimalValue",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            );

            average.Property<int>(
                "Value",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            )?.Override();
#if !DEBUG
            });
#endif
        }
Exemplo n.º 23
0
        public void Constructor()
        {
            var assert = new TypeAssert <SavingsAccount>();

            assert.Extends <Account>();
            assert.Constructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param <decimal>("initialBalance"),
                new Param <decimal>("transactionFee")
                );

            assert.NonConstructor(
                BindingFlags.Instance |
                BindingFlags.Public,
                new Param <decimal>("initialBalance")
                );
            // new SavingsAccount(11.5m, -0.05m);
            assert.Catch <ArgumentOutOfRangeException>(() => assert.New(11.5m, -0.05m));
        }
Exemplo n.º 24
0
        public void TestSum()
        {
#if !DEBUG
            Assert.Multiple(() =>
            {
#endif
            var sum = new TypeAssert<Sum>();
            sum.Class();
            sum.Extends<Aggregator>();
            sum.NonField<List<int>>("Numbers",
                BindingFlags.NonPublic |
                BindingFlags.Public |
                BindingFlags.DeclaredOnly |
                BindingFlags.Instance |
                BindingFlags.GetField);

            sum.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int[]>("numbers"));

            sum.Property<int>(
                "Value",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            )?.Override();

            sum.Method(
                "Append",
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<Aggregator>("aggregators")
            )?.Override();

#if !DEBUG
            });
#endif
        }
Exemplo n.º 25
0
        public void TestCount()
        {
#if !DEBUG
            Assert.Multiple(() =>
            {
#endif
            var count = new TypeAssert<Count>();
            count.Class();
            count.Extends<Aggregator>();
            count.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int[]>("numbers"));
            count.Property<int>(
                "Value",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            )?.Override();

#if !DEBUG
            });
#endif
        }
Exemplo n.º 26
0
        public void TestSphere()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Sphere>();
            assert.Extends<ThreeDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("x"),
                new Param<int>("y"),
                new Param<int>("radius")
            );
            assert.ConstructorCount(1);

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

            assert.Property<double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Volume",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

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

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

            var dimension1 = assert.Field<int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension2 = assert.Field<int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension3 = assert.Field<int>(
              "Dimension3",
              BindingFlags.NonPublic |
              BindingFlags.Instance
          ).DeclaredIn<ThreeDimensionalShape>();

            // var obj = new Sphere(1, 2 ,3);
            dynamic obj = assert.New(2, 1, 4);
            Assert.AreEqual("Sphere", obj.Name);
            Assert.AreEqual(2, obj.X);
            Assert.AreEqual(1, obj.Y);
            Assert.AreEqual(4, obj.Radius);
            Assert.AreEqual(4, dimension1.GetValue(obj));
            Assert.AreEqual(4, dimension2.GetValue(obj));
            Assert.AreEqual(4, dimension3.GetValue(obj));
            Assert.AreEqual(201.06192982974676, obj.Area, 1E-10);
            Assert.AreEqual(268.08257310632899, obj.Volume, 1E-10);
            Assert.AreEqual("(2, 1) radius: 4", obj.ToString());

            obj.Radius = 7;
            Assert.AreEqual(7, dimension1.GetValue(obj));
            Assert.AreEqual(7, dimension2.GetValue(obj));
            Assert.AreEqual(615.75216010359941, obj.Area, 1E-10);
            Assert.AreEqual(1436.7550402417321, obj.Volume, 1E-10);
            Assert.AreEqual("(2, 1) radius: 7", obj.ToString());
#if !DEBUG
});
#endif
        }
Exemplo n.º 27
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.º 28
0
        public void TestHome()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Home>();
            assert.Abstract();
            assert.Property<string>(
              "Address",
              BindingFlags.Instance |
              BindingFlags.Public |
              BindingFlags.GetProperty);

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

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

            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<string>("address"),
                new Param<int>("yearBuilt"),
                new Param<decimal>("price")
            );

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

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

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

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

#if !DEBUG
        });
#endif
        }
Exemplo n.º 29
0
        public void TestCube()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Cube>();
            assert.Extends<ThreeDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("x"),
                new Param<int>("y"),
                new Param<int>("side")
            );
            assert.ConstructorCount(1);

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

            assert.Property<double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Volume",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

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

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

            var dimension1 = assert.Field<int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension2 = assert.Field<int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension3 = assert.Field<int>(
                "Dimension3",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            // var obj = new Sphere(1, 2 ,3);
            dynamic obj = assert.New(3, 5, 2);
            Assert.AreEqual("Cube", obj.Name);
            Assert.AreEqual(3, obj.X);
            Assert.AreEqual(5, obj.Y);
            Assert.AreEqual(2, obj.Side);
            Assert.AreEqual(2, dimension1.GetValue(obj));
            Assert.AreEqual(2, dimension2.GetValue(obj));
            Assert.AreEqual(2, dimension3.GetValue(obj));
            Assert.AreEqual(24, obj.Area, 1E-10);
            Assert.AreEqual(8, obj.Volume, 1E-10);
            Assert.AreEqual("(3, 5) side: 2", obj.ToString());

            obj.Side = 7;
            Assert.AreEqual(7, dimension1.GetValue(obj));
            Assert.AreEqual(7, dimension2.GetValue(obj));
            Assert.AreEqual(294, obj.Area, 1E-10);
            Assert.AreEqual(343, obj.Volume, 1E-10);
            Assert.AreEqual("(3, 5) side: 7", obj.ToString());
#if !DEBUG
});
#endif
        }
Exemplo n.º 30
0
        public void TestInvoiceClass()
        {
#if !DEBUG
            Assert.Multiple(() => {
#endif
            var invoiceClass = new TypeAssert<Invoice>();

            var partNumber = invoiceClass.Property<string>("PartNumber",
                 BindingFlags.Public |
                 BindingFlags.Instance |
                 BindingFlags.GetProperty |
                 BindingFlags.SetProperty
             ).AutoImplemented();

            var partDescription = invoiceClass.Property<string>("PartDescription",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            ).AutoImplemented();

            var quantityField = invoiceClass.Field<int>("_quantity",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            );

            var pricePerItemField = invoiceClass.Field<decimal>("_pricePerItem",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            );

            var quantity = invoiceClass.Property<int>("Quantity",
                    BindingFlags.Public |
                    BindingFlags.Instance |
                    BindingFlags.GetProperty |
                    BindingFlags.SetProperty
                ).NotAutoImplemented();

            var pricePerItem = invoiceClass.Property<decimal>("PricePerItem",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            ).NotAutoImplemented();

            var constructor = invoiceClass.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<string>("partNumber"),
                new Param<string>("partDescription"),
                new Param<int>("quantity"),
                new Param<decimal>("price"));

            var getInvoiceAmount = invoiceClass.Method<decimal>(
                "GetInvoiceAmount",
                BindingFlags.Public |
                BindingFlags.Instance);

            // field testing
            Invoice invoice = invoiceClass.New("1234", "Hammer", 2, 14.95m);
            Assert.AreEqual(2, quantityField.GetValue(invoice), "Initial Quantity");
            Assert.AreEqual(14.95m, pricePerItemField.GetValue(invoice), "Initial price per item");
#if !DEBUG
            });
#endif
        }