Ejemplo n.º 1
0
        public void Company_CheckRequiredMembers()
        {
            Type    type    = typeof(Company);
            Company company = (Company)Activator.CreateInstance(type, "ACME");

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

            PropertyValidator.ValidateReadOnly(prop, "Name", typeof(string));

            prop = type.GetProperty("NumberOfEmployees");
            PropertyValidator.ValidateReadWrite(prop, "NumberOfEmployees", typeof(int));

            prop = type.GetProperty("Revenue");
            PropertyValidator.ValidateReadWrite(prop, "Revenue", typeof(decimal));

            prop = type.GetProperty("Expenses");
            PropertyValidator.ValidateReadWrite(prop, "Expenses", typeof(decimal));


            MethodInfo mi = type.GetMethod("GetCompanySize");

            Assert.IsNotNull(mi, "A method called GetCompanySize needs to be included");
            Assert.AreEqual(typeof(string), mi.ReturnType, "The GetCompanySize() method needs to be type: string");

            mi = type.GetMethod("GetProfit");
            Assert.IsNotNull(mi, "A method called GetProfit needs to be included");
            Assert.AreEqual(typeof(decimal), mi.ReturnType, "The GetProfit() method needs to be type: decimal");
        }
Ejemplo n.º 2
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.º 3
0
        public void Product_CheckRequiredMembers()
        {
            Type    type    = typeof(Product);
            Product product = (Product)Activator.CreateInstance(type);

            FieldInfo fi = type.GetField("name", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNotNull(fi, "A field called name needs to exist");
            Assert.AreEqual(typeof(string), fi.FieldType, "The name field needs to be type: string");

            fi = type.GetField("price", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called price needs to exist");
            Assert.AreEqual(typeof(decimal), fi.FieldType, "The price field needs to be type: decimal");

            fi = type.GetField("weightInOunces", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called weightInOunces needs to exist");
            Assert.AreEqual(typeof(double), fi.FieldType, "The weightInOunces field needs to be type: double");

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

            PropertyValidator.ValidateReadWrite(prop, "Name", typeof(string));

            prop = type.GetProperty("Price");
            PropertyValidator.ValidateReadWrite(prop, "Price", typeof(decimal));

            prop = type.GetProperty("WeightInOunces");
            PropertyValidator.ValidateReadWrite(prop, "WeightInOunces", typeof(double));
        }
Ejemplo n.º 4
0
        public void Company_ExpensesProperty()
        {
            Type    type    = typeof(Company);
            Company company = (Company)Activator.CreateInstance(type, "ACME");

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

            PropertyValidator.ValidateReadWrite(prop, "Expenses", typeof(decimal));
        }
        public void Person_LastNameProperty()
        {
            Type   type   = typeof(Person);
            Person person = (Person)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "LastName", typeof(string));
        }
        public void Product_PriceProperty()
        {
            Type    type    = typeof(Product);
            Product product = (Product)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "Price", typeof(decimal));
        }
        public void Product_WeightProperty()
        {
            Type    type    = typeof(Product);
            Product product = (Product)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "WeightInOunces", typeof(double));
        }
        public void Product_NameProperty()
        {
            Type    type    = typeof(Product);
            Product product = (Product)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "Name", typeof(string));
        }
        public void Person_AgeProperty()
        {
            Type   type   = typeof(Person);
            Person person = (Person)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "Age", typeof(int));
        }
Ejemplo n.º 10
0
        public void Company_NumberOfEmployeesProperty()
        {
            Type    type    = typeof(Company);
            Company company = (Company)Activator.CreateInstance(type, "ACME");

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

            PropertyValidator.ValidateReadWrite(prop, "NumberOfEmployees", typeof(int));
        }
Ejemplo n.º 11
0
        public void Product_CheckRequiredMembers()
        {
            Type    type    = typeof(Product);
            Product product = (Product)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "Name", typeof(string));

            prop = type.GetProperty("Price");
            PropertyValidator.ValidateReadWrite(prop, "Price", typeof(decimal));

            prop = type.GetProperty("WeightInOunces");
            PropertyValidator.ValidateReadWrite(prop, "WeightInOunces", typeof(double));
        }
