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>(); }
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 }
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 }
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 }
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 }
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 }