/// <summary> /// Generates a Unit Test for a Class /// </summary> /// <param name="unitTestCodeClass">Unit Test Class's Code Function. A shell will suffice</param> /// <param name="codeElement">Class's Code Function or Code Property</param> /// <param name="originalCodeClass">The class from which we have chosen our codeElement</param> /// <returns>A CodeClass representation the newly generated class</returns> public virtual CodeClass GenerateTest(CodeClass unitTestCodeClass, CodeClass originalCodeClass, CodeElement codeElement) { if (codeElement is CodeFunction || codeElement is CodeProperty) { string unitTestString = string.Empty; unitTestCodeClass.Comment = originalCodeClass.Comment; unitTestCodeClass.DocComment = originalCodeClass.DocComment; foreach (CodeElement ce in originalCodeClass.Members) { if (ce == codeElement) { if (ce is CodeFunction && ((CodeFunction)ce).Access == vsCMAccess.vsCMAccessPublic) { GenerateTest(unitTestCodeClass, (CodeFunction)ce); } else if (ce is CodeProperty && ((CodeProperty)ce).Access == vsCMAccess.vsCMAccessPublic) { GenerateTest(unitTestCodeClass, (CodeProperty)ce); } } } return unitTestCodeClass; } else throw new Exception(string.Format(UTGHelper.CommonErrors.ERR_TYPE_NOT_SUPPORTED, codeElement.GetType().ToString())); }
/// <summary> /// Generates a Unit Test for a Class /// </summary> /// <param name="unitTestCodeClass">Unit Test Class's Code Function. A shell will suffice</param> /// <param name="codeElement">Class's Code Function or Code Property</param> /// <param name="originalCodeClass">The class from which we have chosen our codeElement</param> /// <returns>A CodeClass representation the newly generated class</returns> public virtual CodeClass GenerateTest(CodeClass unitTestCodeClass, CodeClass originalCodeClass, CodeElement codeElement) { if (codeElement is CodeFunction || codeElement is CodeProperty) { string unitTestString = string.Empty; unitTestCodeClass.Comment = originalCodeClass.Comment; unitTestCodeClass.DocComment = originalCodeClass.DocComment; foreach (CodeElement ce in originalCodeClass.Members) { if (ce == codeElement) { if (ce is CodeFunction && ((CodeFunction)ce).Access == vsCMAccess.vsCMAccessPublic) { GenerateTest(unitTestCodeClass, (CodeFunction)ce); } else if (ce is CodeProperty && ((CodeProperty)ce).Access == vsCMAccess.vsCMAccessPublic) { GenerateTest(unitTestCodeClass, (CodeProperty)ce); } } } return(unitTestCodeClass); } else { throw new Exception(string.Format(UTGHelper.CommonErrors.ERR_TYPE_NOT_SUPPORTED, codeElement.GetType().ToString())); } }