コード例 #1
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
        }
コード例 #2
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
        }
コード例 #3
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
        }
コード例 #4
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
        }