public void IamAnyMood_Returns_HAPPY_usingCtor() { MoodAnalyserClass ma = new MoodAnalyser.MoodAnalyserClass("I am in any mood"); string result = ma.CheckMood(); Assert.AreEqual(result, "HAPPY"); }
public void IamSadMood_Returns_SAD_usingCtor() { MoodAnalyserClass ma = new MoodAnalyser.MoodAnalyserClass("I am in sad mood"); string result = ma.CheckMood(); Assert.AreEqual(result, "SAD"); }
public void IAminAnyMood_Returns_HAPPY_TC2() { string message = "I am in any mood"; MoodAnalyserClass ma = new MoodAnalyser.MoodAnalyserClass(message); string result = ma.CheckMood(); Assert.AreEqual(result, "HAPPY"); }
public void IAmSadMood_Returns_SAD_TC1() { string message = "I am in sad mood"; MoodAnalyserClass ma = new MoodAnalyser.MoodAnalyserClass(message); string result = ma.CheckMood(); Assert.AreEqual(result, "SAD"); }
public void NullEntry_Returns_CustomeException_with_NullErrorMessage() { try { MoodAnalyserClass ma = new MoodAnalyser.MoodAnalyserClass(null); string result = ma.CheckMood(); } catch (MoodAnalyserCustomException e) { Assert.AreEqual("Mood should not be Null", e.Message); } }
static void Main(string[] args) { try { string mood = string.Empty; MoodAnalyserClass moodAnalyser = new MoodAnalyserClass(mood); string result = moodAnalyser.AnalyseMood(); Console.WriteLine(result); } catch (MoodAnalysisException m) { Console.WriteLine(m.Message); } }
//UC7 public static string SetField(string message, string fieldName) { try { MoodAnalyserClass moodAnalyserClass = new MoodAnalyserClass(); Type type = typeof(MoodAnalyserClass); FieldInfo field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance); if (message == null) { throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NULL_MESSAGE, "Message should not be null"); } field.SetValue(moodAnalyserClass, message); return(moodAnalyserClass.message); } catch (NullReferenceException) { throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NO_SUCH_FIELD, "No field found"); } }
public static string SetField(string message, string fieldName) { try { MoodAnalyserClass moodAnalyser = new MoodAnalyserClass(); Type type = Type.GetType("MoodAnalyser.MoodAnalyserClass"); 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"); } }
public static string SetField(string message, string fieldName) { try { MoodAnalyserClass moodAnalyzer = new MoodAnalyserClass(); Type type = typeof(MoodAnalyserClass); FieldInfo fieldInfo = type.GetField(fieldName); if (message == null) { throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.ENTERED_NULL, "Mood should not be NULL"); } fieldInfo.SetValue(moodAnalyzer, message); return(moodAnalyzer.message); } catch (NullReferenceException) { throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.FIELD_NOT_FOUND, "Field is not found"); } }
/// <summary> /// Gets the field for mood analysis. /// </summary> /// <param name="message">The message.</param> /// <param name="fieldName">Name of the field.</param> /// <returns></returns> /// <exception cref="MoodAnalyserCustomException"> /// null value found. /// or /// field not found /// </exception> public static object GetFieldForMoodAnalysis(string message, string fieldName) { try { //creation of object of mood analyser class. MoodAnalyserClass moodAnalyserClass = new MoodAnalyserClass(); //gets the type of mood analyser class. Type type = typeof(MoodAnalyserClass); //field name is passed in type and if that field exists, it is saved in fieldinfo. FieldInfo fieldInfo = type.GetField(fieldName); if (message == null) { throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NULL_MESSAGE, "null value found."); } //field info is set with value by passing object and value fieldInfo.SetValue(moodAnalyserClass, message); //class is returned with field value initialized return(moodAnalyserClass); } catch (NullReferenceException) { throw new MoodAnalyserCustomException(MoodAnalyserCustomException.ExceptionType.NO_SUCH_FIELD, "field not found"); } }