/// <summary> /// Implements the mock variable. /// </summary> /// <param name="instance">The instance.</param> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="mockVariableDeclaration">The mock variable declaration.</param> /// <returns>The code variable.</returns> public static CodeVariable ImplementMockVariable( this CodeClass instance, string name, string type, string mockVariableDeclaration) { TraceService.WriteLine("CodeClassExtensions::ImplementMockVariable file=" + instance.Name); CodeVariable codeVariable = instance.AddVariable(name, type, 0, vsCMAccess.vsCMAccessPrivate, 0); string typeDescriptor = name.Substring(4, 1).ToUpper() + name.Substring(5); codeVariable.DocComment = "<doc><summary>\r\nMock " + typeDescriptor + ".\r\n</summary></doc>"; EditPoint startPoint = codeVariable.StartPoint.CreateEditPoint(); EditPoint endPoint = codeVariable.EndPoint.CreateEditPoint(); //// if we are Moq then we change the variable declaration. if (string.IsNullOrEmpty(mockVariableDeclaration) == false) { string substitution = mockVariableDeclaration.Replace("%TYPE%", type); string text = startPoint.GetText(endPoint); string newText = text.Replace("private " + type, "private " + substitution); startPoint.ReplaceText(endPoint, newText, 0); } // get the new endpoint before inserting new line. endPoint = codeVariable.EndPoint.CreateEditPoint(); endPoint.InsertNewLine(); return(codeVariable); }
/// <summary> /// Implements the mock variable. /// </summary> /// <param name="instance">The instance.</param> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <returns>The code variable.</returns> public static CodeVariable ImplementMockVariable( this CodeClass instance, string name, string type) { TraceService.WriteLine("CodeClassExtensions::ImplementMockVariable file=" + instance.Name); CodeVariable codeVariable = instance.AddVariable(name, type, 0, vsCMAccess.vsCMAccessPrivate, 0); string typeDescriptor = name.Substring(4, 1).ToUpper() + name.Substring(5); codeVariable.DocComment = "<doc><summary>\r\nMock " + typeDescriptor + ".\r\n</summary></doc>"; EditPoint startPoint = codeVariable.StartPoint.CreateEditPoint(); EditPoint endPoint = codeVariable.EndPoint.CreateEditPoint(); string text = startPoint.GetText(endPoint); string newText = text.Replace(type, "Mock<" + type + ">"); startPoint.ReplaceText(endPoint, newText, 0); // get the new endpoint before inserting new line. endPoint = codeVariable.EndPoint.CreateEditPoint(); endPoint.InsertNewLine(); return(codeVariable); }