Пример #1
0
 public void GivenNullMoodShouldThrowMoodAnalysisException()
 {
     try
     {
         string      message     = null;
         MoodAnalyse moodAnalyse = new MoodAnalyse(message);
         string      mood        = moodAnalyse.analyseMood();
     }
     catch (MoodAnalyzerCustomException e)
     {
         Assert.AreEqual("Mood should not be null", e.Message);
     }
 }
Пример #2
0
 static void Main(string[] args)
 {
     try
     {
         string      mood         = Console.ReadLine();
         MoodAnalyse moodAnalyser = new MoodAnalyse(mood);
         string      res          = moodAnalyser.AnalyseMood();
         Console.WriteLine(res);
     }
     catch (MoodAnalysisException m)
     {
         Console.WriteLine(m.Message);
     }
 }
 public static string SetField(string message, string fieldName)
 {
     try
     {
         MoodAnalyse moodAnalyser = new MoodAnalyse();
         Type        type         = Type.GetType("MoodAnalyser.MoodAnalyse");
         FieldInfo   fieldInfo    = type.GetField(fieldName);
         if (message == null)
         {
             throw new MoodAnalysisException(MoodAnalysisException.ExceptionType.EMPTY_MESSAGE, "message should not be null");
         }
         fieldInfo.SetValue(moodAnalyser, message);
         return(moodAnalyser.message);
     }
     catch (NullReferenceException)
     {
         throw new MoodAnalysisException(MoodAnalysisException.ExceptionType.NO_SUCH_FIELD, "no such field found");
     }
 }
Пример #4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcom to Mood Analyser");

            // Ask the user to enter his mood
            Console.WriteLine("Enter the state of mood");
            string message = Console.ReadLine();

            // Call AnalyseMood method to check for mood
            MoodAnalyse moodAnalyse = new MoodAnalyse(message);
            string      mood        = moodAnalyse.AnalyseMood();

            // Creating parameterless MoodAnalyser object at run time
            MoodAnalyserReflector.CreateMoodAnalyserObject("MoodAnalyse", "MoodAnalyse", null);

            // Creating parameterized MoodAnalyser object at run time
            MoodAnalyserReflector.CreateMoodAnalyserObject("MoodAnalyse", "MoodAnalyse", "Happy");

            // Invoking Method using reflections
            MoodAnalyserReflector.InvokeMethod("Happy", "AnalyseMood");

            // Giving the message using field in reflection dynamically
            MoodAnalyserReflector.ChangeMoodDynamically("Sad", "message");
        }