public void checkForParamterisedConstructor() { MoodAnalyzer mod = new MoodAnalyzer("i am in sad mood"); //create mood analyser reflection object analyser moodAnalyserReflector <MoodAnalyzer> analyser = new moodAnalyserReflector <MoodAnalyzer>(); //call the parameterised constructor //return the constructor information to the return object ConstructorInfo returnObject = analyser.ParameteriseConstructor(1); //send return object as argument to create mood analuser object constructor = analyser.creteMoodAnalyser(returnObject, "MoodAnalyzer", "i am in sad mood"); //object provided as an actual value is an instance of the expected type at that time we use isinstanceof Assert.IsInstanceOf(typeof(MoodAnalyzer), constructor); }
public void checkForMethodNotFoundForParameterisedConstructor() { try { //create mood analyser reflection object analyser moodAnalyserReflector <MoodAnalyzer> analyser = new moodAnalyserReflector <MoodAnalyzer>(); //call the default constructor //return the constructor information to the return object ConstructorInfo returnObject = analyser.ParameteriseConstructor(1); //send null ass ConstructorInfo and throws exception catch in catch block ConstructorInfo mood = null; object constructor = analyser.creteMoodAnalyser(mood, "MoodAnalyzer", "i am in sad mood"); } catch (Exception e) { //exception massage same ass "method not found" then pass the test Assert.AreEqual("method not found", e.Message); } }
public void checkForClassNotFoundForParameterisedConstructor() { try { //create mood analyser reflection object analyser moodAnalyserReflector <MoodAnalyzer> analyser = new moodAnalyserReflector <MoodAnalyzer>(); //call the default constructor //return the constructor information to the return object ConstructorInfo returnObject = analyser.ParameteriseConstructor(1); // send wrong class as argumet then throws exception and catch in catch block object constructor = analyser.creteMoodAnalyser(returnObject, "mood", "i am in sad mood"); } catch (Exception e) { //exception massage same ass class not found then pass the test Assert.AreEqual("class not found", e.Message); } }