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"); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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"); }
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"); }
public void Product_WeightProperty() { PropertyInfo prop = type.GetProperty("WeightInOunces"); PropertyValidator.ValidateReadWrite(prop, "WeightInOunces", typeof(double)); }
public void Product_PriceProperty() { PropertyInfo prop = type.GetProperty("Price"); PropertyValidator.ValidateReadWrite(prop, "Price", typeof(decimal)); }
public void Product_NameProperty() { PropertyInfo prop = type.GetProperty("Name"); PropertyValidator.ValidateReadWrite(prop, "Name", typeof(string)); }
public void Person_AgeProperty() { PropertyInfo prop = type.GetProperty("Age"); PropertyValidator.ValidateReadWrite(prop, "Age", typeof(int)); }
public void Person_LastNameProperty() { PropertyInfo prop = type.GetProperty("LastName"); PropertyValidator.ValidateReadWrite(prop, "LastName", typeof(string)); }
public void Company_RevenueProperty() { PropertyInfo prop = type.GetProperty("Revenue"); PropertyValidator.ValidateReadWrite(prop, "Revenue", typeof(decimal)); }
public void Company_NumberOfEmployeesProperty() { PropertyInfo prop = type.GetProperty("NumberOfEmployees"); PropertyValidator.ValidateReadWrite(prop, "NumberOfEmployees", typeof(int)); }
public void Company_ExpensesProperty() { PropertyInfo prop = type.GetProperty("Expenses"); PropertyValidator.ValidateReadWrite(prop, "Expenses", typeof(decimal)); }