Ejemplo n.º 1
0
        public void Employee_HasRequiredMembers()
        {
            Type type = typeof(Employee);

            PropertyInfo prop = type.GetProperty("EmployeeId");

            PropertyValidator.ValidateReadPrivateWrite(prop, "EmployeeId", typeof(int));

            prop = type.GetProperty("FirstName");
            PropertyValidator.ValidateReadPrivateWrite(prop, "FirstName", typeof(string));

            prop = type.GetProperty("LastName");
            PropertyValidator.ValidateReadWrite(prop, "LastName", typeof(string));

            prop = type.GetProperty("FullName");
            PropertyValidator.ValidateReadOnly(prop, "FullName", typeof(string));

            prop = type.GetProperty("Department");
            PropertyValidator.ValidateReadWrite(prop, "Department", typeof(string));

            prop = type.GetProperty("AnnualSalary");
            PropertyValidator.ValidateReadPrivateWrite(prop, "AnnualSalary", typeof(double));

            MethodInfo method = type.GetMethod("RaiseSalary");

            MethodValidator.ValidatePublicMethod(method, "RaiseSalary", typeof(void));
        }
Ejemplo n.º 2
0
        public void Airplane_HasRequiredMembers()
        {
            Type type = typeof(Airplane);

            PropertyInfo prop = type.GetProperty("PlaneNumber");

            PropertyValidator.ValidateReadPrivateWrite(prop, "PlaneNumber", typeof(string));

            prop = type.GetProperty("BookedFirstClassSeats");
            PropertyValidator.ValidateReadPrivateWrite(prop, "BookedFirstClassSeats", typeof(int));

            prop = type.GetProperty("AvailableFirstClassSeats");
            PropertyValidator.ValidateReadOnly(prop, "AvailableFirstClassSeats", typeof(int));

            prop = type.GetProperty("TotalFirstClassSeats");
            PropertyValidator.ValidateReadPrivateWrite(prop, "TotalFirstClassSeats", typeof(int));

            prop = type.GetProperty("BookedCoachSeats");
            PropertyValidator.ValidateReadPrivateWrite(prop, "BookedCoachSeats", typeof(int));

            prop = type.GetProperty("AvailableCoachSeats");
            PropertyValidator.ValidateReadOnly(prop, "AvailableCoachSeats", typeof(int));

            prop = type.GetProperty("TotalCoachSeats");
            PropertyValidator.ValidateReadPrivateWrite(prop, "TotalCoachSeats", typeof(int));

            MethodInfo method = type.GetMethod("ReserveSeats");

            MethodValidator.ValidatePublicMethod(method, "ReserveSeats", typeof(bool));
        }
Ejemplo n.º 3
0
        public void Elevator_HasRequiredMembers()
        {
            Type     type     = typeof(Elevator);
            Elevator elevator = (Elevator)Activator.CreateInstance(type, 3);

            PropertyInfo prop = type.GetProperty("CurrentLevel");

            PropertyValidator.ValidateReadPrivateWrite(prop, "CurrentLevel", typeof(int));

            prop = type.GetProperty("NumberOfLevels");
            PropertyValidator.ValidateReadOnly(prop, "NumberOfLevels", typeof(int));

            prop = type.GetProperty("DoorIsOpen");
            PropertyValidator.ValidateReadPrivateWrite(prop, "DoorIsOpen", typeof(bool));

            MethodInfo method = type.GetMethod("OpenDoor");

            MethodValidator.ValidatePublicMethod(method, "OpenDoor", typeof(void));

            method = type.GetMethod("CloseDoor");
            MethodValidator.ValidatePublicMethod(method, "CloseDoor", typeof(void));

            method = type.GetMethod("GoUp");
            MethodValidator.ValidatePublicMethod(method, "GoUp", typeof(void));
            Assert.AreEqual(1, method.GetParameters().Length, "GoUp should accept 1 parameter");

            method = type.GetMethod("GoDown");
            MethodValidator.ValidatePublicMethod(method, "GoDown", typeof(void));
            Assert.AreEqual(1, method.GetParameters().Length, "GoDown should accept 1 parameter");
        }
Ejemplo n.º 4
0
        public void FruitTree_HasRequiredMembers()
        {
            Type type = typeof(FruitTree);

            PropertyInfo[] properties = type.GetProperties();

            PropertyInfo prop = FindPropertyByName(properties, "TypeOfFruit");

            PropertyValidator.ValidateReadPrivateWrite(prop, "TypeOfFruit", typeof(string));

            prop = FindPropertyByName(properties, "PiecesOfFruitLeft");
            PropertyValidator.ValidateReadPrivateWrite(prop, "PiecesOfFruitLeft", typeof(int));

            MethodInfo method = type.GetMethod("PickFruit");

            Assert.IsNotNull(method, "You do not have the PickFruit method");
            Assert.AreEqual(typeof(bool), method.ReturnType, "Your PickFruit method should return a bool");
            Assert.AreEqual(true, method.IsPublic, "PickFruit should be a public method");
        }
        public void Television_HasRequiredMembers()
        {
            Type       type = typeof(Television);
            Television tv   = (Television)Activator.CreateInstance(type);

            PropertyInfo prop = type.GetProperty("IsOn");

            PropertyValidator.ValidateReadPrivateWrite(prop, "IsOn", typeof(bool));

            prop = type.GetProperty("CurrentChannel");
            PropertyValidator.ValidateReadPrivateWrite(prop, "CurrentChannel", typeof(int));

            prop = type.GetProperty("CurrentVolume");
            PropertyValidator.ValidateReadPrivateWrite(prop, "CurrentVolume", typeof(int));

            MethodInfo method = type.GetMethod("TurnOff");

            MethodValidator.ValidatePublicMethod(method, "TurnOff", typeof(void));

            method = type.GetMethod("TurnOn");
            MethodValidator.ValidatePublicMethod(method, "TurnOn", typeof(void));

            method = type.GetMethod("ChangeChannel");
            MethodValidator.ValidatePublicMethod(method, "ChangeChannel", typeof(void));
            Assert.AreEqual(1, method.GetParameters().Length, "ChangeChannel should accept 1 parameter");

            method = type.GetMethod("ChannelUp");
            MethodValidator.ValidatePublicMethod(method, "ChannelUp", typeof(void));

            method = type.GetMethod("ChannelDown");
            MethodValidator.ValidatePublicMethod(method, "ChannelDown", typeof(void));

            method = type.GetMethod("RaiseVolume");
            MethodValidator.ValidatePublicMethod(method, "RaiseVolume", typeof(void));

            method = type.GetMethod("LowerVolume");
            MethodValidator.ValidatePublicMethod(method, "LowerVolume", typeof(void));
        }