Ejemplo n.º 12
0
        public void Company_CheckRequiredMembers()
        {
            Type    type    = typeof(Company);
            Company company = (Company)Activator.CreateInstance(type, "ACME");

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

            PropertyValidator.ValidateReadOnly(prop, "Name", typeof(string));

            prop = type.GetProperty("NumberOfEmployees");
            PropertyValidator.ValidateReadWrite(prop, "NumberOfEmployees", typeof(int));

            prop = type.GetProperty("Revenue");
            PropertyValidator.ValidateReadWrite(prop, "Revenue", typeof(decimal));

            prop = type.GetProperty("Expenses");
            PropertyValidator.ValidateReadWrite(prop, "Expenses", typeof(decimal));

            FieldInfo fi = type.GetField("name", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNotNull(fi, "A field called name needs to exist");
            Assert.AreEqual(typeof(string), fi.FieldType, "The name field needs to be type: string");

            fi = type.GetField("numberOfEmployees", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called numberOfEmployees needs to exist");
            Assert.AreEqual(typeof(int), fi.FieldType, "The numberOfEmployees field needs to be type: int");

            fi = type.GetField("revenue", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called revenue needs to exist");
            Assert.AreEqual(typeof(decimal), fi.FieldType, "The revenue field needs to be type: decimal");

            fi = type.GetField("expenses", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called expenses needs to exist");
            Assert.AreEqual(typeof(decimal), fi.FieldType, "The expenses field needs to be type: decimal");

            MethodInfo mi = type.GetMethod("GetCompanySize");

            Assert.IsNotNull(mi, "A method called GetCompanySize needs to be included");
            Assert.AreEqual(typeof(string), mi.ReturnType, "The GetCompanySize() method needs to be type: string");

            mi = type.GetMethod("GetProfit");
            Assert.IsNotNull(mi, "A method called GetProfit needs to be included");
            Assert.AreEqual(typeof(decimal), mi.ReturnType, "The GetProfit() method needs to be type: decimal");
        }
        public void Homework_HasRequiredProperties()
        {
            Type type = typeof(HomeworkAssignment);

            PropertyInfo[] properties = type.GetProperties();

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

            PropertyValidator.ValidateReadWrite(prop, "EarnedMarks", typeof(int));

            prop = FindPropertyByName(properties, "PossibleMarks");
            PropertyValidator.ValidateReadWrite(prop, "PossibleMarks", typeof(int));

            prop = FindPropertyByName(properties, "SubmitterName");
            PropertyValidator.ValidateReadWrite(prop, "SubmitterName", typeof(string));


            prop = FindPropertyByName(properties, "LetterGrade");
            PropertyValidator.ValidateReadOnly(prop, "LetterGrade", typeof(string));
        }
Ejemplo n.º 14
0
        public void Homework_HasRequiredProperties()
        {
            Type type = typeof(HomeworkAssignment);
            HomeworkAssignment assignment = (HomeworkAssignment)Activator.CreateInstance(type, 100, "Default Name");

            PropertyInfo[] properties = type.GetProperties();

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

            PropertyValidator.ValidateReadWrite(prop, "TotalMarks", typeof(int));

            prop = FindPropertyByName(properties, "PossibleMarks");
            PropertyValidator.ValidateReadOnly(prop, "PossibleMarks", typeof(int));

            prop = FindPropertyByName(properties, "SubmitterName");
            PropertyValidator.ValidateReadOnly(prop, "SubmitterName", typeof(string));


            prop = FindPropertyByName(properties, "LetterGrade");
            PropertyValidator.ValidateReadOnly(prop, "LetterGrade", typeof(string));
        }
Ejemplo n.º 15
0
        public void Person_CheckRequiredMembers()
        {
            Type   type   = typeof(Person);
            Person person = (Person)Activator.CreateInstance(type);

            FieldInfo fi = type.GetField("firstName", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNotNull(fi, "A field called firstName needs to exist");
            Assert.AreEqual(typeof(string), fi.FieldType, "The firstName field needs to be type: string");

            fi = type.GetField("lastName", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called lastName needs to exist");
            Assert.AreEqual(typeof(string), fi.FieldType, "The lastName field needs to be type: string");

            fi = type.GetField("age", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(fi, "A field called age needs to exist");
            Assert.AreEqual(typeof(int), fi.FieldType, "The age field needs to be type: int");

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

            PropertyValidator.ValidateReadWrite(prop, "FirstName", typeof(string));

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

            prop = type.GetProperty("Age");
            PropertyValidator.ValidateReadWrite(prop, "Age", typeof(int));

            MethodInfo mi = type.GetMethod("GetFullName");

            Assert.IsNotNull(mi, "A method called GetFullName needs to be included");
            Assert.AreEqual(typeof(string), mi.ReturnType, "The GetFullName() method needs to be type: string");

            mi = type.GetMethod("IsAdult");
            Assert.IsNotNull(mi, "A method called IsAdult needs to be included");
            Assert.AreEqual(typeof(bool), mi.ReturnType, "The IsAdult() method needs to be type: bool");
        }
Ejemplo n.º 16
0
        public void Person_CheckRequiredMembers()
        {
            Type   type   = typeof(Person);
            Person person = (Person)Activator.CreateInstance(type);

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

            PropertyValidator.ValidateReadWrite(prop, "FirstName", typeof(string));

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

            prop = type.GetProperty("Age");
            PropertyValidator.ValidateReadWrite(prop, "Age", typeof(int));

            MethodInfo mi = type.GetMethod("GetFullName");

            Assert.IsNotNull(mi, "A method called GetFullName needs to be included");
            Assert.AreEqual(typeof(string), mi.ReturnType, "The GetFullName() method needs to be type: string");

            mi = type.GetMethod("IsAdult");
            Assert.IsNotNull(mi, "A method called IsAdult needs to be included");
            Assert.AreEqual(typeof(bool), mi.ReturnType, "The IsAdult() method needs to be type: bool");
        }
Ejemplo n.º 17
0
        public void Product_WeightProperty()
        {
            PropertyInfo prop = type.GetProperty("WeightInOunces");

            PropertyValidator.ValidateReadWrite(prop, "WeightInOunces", typeof(double));
        }
Ejemplo n.º 18
0
        public void Product_PriceProperty()
        {
            PropertyInfo prop = type.GetProperty("Price");

            PropertyValidator.ValidateReadWrite(prop, "Price", typeof(decimal));
        }
Ejemplo n.º 19
0
        public void Product_NameProperty()
        {
            PropertyInfo prop = type.GetProperty("Name");

            PropertyValidator.ValidateReadWrite(prop, "Name", typeof(string));
        }
Ejemplo n.º 20
0
        public void Person_AgeProperty()
        {
            PropertyInfo prop = type.GetProperty("Age");

            PropertyValidator.ValidateReadWrite(prop, "Age", typeof(int));
        }
Ejemplo n.º 21
0
        public void Person_LastNameProperty()
        {
            PropertyInfo prop = type.GetProperty("LastName");

            PropertyValidator.ValidateReadWrite(prop, "LastName", typeof(string));
        }
Ejemplo n.º 22
0
        public void Company_RevenueProperty()
        {
            PropertyInfo prop = type.GetProperty("Revenue");

            PropertyValidator.ValidateReadWrite(prop, "Revenue", typeof(decimal));
        }
Ejemplo n.º 23
0
        public void Company_NumberOfEmployeesProperty()
        {
            PropertyInfo prop = type.GetProperty("NumberOfEmployees");

            PropertyValidator.ValidateReadWrite(prop, "NumberOfEmployees", typeof(int));
        }
Ejemplo n.º 24
0
        public void Company_ExpensesProperty()
        {
            PropertyInfo prop = type.GetProperty("Expenses");

            PropertyValidator.ValidateReadWrite(prop, "Expenses", typeof(decimal));
        }