コード例 #1
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
        }
コード例 #2
0
        public void TestSphereClass()
        {
            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();

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

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

            assert.Field <int>(
                "Dimension3",
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).DeclaredIn <ThreeDimensionalShape>();
        }
コード例 #3
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
        }
コード例 #4
0
        public void TestSingleFamily()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<SingleFamily>();
            assert.Extends<Home>();
            assert.NotImplements<IRental>();

            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();
#if !DEBUG
});
#endif
        }
コード例 #5
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
        }
コード例 #6
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
        }
コード例 #7
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
        }
コード例 #8
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
        }
コード例 #9
0
        public void TestCircle()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            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();

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

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

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

            obj.Radius = 7;
            Assert.AreEqual(7, dimension1.GetValue(obj));
            Assert.AreEqual(7, dimension2.GetValue(obj));
            Assert.AreEqual(153.93804002589985, obj.Area, 1E-10);
            Assert.AreEqual("(1, 2) radius: 7", obj.ToString());
#if !DEBUG
});
#endif
        }
コード例 #10
0
        public void TestParkClass()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Park>();
            assert.Class();
            assert.NonAbstract();
            assert.Field<string>(
                "_name",
                BindingFlags.Instance |
                BindingFlags.NonPublic
            ).Private().ReadOnly();

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

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

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

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

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

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

            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<string>("name"),
                new Param<string>("address"),
                new Param<FacilityType>("type"),
                new Param<string>("phone"),
                new Param<int>("openingHour"),
                new Param<int>("closingHour"),
                new Param<decimal>("fee")
            );

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

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

            assert.Method<decimal>(
                "CalculateFee",
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("numberOfVisitors")
            );

            assert.Method<decimal>(
                "CalculateFee",
                BindingFlags.Public |
                BindingFlags.Static,
                new Param<int>("numberOfVisitors"),
                new Param<Park[]>("parks")
            );

            assert.Method(
                "Show",
                BindingFlags.Public |
                BindingFlags.Static,
                new Param<Park[]>("parks")
            );
#if !DEBUG
    });
#endif
        }