示例#1
0
 public void AddMethod(string name, NewMethodInfo method)
 {
     if (_methods.Keys.Contains(name))
         _methods[name] = method;
     else
         _methods.Add(name, method);
 }
示例#2
0
 public void AddMethod(string name, NewMethodInfo method)
 {
     if (_methods.Keys.Contains(name))
     {
         _methods[name] = method;
     }
     else
     {
         _methods.Add(name, method);
     }
 }
示例#3
0
        public void ReplaceMethod(string fileName, string methodName, NewMethodInfo newMethodInfo)
        {
            ConstructedFile file;

            if (_files.Where(cf => cf.FileName == fileName).Count() != 0)
            {
                file = _files.Where(cf => cf.FileName == fileName).First();
            }
            else
            {
                file = new ConstructedFile(fileName);
            }

            file.AddMethod(methodName, newMethodInfo);
        }
示例#4
0
        public void ApplyChanges()
        {
            string[] files = Directory.GetFiles(this.DestinationFolder, "*" + this.FileName, SearchOption.AllDirectories);

            if (files.Count() > 0)
            {
                string filePath = files.FirstOrDefault();
                string fileText = File.ReadAllText(filePath);

                foreach (string methodName in _methods.Keys)
                {
                    NewMethodInfo methodSig = _methods[methodName];

                    int startPos = fileText.IndexOf(methodSig.MethodSignature);
                    if (startPos == -1)
                    {
                        throw new TestFailedException(String.Format("Could not find method body to replace. file: {0}, method: {1}", this.FileName, methodName));
                    }

                    startPos = fileText.IndexOf("{", startPos + 1) + 1;

                    int endPos = fileText.IndexOf("// " + methodName);
                    if (endPos == -1)
                    {
                        endPos = fileText.IndexOf("//" + methodName); // try without space
                    }
                    if (endPos == -1)
                    {
                        throw new TestFailedException(String.Format("Could not find method body to replace. file: {0}, method: {1}", this.FileName, methodName));
                    }

                    endPos = fileText.LastIndexOf("}", endPos, endPos - startPos) - 1;

                    fileText = fileText.Substring(0, startPos) + "\r\n" + methodSig.BodyText + "\r\n" + fileText.Substring(endPos);
                }

                File.WriteAllText(filePath, fileText);
            }
        }
示例#5
0
        public void ReplaceMethod(string fileName, string methodName, NewMethodInfo newMethodInfo)
        {
            ConstructedFile file;

            if (_files.Where(cf => cf.FileName == fileName).Count() != 0)
                file = _files.Where(cf => cf.FileName == fileName).First();
            else
                file = new ConstructedFile(fileName);

            file.AddMethod(methodName, newMethodInfo);
        }