117 changed files with 4690 additions and 152 deletions
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpCompletionBinding : DefaultCodeCompletionBinding |
||||
{ |
||||
public RazorCSharpCompletionBinding() |
||||
{ |
||||
} |
||||
|
||||
public override CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) |
||||
{ |
||||
if (ch == '.') { |
||||
new RazorCSharpDotCompletionDataProvider().ShowCompletion(editor); |
||||
return CodeCompletionKeyPressResult.Completed; |
||||
} else if (ch == '(') { |
||||
return base.HandleKeyPress(editor, ch); |
||||
} |
||||
return CodeCompletionKeyPressResult.None; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpDotCompletionDataProvider : DotCodeCompletionItemProvider |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpExpressionFinder : IExpressionFinder |
||||
{ |
||||
public RazorCSharpExpressionFinder() |
||||
{ |
||||
} |
||||
|
||||
public ExpressionResult FindExpression(string text, int offset) |
||||
{ |
||||
int position = offset - 1; |
||||
while (position > 0 && IsValidCharacter(text[position])) { |
||||
position--; |
||||
} |
||||
position++; |
||||
string expression = text.Substring(position, offset - position); |
||||
return new ExpressionResult(expression); |
||||
} |
||||
|
||||
bool IsValidCharacter(char ch) |
||||
{ |
||||
return Char.IsLetterOrDigit(ch) || |
||||
(ch == '.') || |
||||
(ch == '_'); |
||||
} |
||||
|
||||
public ExpressionResult FindFullExpression(string text, int offset) |
||||
{ |
||||
return ExpressionResult.Empty; |
||||
} |
||||
|
||||
public string RemoveLastPart(string expression) |
||||
{ |
||||
return expression; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Web.Razor; |
||||
using ICSharpCode.SharpDevelop; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpModelTypeLocater |
||||
{ |
||||
public RazorCSharpModelTypeLocater(ITextBuffer textBuffer) |
||||
{ |
||||
ParserResults results = ParseTemplate(textBuffer); |
||||
ModelTypeName = GetModelTypeName(results); |
||||
} |
||||
|
||||
ParserResults ParseTemplate(ITextBuffer textBuffer) |
||||
{ |
||||
var host = new RazorEngineHost(new CSharpRazorCodeLanguage()); |
||||
var engine = new RazorTemplateEngine(host); |
||||
return engine.ParseTemplate(textBuffer.CreateReader()); |
||||
} |
||||
|
||||
string GetModelTypeName(ParserResults results) |
||||
{ |
||||
var visitor = new RazorCSharpParserModelTypeVisitor(); |
||||
results.Document.Accept(visitor); |
||||
return visitor.ModelTypeName; |
||||
} |
||||
|
||||
public string ModelTypeName { get; private set; } |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.CSharp; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpParser : IParser |
||||
{ |
||||
public RazorCSharpParser() |
||||
{ |
||||
} |
||||
|
||||
public string[] LexerTags { get; set; } |
||||
|
||||
public LanguageProperties Language { |
||||
get { return LanguageProperties.CSharp; } |
||||
} |
||||
|
||||
public IExpressionFinder CreateExpressionFinder(string fileName) |
||||
{ |
||||
return new RazorCSharpExpressionFinder(); |
||||
} |
||||
|
||||
public bool CanParse(string fileName) |
||||
{ |
||||
return Path.GetExtension(fileName).Equals(".cshtml", StringComparison.OrdinalIgnoreCase); |
||||
} |
||||
|
||||
public bool CanParse(IProject project) |
||||
{ |
||||
return project.Language == "C#"; |
||||
} |
||||
|
||||
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent) |
||||
{ |
||||
var modelTypeLocater = new RazorCSharpModelTypeLocater(fileContent); |
||||
return new RazorCompilationUnit(projectContent) { |
||||
ModelTypeName = modelTypeLocater.ModelTypeName |
||||
}; |
||||
} |
||||
|
||||
public IResolver CreateResolver() |
||||
{ |
||||
return new RazorCSharpResolver(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Web.Razor.Parser; |
||||
using System.Web.Razor.Parser.SyntaxTree; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpParserModelTypeVisitor : ParserVisitor |
||||
{ |
||||
bool foundModelTypeName; |
||||
|
||||
public RazorCSharpParserModelTypeVisitor() |
||||
{ |
||||
ModelTypeName = String.Empty; |
||||
} |
||||
|
||||
public string ModelTypeName { get; private set; } |
||||
|
||||
public override void VisitSpan(Span span) |
||||
{ |
||||
Console.WriteLine("Span.Kind: " + span.Kind); |
||||
Console.WriteLine("Span.GetType(): " + span.GetType().Name); |
||||
Console.WriteLine("Span.Content: '" + span.Content + "'"); |
||||
|
||||
if (foundModelTypeName) |
||||
return; |
||||
|
||||
if (IsModelSpan(span)) { |
||||
VisitModelNameSpan(span.Next); |
||||
} |
||||
} |
||||
|
||||
bool IsModelSpan(Span span) |
||||
{ |
||||
return span.Content == "model"; |
||||
} |
||||
|
||||
void VisitModelNameSpan(Span span) |
||||
{ |
||||
if (span == null) |
||||
return; |
||||
|
||||
string firstLineOfMarkup = GetFirstLine(span.Content); |
||||
ModelTypeName = firstLineOfMarkup.Trim(); |
||||
foundModelTypeName = true; |
||||
} |
||||
|
||||
string GetFirstLine(string text) |
||||
{ |
||||
int endOfLineIndex = text.IndexOf('\r'); |
||||
if (endOfLineIndex > 0) { |
||||
return text.Substring(0, endOfLineIndex); |
||||
} |
||||
return text; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCSharpResolver : IResolver |
||||
{ |
||||
NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.CSharp); |
||||
|
||||
public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) |
||||
{ |
||||
ParseInformation parseInfoWithWebViewPageClass = CreateParseInformationWithWebViewPageClass(parseInfo); |
||||
expressionResult.Region = GetRegionInMiddleOfWebViewPageClass(); |
||||
return resolver.Resolve(expressionResult, parseInfoWithWebViewPageClass, fileContent); |
||||
} |
||||
|
||||
ParseInformation CreateParseInformationWithWebViewPageClass(ParseInformation parseInfo) |
||||
{ |
||||
RazorCompilationUnit compilationUnit = RazorCompilationUnit.CreateFromParseInfo(parseInfo); |
||||
AddDefaultUsings(compilationUnit); |
||||
AddWebViewPageClass(compilationUnit); |
||||
return new ParseInformation(compilationUnit); |
||||
} |
||||
|
||||
void AddDefaultUsings(ICompilationUnit compilationUnit) |
||||
{ |
||||
AddUsing("System.Web.Mvc", compilationUnit); |
||||
AddUsing("System.Web.Mvc.Ajax", compilationUnit); |
||||
AddUsing("System.Web.Mvc.Html", compilationUnit); |
||||
AddUsing("System.Web.Routing", compilationUnit); |
||||
} |
||||
|
||||
void AddUsing(string name, ICompilationUnit compilationUnit) |
||||
{ |
||||
DefaultUsing defaultUsing = CreateUsing(name, compilationUnit.ProjectContent); |
||||
compilationUnit.UsingScope.Usings.Add(defaultUsing); |
||||
} |
||||
|
||||
DefaultUsing CreateUsing(string namespaceName, IProjectContent projectContent) |
||||
{ |
||||
var defaultUsing = new DefaultUsing(projectContent); |
||||
defaultUsing.Usings.Add(namespaceName); |
||||
return defaultUsing; |
||||
} |
||||
|
||||
void AddWebViewPageClass(RazorCompilationUnit compilationUnit) |
||||
{ |
||||
DefaultClass webViewPageClass = CreateWebViewPageClass(compilationUnit); |
||||
compilationUnit.Classes.Add(webViewPageClass); |
||||
} |
||||
|
||||
DefaultClass CreateWebViewPageClass(RazorCompilationUnit compilationUnit) |
||||
{ |
||||
var webViewPageClass = new DefaultClass(compilationUnit, "RazorWebViewPage") { |
||||
Region = new DomRegion(1, 0, 3, 0) |
||||
}; |
||||
IReturnType modelType = GetModelReturnType(compilationUnit); |
||||
AddWebViewPageBaseClass(webViewPageClass, modelType); |
||||
return webViewPageClass; |
||||
} |
||||
|
||||
IReturnType GetModelReturnType(RazorCompilationUnit compilationUnit) |
||||
{ |
||||
IClass modelType = GetClassIfTypeNameIsNotEmpty(compilationUnit.ProjectContent, compilationUnit.ModelTypeName); |
||||
if (modelType != null) { |
||||
return modelType.DefaultReturnType; |
||||
} |
||||
return new DynamicReturnType(compilationUnit.ProjectContent); |
||||
} |
||||
|
||||
IClass GetClassIfTypeNameIsNotEmpty(IProjectContent projectContent, string modelTypeName) |
||||
{ |
||||
if (!String.IsNullOrEmpty(modelTypeName)) { |
||||
return projectContent.GetClass(modelTypeName, 0); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
void AddWebViewPageBaseClass(DefaultClass webViewPageClass, IReturnType modelType) |
||||
{ |
||||
IClass webViewPageBaseClass = webViewPageClass.ProjectContent.GetClass("System.Web.Mvc.WebViewPage", 1); |
||||
if (webViewPageBaseClass != null) { |
||||
IReturnType returnType = GetWebViewPageBaseClassReturnType(webViewPageBaseClass, modelType); |
||||
webViewPageClass.BaseTypes.Add(returnType); |
||||
} |
||||
} |
||||
|
||||
IReturnType GetWebViewPageBaseClassReturnType(IClass webViewPageBaseClass, IReturnType modelType) |
||||
{ |
||||
var typeArguments = new List<IReturnType>(); |
||||
typeArguments.Add(modelType); |
||||
return new ConstructedReturnType(webViewPageBaseClass.DefaultReturnType, typeArguments); |
||||
} |
||||
|
||||
DomRegion GetRegionInMiddleOfWebViewPageClass() |
||||
{ |
||||
return new DomRegion(2, 0, 2, 0); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.AspNet.Mvc.Completion |
||||
{ |
||||
public class RazorCompilationUnit : DefaultCompilationUnit |
||||
{ |
||||
public RazorCompilationUnit(IProjectContent projectContent) |
||||
: base(projectContent) |
||||
{ |
||||
} |
||||
|
||||
public static RazorCompilationUnit CreateFromParseInfo(ParseInformation parseInformation) |
||||
{ |
||||
return new RazorCompilationUnit(parseInformation.CompilationUnit.ProjectContent) { |
||||
ModelTypeName = GetModelTypeName(parseInformation.CompilationUnit) |
||||
}; |
||||
} |
||||
|
||||
static string GetModelTypeName(ICompilationUnit compilationUnit) |
||||
{ |
||||
var originalRazorCompilationUnit = compilationUnit as RazorCompilationUnit; |
||||
if (originalRazorCompilationUnit != null) { |
||||
return originalRazorCompilationUnit.ModelTypeName; |
||||
} |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string ModelTypeName { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,148 @@
@@ -0,0 +1,148 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.AspNet.Mvc.Completion; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
|
||||
namespace AspNet.Mvc.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class RazorCSharpParserTests |
||||
{ |
||||
RazorCSharpParser parser; |
||||
|
||||
void CreateParser() |
||||
{ |
||||
parser = new RazorCSharpParser(); |
||||
} |
||||
|
||||
ICompilationUnit Parse(string code) |
||||
{ |
||||
var projectContent = new DefaultProjectContent(); |
||||
var textBuffer = new StringTextBuffer(code); |
||||
return parser.Parse(projectContent, @"d:\MyProject\Views\Index.cshtml", textBuffer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_ModelDirectiveWithTypeName_ModelTypeNameFound() |
||||
{ |
||||
CreateParser(); |
||||
string code = "@model MvcApplication.MyModel\r\n"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual("MvcApplication.MyModel", compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_ModelDirectiveWithTypeNameFollowedByHtmlMarkup_ModelTypeNameFound() |
||||
{ |
||||
CreateParser(); |
||||
string code = |
||||
"@model MvcApplication.LogonModel\r\n" + |
||||
"<h2>Index</h2>\r\n"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual("MvcApplication.LogonModel", compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_SingleLineFileWithModelDirectiveAndTypeNameButNoNewLineAtEnd_ModelTypeNameFound() |
||||
{ |
||||
CreateParser(); |
||||
string code = "@model MvcApplication.MyModel"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual("MvcApplication.MyModel", compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_ModelTypeDirectiveWithTypeNameFollowedByRazorBlock_ModelTypeNameFound() |
||||
{ |
||||
CreateParser(); |
||||
|
||||
string code = |
||||
"@model IEnumerable<MvcApplication1.Models.MyClass>\r\n" + |
||||
"\r\n" + |
||||
"@{\r\n" + |
||||
" ViewBag.Title = \"Title1\";\r\n" + |
||||
"}\r\n" + |
||||
"\r\n"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual("IEnumerable<MvcApplication1.Models.MyClass>", compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_UsingDirective_ModelTypeNameIsEmptyString() |
||||
{ |
||||
CreateParser(); |
||||
string code = "@using System.Xml\r\n"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual(String.Empty, compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_HelperDirective_ModelTypeNameIsEmptyString() |
||||
{ |
||||
CreateParser(); |
||||
string code = "@helper MyHelper\r\n"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual(String.Empty, compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_HtmlMarkupOnly_ModelTypeNameIsEmptyString() |
||||
{ |
||||
CreateParser(); |
||||
string code = "<h1>heading</h1>\r\n"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual(String.Empty, compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_ModelDirectiveOnly_ModelTypeNameIsEmptyString() |
||||
{ |
||||
CreateParser(); |
||||
string code = "@model"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual(String.Empty, compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_ModelStringInsideParagraphTags_ModelTypeNameIsEmptyString() |
||||
{ |
||||
CreateParser(); |
||||
string code = "<p>model</p>"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual(String.Empty, compilationUnit.ModelTypeName); |
||||
} |
||||
|
||||
[Test] |
||||
public void Parse_ModelStringOnlyWithoutRazorTransition_ModelTypeNameIsEmptyString() |
||||
{ |
||||
CreateParser(); |
||||
string code = "model"; |
||||
|
||||
var compilationUnit = Parse(code) as RazorCompilationUnit; |
||||
|
||||
Assert.AreEqual(String.Empty, compilationUnit.ModelTypeName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ClassKindUpdater : IClassKindUpdater |
||||
{ |
||||
public ClassKindUpdater(IClass c) |
||||
: this(c, new DocumentLoader()) |
||||
{ |
||||
} |
||||
|
||||
public ClassKindUpdater(IClass c, IDocumentLoader documentLoader) |
||||
{ |
||||
this.Class = c; |
||||
this.DocumentLoader = documentLoader; |
||||
} |
||||
|
||||
IClass Class { get; set; } |
||||
IDocumentLoader DocumentLoader { get; set; } |
||||
IRefactoringDocument Document { get; set; } |
||||
|
||||
public void MakeClassPartial() |
||||
{ |
||||
if (Class.IsPartial) |
||||
return; |
||||
|
||||
OpenFileContainingClass(); |
||||
int offset = GetPartialKeywordInsertOffset(); |
||||
InsertPartialKeyword(offset); |
||||
} |
||||
|
||||
void OpenFileContainingClass() |
||||
{ |
||||
Document = DocumentLoader.LoadRefactoringDocument(Class.CompilationUnit.FileName); |
||||
} |
||||
|
||||
int GetPartialKeywordInsertOffset() |
||||
{ |
||||
IRefactoringDocumentLine line = Document.GetLine(Class.Region.BeginLine); |
||||
int offset = line.Text.IndexOf(" class", StringComparison.OrdinalIgnoreCase); |
||||
if (offset >= 0) { |
||||
return offset + line.Offset + 1; |
||||
} |
||||
throw new ApplicationException("Unable to find 'class' declaration."); |
||||
} |
||||
|
||||
void InsertPartialKeyword(int offset) |
||||
{ |
||||
string partialKeyword = GetLanguageSpecificPartialKeyword(); |
||||
Document.Insert(offset, partialKeyword + " "); |
||||
} |
||||
|
||||
string GetLanguageSpecificPartialKeyword() |
||||
{ |
||||
if (Class.ProjectContent.Language == LanguageProperties.VBNet) { |
||||
return "Partial"; |
||||
} |
||||
return "partial"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public class CodeFunction2 : CodeFunction |
||||
{ |
||||
public CodeFunction2(IMethod method) |
||||
: base(method) |
||||
{ |
||||
} |
||||
|
||||
public virtual bool IsGeneric { |
||||
get { return Method.HasTypeParameters(); } |
||||
} |
||||
|
||||
public virtual vsCMOverrideKind OverrideKind { |
||||
get { return GetOverrideKind(); } |
||||
} |
||||
|
||||
vsCMOverrideKind GetOverrideKind() |
||||
{ |
||||
if (Method.IsAbstract) { |
||||
return vsCMOverrideKind.vsCMOverrideKindAbstract; |
||||
} else if (Method.IsVirtual) { |
||||
return vsCMOverrideKind.vsCMOverrideKindVirtual; |
||||
} else if (Method.IsOverride) { |
||||
return vsCMOverrideKind.vsCMOverrideKindOverride; |
||||
} else if (Method.IsSealed) { |
||||
return vsCMOverrideKind.vsCMOverrideKindSealed; |
||||
} else if (Method.IsNew) { |
||||
return vsCMOverrideKind.vsCMOverrideKindNew; |
||||
} |
||||
return vsCMOverrideKind.vsCMOverrideKindNone; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public class CodeParameter2 : CodeParameter |
||||
{ |
||||
public CodeParameter2(IProjectContent projectContent, IParameter parameter) |
||||
: base(projectContent, parameter) |
||||
{ |
||||
} |
||||
|
||||
public virtual vsCMParameterKind ParameterKind { |
||||
get { return GetParameterKind(); } |
||||
} |
||||
|
||||
vsCMParameterKind GetParameterKind() |
||||
{ |
||||
if (Parameter.IsOptional) { |
||||
return vsCMParameterKind.vsCMParameterKindOptional; |
||||
} else if (Parameter.IsOut) { |
||||
return vsCMParameterKind.vsCMParameterKindOut; |
||||
} else if (Parameter.IsRef) { |
||||
return vsCMParameterKind.vsCMParameterKindRef; |
||||
} else if (Parameter.IsParams) { |
||||
return vsCMParameterKind.vsCMParameterKindParamArray; |
||||
} else if (Parameter.IsIn()) { |
||||
return vsCMParameterKind.vsCMParameterKindIn; |
||||
} |
||||
return vsCMParameterKind.vsCMParameterKindNone; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public class Document : MarshalByRefObject |
||||
{ |
||||
IViewContent view; |
||||
|
||||
public Document(string fileName, IViewContent view) |
||||
{ |
||||
this.FullName = fileName; |
||||
this.view = view; |
||||
} |
||||
|
||||
public virtual bool Saved { |
||||
get { return !view.IsDirty; } |
||||
set { view.PrimaryFile.IsDirty = !value; } |
||||
} |
||||
|
||||
public string FullName { get; private set; } |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public abstract class EnumerableProjectItems : MarshalByRefObject, IEnumerable<ProjectItem> |
||||
{ |
||||
public EnumerableProjectItems() |
||||
{ |
||||
} |
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return GetEnumerator(); |
||||
} |
||||
|
||||
public IEnumerator<ProjectItem> GetEnumerator() |
||||
{ |
||||
return GetProjectItems().ToList().GetEnumerator(); |
||||
} |
||||
|
||||
protected abstract IEnumerable<ProjectItem> GetProjectItems(); |
||||
|
||||
internal virtual int Count { |
||||
get { return GetProjectItems().Count(); } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
/// <summary>
|
||||
/// File code model namespaces take the full name of the namespace that a class
|
||||
/// is inside. So for the FileCodeModelNamespace class the CodeNamespace.Name
|
||||
/// would be ICSharpCode.PackageManagement.EnvDTE.
|
||||
/// This differs from the CodeModel CodeNamespace which breaks up the namespaces into
|
||||
/// parts.
|
||||
/// </summary>
|
||||
public class FileCodeModelCodeNamespace : CodeNamespace |
||||
{ |
||||
FileCodeModelCodeNamespaceMembers members = new FileCodeModelCodeNamespaceMembers(); |
||||
|
||||
public FileCodeModelCodeNamespace(IProjectContent projectContent, string namespaceName) |
||||
: base(projectContent, namespaceName) |
||||
{ |
||||
} |
||||
|
||||
public override string Name { |
||||
get { return base.FullName; } |
||||
} |
||||
|
||||
public override CodeElements Members { |
||||
get { return members; } |
||||
} |
||||
|
||||
public void AddClass(IProjectContent projectContent, IClass c) |
||||
{ |
||||
members.AddClass(projectContent, c); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public class FileCodeModelCodeNamespaceMembers : CodeElementsList |
||||
{ |
||||
public FileCodeModelCodeNamespaceMembers() |
||||
{ |
||||
} |
||||
|
||||
public void AddClass(IProjectContent projectContent, IClass c) |
||||
{ |
||||
var codeClass = new CodeClass2(projectContent, c); |
||||
AddCodeElement(codeClass); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public static class FileProjectItemExtensions |
||||
{ |
||||
public static bool IsDependentUponAnotherFile(this FileProjectItem projectItem) |
||||
{ |
||||
return !String.IsNullOrEmpty(projectItem.DependentUpon); |
||||
} |
||||
|
||||
public static bool IsDependentUpon(this FileProjectItem projectItem, FileProjectItem otherProjectItem) |
||||
{ |
||||
return projectItem.DependentUpon == otherProjectItem.Include; |
||||
} |
||||
|
||||
public static bool IsDependentUponFileName(this FileProjectItem projectItem, string fileName) |
||||
{ |
||||
return FileUtility.IsEqualFileName(projectItem.GetDependentUponFileName(), fileName); |
||||
} |
||||
|
||||
public static string GetDependentUponFileName(this FileProjectItem projectItem) |
||||
{ |
||||
string directory = Path.GetDirectoryName(projectItem.FileName); |
||||
return Path.Combine(directory, projectItem.DependentUpon); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using SD = ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
/// <summary>
|
||||
/// A file can have child project items if it has files that depend upon it.
|
||||
/// For example, winform designer files (MainForm.Designer.cs)
|
||||
/// </summary>
|
||||
public class FileProjectItems : ProjectItems |
||||
{ |
||||
ProjectItem projectItem; |
||||
IPackageManagementFileService fileService; |
||||
|
||||
public FileProjectItems(ProjectItem projectItem) |
||||
: this(projectItem, new PackageManagementFileService()) |
||||
{ |
||||
} |
||||
|
||||
public FileProjectItems(ProjectItem projectItem, IPackageManagementFileService fileService) |
||||
: base(projectItem.ContainingProject, projectItem, fileService) |
||||
{ |
||||
this.projectItem = projectItem; |
||||
this.fileService = fileService; |
||||
} |
||||
|
||||
protected override IEnumerable<ProjectItem> GetProjectItems() |
||||
{ |
||||
return GetChildDependentProjectItems().ToList(); |
||||
} |
||||
|
||||
IEnumerable<ProjectItem> GetChildDependentProjectItems() |
||||
{ |
||||
foreach (SD.FileProjectItem fileProjectItem in GetFileProjectItems()) { |
||||
if (fileProjectItem.IsDependentUpon(projectItem.MSBuildProjectItem)) { |
||||
yield return new ProjectItem(Project, fileProjectItem); |
||||
} |
||||
} |
||||
} |
||||
|
||||
IEnumerable<SD.FileProjectItem> GetFileProjectItems() |
||||
{ |
||||
return Project |
||||
.MSBuildProject |
||||
.Items |
||||
.Where(item => item is SD.FileProjectItem) |
||||
.Select(item => (SD.FileProjectItem)item); |
||||
} |
||||
|
||||
protected override ProjectItem AddFileProjectItemToProject(string fileName) |
||||
{ |
||||
return AddFileProjectItemWithDependent(fileName); |
||||
} |
||||
|
||||
ProjectItem AddFileProjectItemWithDependent(string fileName) |
||||
{ |
||||
return Project.AddFileProjectItemWithDependentUsingFullPath(fileName, projectItem.Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public static class IClassExtensions |
||||
{ |
||||
/// <summary>
|
||||
/// Returns true if the class fully qualified name matches the name or
|
||||
/// any class in the inheritance tree matches the name.
|
||||
/// </summary>
|
||||
public static bool IsDerivedFrom(this IClass c, string typeName) |
||||
{ |
||||
if (c.FullyQualifiedName == typeName) { |
||||
return true; |
||||
} |
||||
|
||||
if (TypeNameMatchesBaseType(c.BaseType, typeName)) { |
||||
return true; |
||||
} |
||||
|
||||
return IsTypeInClassInheritanceTree(c, typeName); |
||||
} |
||||
|
||||
static bool TypeNameMatchesBaseType(IReturnType baseType, string typeName) |
||||
{ |
||||
return |
||||
(baseType != null) && |
||||
(baseType.FullyQualifiedName == typeName); |
||||
} |
||||
|
||||
static bool IsTypeInClassInheritanceTree(IClass c, string typeName) |
||||
{ |
||||
return c |
||||
.ClassInheritanceTreeClassesOnly |
||||
.Any(inheritedClass => inheritedClass.FullyQualifiedName == typeName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public static class IParameterExtensions |
||||
{ |
||||
public static bool IsIn(this IParameter parameter) |
||||
{ |
||||
return (parameter.Modifiers & ParameterModifiers.In) == ParameterModifiers.In; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public class Window : MarshalByRefObject |
||||
{ |
||||
public Window() |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public enum vsCMClassKind |
||||
{ |
||||
vsCMClassKindMainClass = 1, |
||||
vsCMClassKindPartialClass = 4 |
||||
} |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public enum vsCMOverrideKind |
||||
{ |
||||
vsCMOverrideKindNone = 0, |
||||
vsCMOverrideKindAbstract = 1, |
||||
vsCMOverrideKindVirtual = 2, |
||||
vsCMOverrideKindOverride = 4, |
||||
vsCMOverrideKindNew = 8, |
||||
vsCMOverrideKindSealed = 16 |
||||
} |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public enum vsCMParameterKind |
||||
{ |
||||
vsCMParameterKindNone = 0, |
||||
vsCMParameterKindIn = 1, |
||||
vsCMParameterKindRef = 2, |
||||
vsCMParameterKindOut = 4, |
||||
vsCMParameterKindOptional = 8, |
||||
vsCMParameterKindParamArray = 16 |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public enum vsCMTypeRef |
||||
{ |
||||
vsCMTypeRefOther = 0, |
||||
vsCMTypeRefCodeType = 1, |
||||
vsCMTypeRefArray = 2, |
||||
vsCMTypeRefVoid = 3, |
||||
vsCMTypeRefPointer = 4, |
||||
vsCMTypeRefString = 5, |
||||
vsCMTypeRefObject = 6, |
||||
vsCMTypeRefByte = 7, |
||||
vsCMTypeRefChar = 8, |
||||
vsCMTypeRefShort = 9, |
||||
vsCMTypeRefInt = 10, |
||||
vsCMTypeRefLong = 11, |
||||
vsCMTypeRefFloat = 12, |
||||
vsCMTypeRefDouble = 13, |
||||
vsCMTypeRefDecimal = 14, |
||||
vsCMTypeRefBool = 15, |
||||
vsCMTypeRefVariant = 16 |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface IClassKindUpdater |
||||
{ |
||||
void MakeClassPartial(); |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
/// <summary>
|
||||
/// Used to update a method's source code and make the method virtual.
|
||||
/// </summary>
|
||||
public interface IVirtualMethodUpdater |
||||
{ |
||||
void MakeMethodVirtual(); |
||||
} |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class VirtualMethodUpdater : IVirtualMethodUpdater |
||||
{ |
||||
public VirtualMethodUpdater(IMethod method) |
||||
: this(method, new DocumentLoader()) |
||||
{ |
||||
} |
||||
|
||||
public VirtualMethodUpdater(IMethod method, IDocumentLoader documentLoader) |
||||
{ |
||||
this.Method = method; |
||||
this.DocumentLoader = documentLoader; |
||||
} |
||||
|
||||
IMethod Method { get; set; } |
||||
IDocumentLoader DocumentLoader { get; set; } |
||||
IRefactoringDocument Document { get; set; } |
||||
|
||||
public void MakeMethodVirtual() |
||||
{ |
||||
if (Method.IsVirtual) |
||||
return; |
||||
|
||||
OpenFileContainingMethod(); |
||||
int offset = GetVirtualKeywordInsertOffset(); |
||||
InsertVirtualKeyword(offset); |
||||
} |
||||
|
||||
void OpenFileContainingMethod() |
||||
{ |
||||
Document = DocumentLoader.LoadRefactoringDocument(Method.CompilationUnit.FileName); |
||||
} |
||||
|
||||
int GetVirtualKeywordInsertOffset() |
||||
{ |
||||
IRefactoringDocumentLine line = Document.GetLine(Method.Region.BeginLine); |
||||
int offset = line.Text.IndexOf("public ", StringComparison.OrdinalIgnoreCase); |
||||
if (offset >= 0) { |
||||
int publicKeywordLength = 6; |
||||
return offset + line.Offset + publicKeywordLength + 1; |
||||
} |
||||
throw new ApplicationException("Unable to find 'method' declaration."); |
||||
} |
||||
|
||||
void InsertVirtualKeyword(int offset) |
||||
{ |
||||
string virtualKeyword = GetLanguageSpecificVirtualKeyword(); |
||||
Document.Insert(offset, virtualKeyword + " "); |
||||
} |
||||
|
||||
string GetLanguageSpecificVirtualKeyword() |
||||
{ |
||||
if (Method.ProjectContent.Language == LanguageProperties.VBNet) { |
||||
return "Overridable"; |
||||
} |
||||
return "virtual"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
|
||||
namespace Microsoft.VisualStudio.Shell.Interop |
||||
{ |
||||
public class SDTE : DTE |
||||
{ |
||||
public SDTE() |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,165 @@
@@ -0,0 +1,165 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class ClassKindUpdaterTests |
||||
{ |
||||
ClassKindUpdater updater; |
||||
ClassHelper classHelper; |
||||
IRefactoringDocument document; |
||||
IDocumentLoader documentLoader; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
classHelper = new ClassHelper(); |
||||
document = MockRepository.GenerateStub<IRefactoringDocument>(); |
||||
documentLoader = MockRepository.GenerateStub<IDocumentLoader>(); |
||||
} |
||||
|
||||
void CreatePublicCSharpClass() |
||||
{ |
||||
classHelper.CreatePublicClass("MyClass"); |
||||
classHelper.ProjectContentHelper.ProjectContentIsForCSharpProject(); |
||||
} |
||||
|
||||
void CreatePublicVisualBasicClass() |
||||
{ |
||||
classHelper.CreatePublicClass("MyClass"); |
||||
classHelper.ProjectContentHelper.ProjectContentIsForVisualBasicProject(); |
||||
} |
||||
|
||||
void SetDocumentFileName(string fileName) |
||||
{ |
||||
documentLoader.Stub(loader => loader.LoadRefactoringDocument(fileName)).Return(document); |
||||
} |
||||
|
||||
void CreateClassKindUpdater() |
||||
{ |
||||
updater = new ClassKindUpdater(classHelper.Class, documentLoader); |
||||
} |
||||
|
||||
void SetClassFileName(string fileName) |
||||
{ |
||||
classHelper.SetClassFileName(fileName); |
||||
SetDocumentFileName(fileName); |
||||
} |
||||
|
||||
void SetClassDeclarationLineWithOffset(int line, string text, int offset) |
||||
{ |
||||
classHelper.SetRegionBeginLine(line); |
||||
SetDocumentLineText(line, text, offset); |
||||
} |
||||
|
||||
void SetClassDeclarationLine(int line, string text) |
||||
{ |
||||
SetClassDeclarationLineWithOffset(line, text, 0); |
||||
} |
||||
|
||||
void SetDocumentLineText(int lineNumber, string text, int offset) |
||||
{ |
||||
IRefactoringDocumentLine documentLine = MockRepository.GenerateStub<IRefactoringDocumentLine>(); |
||||
documentLine.Stub(line => line.Text).Return(text); |
||||
documentLine.Stub(line => line.Offset).Return(offset); |
||||
document.Stub(doc => doc.GetLine(lineNumber)).Return(documentLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_PublicCSharpClassWithNoOtherModifiers_OpensFileContainingClassInSharpDevelop() |
||||
{ |
||||
CreatePublicCSharpClass(); |
||||
CreateClassKindUpdater(); |
||||
string fileName = @"d:\projects\MyProject\MyClass.cs"; |
||||
SetClassFileName(fileName); |
||||
SetClassDeclarationLine(1, "public class MyClass"); |
||||
|
||||
updater.MakeClassPartial(); |
||||
|
||||
documentLoader.AssertWasCalled(loader => loader.LoadRefactoringDocument(fileName)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_PublicCSharpClassWithNoOtherModifiers_AddsPartialKeywordToClassDefinition() |
||||
{ |
||||
CreatePublicCSharpClass(); |
||||
CreateClassKindUpdater(); |
||||
SetClassFileName(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetClassDeclarationLine(1, "public class MyClass"); |
||||
|
||||
updater.MakeClassPartial(); |
||||
|
||||
document.AssertWasCalled(doc => doc.Insert(7, "partial ")); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_PublicCSharpClassThatIsAlreadyPartial_ClassDefinitionIsUnchanged() |
||||
{ |
||||
CreatePublicCSharpClass(); |
||||
CreateClassKindUpdater(); |
||||
classHelper.MakeClassPartial(); |
||||
SetClassFileName(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetClassDeclarationLine(1, "public class MyClass"); |
||||
|
||||
updater.MakeClassPartial(); |
||||
|
||||
document.AssertWasNotCalled(doc => doc.Insert(Arg<int>.Is.Anything, Arg<string>.Is.Anything)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_PublicVisualBasicClassWithNoOtherModifiers_AddsVisualBasicPartialKeywordToClassDefinition() |
||||
{ |
||||
CreatePublicVisualBasicClass(); |
||||
CreateClassKindUpdater(); |
||||
SetClassFileName(@"d:\projects\MyProject\MyClass.vb"); |
||||
SetClassDeclarationLine(1, "Public Class MyClass"); |
||||
|
||||
updater.MakeClassPartial(); |
||||
|
||||
document.AssertWasCalled(doc => doc.Insert(7, "Partial ")); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_NoClassKeywordInClassDeclarationLine_ExceptionIsThrown() |
||||
{ |
||||
CreatePublicCSharpClass(); |
||||
CreateClassKindUpdater(); |
||||
SetClassFileName(@"d:\projects\MyProject\test.cs"); |
||||
SetClassDeclarationLine(1, "public test"); |
||||
|
||||
Assert.Throws<ApplicationException>(() => updater.MakeClassPartial()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_NoClassKeywordButClassNameIncludesClassKeyword_ExceptionIsThrown() |
||||
{ |
||||
CreatePublicCSharpClass(); |
||||
CreateClassKindUpdater(); |
||||
SetClassFileName(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetClassDeclarationLine(1, "public MyClass"); |
||||
|
||||
Assert.Throws<ApplicationException>(() => updater.MakeClassPartial()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeClassPartial_PublicCSharpClassNotOnFirstLine_AddsPartialKeywordToClassDefinitionAtCorrectOffset() |
||||
{ |
||||
CreatePublicCSharpClass(); |
||||
CreateClassKindUpdater(); |
||||
SetClassFileName(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetClassDeclarationLineWithOffset(1, "public class MyClass", offset: 10); |
||||
|
||||
updater.MakeClassPartial(); |
||||
|
||||
document.AssertWasCalled(doc => doc.Insert(17, "partial ")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,131 @@
@@ -0,0 +1,131 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class CodeFunction2Tests |
||||
{ |
||||
CodeFunction2 codeFunction; |
||||
MethodHelper helper; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
helper = new MethodHelper(); |
||||
} |
||||
|
||||
void CreatePublicFunction(string name) |
||||
{ |
||||
helper.CreatePublicMethod(name); |
||||
CreateFunction(); |
||||
} |
||||
|
||||
void CreateFunction() |
||||
{ |
||||
codeFunction = new CodeFunction2(helper.Method); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverrideKind_OrdinaryMethod_ReturnsNone() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
|
||||
vsCMOverrideKind kind = codeFunction.OverrideKind; |
||||
|
||||
Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindNone, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverrideKind_AbstractMethod_ReturnsAbstract() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.MakeMethodAbstract(); |
||||
|
||||
vsCMOverrideKind kind = codeFunction.OverrideKind; |
||||
|
||||
Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindAbstract, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverrideKind_VirtualMethod_ReturnsVirtual() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.MakeMethodVirtual(); |
||||
|
||||
vsCMOverrideKind kind = codeFunction.OverrideKind; |
||||
|
||||
Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindVirtual, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverrideKind_MethodOverride_ReturnsOverride() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.MakeMethodOverride(); |
||||
|
||||
vsCMOverrideKind kind = codeFunction.OverrideKind; |
||||
|
||||
Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindOverride, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverrideKind_SealedMethod_ReturnsSealed() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.MakeMethodSealed(); |
||||
|
||||
vsCMOverrideKind kind = codeFunction.OverrideKind; |
||||
|
||||
Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindSealed, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverrideKind_MethodHiddenByNewKeyword_ReturnsNew() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.MakeMethodNewOverride(); |
||||
|
||||
vsCMOverrideKind kind = codeFunction.OverrideKind; |
||||
|
||||
Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindNew, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsGeneric_MethodHasTypeParameter_ReturnsTrue() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.AddTypeParameter("TResult"); |
||||
|
||||
bool generic = codeFunction.IsGeneric; |
||||
|
||||
Assert.IsTrue(generic); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsGeneric_MethodHasTypeParameters_ReturnsFalse() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
helper.NoTypeParameters(); |
||||
|
||||
bool generic = codeFunction.IsGeneric; |
||||
|
||||
Assert.IsFalse(generic); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsGeneric_MethodTypeParametersIsNull_ReturnsFalse() |
||||
{ |
||||
CreatePublicFunction("MyClass.MyFunction"); |
||||
|
||||
bool generic = codeFunction.IsGeneric; |
||||
|
||||
Assert.IsFalse(generic); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class CodeParameter2Tests |
||||
{ |
||||
ParameterHelper helper; |
||||
CodeParameter2 parameter; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
helper = new ParameterHelper(); |
||||
} |
||||
|
||||
void CreateParameter() |
||||
{ |
||||
parameter = new CodeParameter2(null, helper.Parameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterKind_NormalParameter_ReturnsNone() |
||||
{ |
||||
CreateParameter(); |
||||
|
||||
vsCMParameterKind kind = parameter.ParameterKind; |
||||
|
||||
Assert.AreEqual(vsCMParameterKind.vsCMParameterKindNone, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterKind_OptionalParameter_ReturnsOptional() |
||||
{ |
||||
CreateParameter(); |
||||
helper.MakeOptionalParameter(); |
||||
|
||||
vsCMParameterKind kind = parameter.ParameterKind; |
||||
|
||||
Assert.AreEqual(vsCMParameterKind.vsCMParameterKindOptional, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterKind_OutParameter_ReturnsOut() |
||||
{ |
||||
CreateParameter(); |
||||
helper.MakeOutParameter(); |
||||
|
||||
vsCMParameterKind kind = parameter.ParameterKind; |
||||
|
||||
Assert.AreEqual(vsCMParameterKind.vsCMParameterKindOut, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterKind_RefParameter_ReturnsRef() |
||||
{ |
||||
CreateParameter(); |
||||
helper.MakeRefParameter(); |
||||
|
||||
vsCMParameterKind kind = parameter.ParameterKind; |
||||
|
||||
Assert.AreEqual(vsCMParameterKind.vsCMParameterKindRef, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterKind_ParamArrayParameter_ReturnsParamArray() |
||||
{ |
||||
CreateParameter(); |
||||
helper.MakeParamArrayParameter(); |
||||
|
||||
vsCMParameterKind kind = parameter.ParameterKind; |
||||
|
||||
Assert.AreEqual(vsCMParameterKind.vsCMParameterKindParamArray, kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParameterKind_InParameter_ReturnsIn() |
||||
{ |
||||
CreateParameter(); |
||||
helper.MakeInParameter(); |
||||
|
||||
vsCMParameterKind kind = parameter.ParameterKind; |
||||
|
||||
Assert.AreEqual(vsCMParameterKind.vsCMParameterKindIn, kind); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using NUnit.Framework; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class DocumentTests |
||||
{ |
||||
IViewContent view; |
||||
Document document; |
||||
OpenedFile openedFile; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
openedFile = MockRepository.GenerateStub<OpenedFile>(); |
||||
view = MockRepository.GenerateStub<IViewContent>(); |
||||
view.Stub(v => v.PrimaryFile).Return(openedFile); |
||||
} |
||||
|
||||
void CreateDocument(string fileName) |
||||
{ |
||||
document = new Document(fileName, view); |
||||
} |
||||
|
||||
void OpenFileIsDirty() |
||||
{ |
||||
openedFile.IsDirty = true; |
||||
} |
||||
|
||||
[Test] |
||||
public void Saved_SetToTrue_OpenFileIsDirtySetToFalse() |
||||
{ |
||||
CreateDocument(@"d:\projects\MyProject\program.cs"); |
||||
OpenFileIsDirty(); |
||||
|
||||
document.Saved = true; |
||||
|
||||
Assert.IsFalse(openedFile.IsDirty); |
||||
} |
||||
|
||||
[Test] |
||||
public void Saved_SetToFalse_OpenFileIsDirtySetToTrue() |
||||
{ |
||||
CreateDocument(@"d:\projects\MyProject\program.cs"); |
||||
|
||||
document.Saved = false; |
||||
|
||||
Assert.IsTrue(openedFile.IsDirty); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
using Rhino.Mocks; |
||||
using DTE = ICSharpCode.PackageManagement.EnvDTE; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class FileProjectItemsTests |
||||
{ |
||||
TestableDTEProject project; |
||||
FileProjectItems fileProjectItems; |
||||
TestableProject msbuildProject; |
||||
FakeFileService fakeFileService; |
||||
|
||||
void CreateProjectWithOneFileInProjectFolder( |
||||
string include, |
||||
string projectFileName = @"c:\projects\MyProject\MyProject.csproj") |
||||
{ |
||||
project = new TestableDTEProject(); |
||||
msbuildProject = project.TestableProject; |
||||
fakeFileService = project.FakeFileService; |
||||
msbuildProject.FileName = projectFileName; |
||||
msbuildProject.AddFile(include); |
||||
} |
||||
|
||||
void CreateFileProjectItemsFromFileInProjectFolder(string include) |
||||
{ |
||||
DTE.ProjectItem projectItem = project.ProjectItems.Item(include); |
||||
fileProjectItems = new DTE.FileProjectItems(projectItem, fakeFileService); |
||||
} |
||||
|
||||
IProjectBrowserUpdater CreateProjectBrowserUpdater() |
||||
{ |
||||
IProjectBrowserUpdater projectBrowserUpdater = MockRepository.GenerateStub<IProjectBrowserUpdater>(); |
||||
project.FakeProjectService.ProjectBrowserUpdater = projectBrowserUpdater; |
||||
return projectBrowserUpdater; |
||||
} |
||||
|
||||
[Test] |
||||
public void AddFromFile_AddFromFileFromProjectItemsBelongingToFile_FileIsParsed() |
||||
{ |
||||
string projectFileName = @"d:\projects\myproject\MyProject.csproj"; |
||||
CreateProjectWithOneFileInProjectFolder("MainForm.cs", projectFileName); |
||||
CreateFileProjectItemsFromFileInProjectFolder("MainForm.cs"); |
||||
string fileName = @"d:\projects\myproject\MainForm.Designer.cs"; |
||||
|
||||
fileProjectItems.AddFromFile(fileName); |
||||
|
||||
string parsedFileName = fakeFileService.FileNamePassedToParseFile; |
||||
Assert.AreEqual(fileName, parsedFileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddFromFile_AddFromFileFromProjectItemsBelongingToFile_ReturnsProjectItemAdded() |
||||
{ |
||||
string projectFileName = @"d:\projects\myproject\MyProject.csproj"; |
||||
CreateProjectWithOneFileInProjectFolder("MainForm.cs", projectFileName); |
||||
CreateFileProjectItemsFromFileInProjectFolder("MainForm.cs"); |
||||
string fileName = @"d:\projects\myproject\MainForm.Designer.cs"; |
||||
|
||||
DTE.ProjectItem itemAdded = fileProjectItems.AddFromFile(fileName); |
||||
|
||||
string fullPath = (string)itemAdded.Properties.Item("FullPath").Value; |
||||
Assert.AreEqual("MainForm.Designer.cs", itemAdded.Name); |
||||
Assert.AreEqual(fileName, fullPath); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddFromFile_AddFromFileFromProjectItemsBelongingToFile_ProjectIsSaved() |
||||
{ |
||||
string projectFileName = @"d:\projects\myproject\MyProject.csproj"; |
||||
CreateProjectWithOneFileInProjectFolder("MainForm.cs", projectFileName); |
||||
CreateFileProjectItemsFromFileInProjectFolder("MainForm.cs"); |
||||
string fileName = @"d:\projects\myproject\MainForm.Designer.cs"; |
||||
|
||||
fileProjectItems.AddFromFile(fileName); |
||||
|
||||
bool saved = msbuildProject.IsSaved; |
||||
Assert.IsTrue(saved); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddFromFile_AddFromFileFromProjectItemsBelongingToFile_ProjectBrowserUpdaterIsDisposed() |
||||
{ |
||||
string projectFileName = @"d:\projects\myproject\MyProject.csproj"; |
||||
CreateProjectWithOneFileInProjectFolder("MainForm.cs", projectFileName); |
||||
IProjectBrowserUpdater projectBrowserUpdater = CreateProjectBrowserUpdater(); |
||||
CreateFileProjectItemsFromFileInProjectFolder("MainForm.cs"); |
||||
string fileName = @"d:\projects\myproject\MainForm.Designer.cs"; |
||||
|
||||
fileProjectItems.AddFromFile(fileName); |
||||
|
||||
projectBrowserUpdater.AssertWasCalled(updater => updater.Dispose()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class ProjectsTests |
||||
{ |
||||
Projects projects; |
||||
SolutionHelper solutionHelper; |
||||
|
||||
void CreateSolutionWithSingleProject(string projectName) |
||||
{ |
||||
solutionHelper = new SolutionHelper(); |
||||
solutionHelper.AddProjectToSolution(projectName); |
||||
projects = solutionHelper.Solution.Projects; |
||||
} |
||||
|
||||
void CreateSolutionWithTwoProjects(string projectName1, string projectName2) |
||||
{ |
||||
solutionHelper = new SolutionHelper(); |
||||
solutionHelper.AddProjectToSolution(projectName1); |
||||
solutionHelper.AddProjectToSolution(projectName2); |
||||
projects = solutionHelper.Solution.Projects; |
||||
} |
||||
|
||||
[Test] |
||||
public void Item_OneProjectAndFirstItemRequested_ReturnsProject() |
||||
{ |
||||
CreateSolutionWithSingleProject("MyProject"); |
||||
|
||||
Project project = projects.Item(1); |
||||
|
||||
Assert.AreEqual("MyProject", project.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void Item_TwoProjectsAndSecondItemRequested_ReturnsSecondProject() |
||||
{ |
||||
CreateSolutionWithTwoProjects("MyProject1", "MyProject2"); |
||||
|
||||
Project project = projects.Item(2); |
||||
|
||||
Assert.AreEqual("MyProject2", project.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void Count_OneProject_ReturnsOne() |
||||
{ |
||||
CreateSolutionWithSingleProject("MyProject"); |
||||
|
||||
int count = projects.Count; |
||||
|
||||
Assert.AreEqual(1, count); |
||||
} |
||||
|
||||
[Test] |
||||
public void Count_TwoProjects_ReturnsTwo() |
||||
{ |
||||
CreateSolutionWithTwoProjects("MyProject1", "MyProject2"); |
||||
|
||||
int count = projects.Count; |
||||
|
||||
Assert.AreEqual(2, count); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class ParameterHelper |
||||
{ |
||||
public IParameter Parameter; |
||||
|
||||
public ParameterHelper() |
||||
{ |
||||
Parameter = MockRepository.GenerateStub<IParameter>(); |
||||
} |
||||
|
||||
public void MakeOptionalParameter() |
||||
{ |
||||
Parameter.Stub(p => p.IsOptional).Return(true); |
||||
} |
||||
|
||||
public void MakeOutParameter() |
||||
{ |
||||
Parameter.Stub(p => p.IsOut).Return(true); |
||||
} |
||||
|
||||
public void MakeRefParameter() |
||||
{ |
||||
Parameter.Stub(p => p.IsRef).Return(true); |
||||
} |
||||
|
||||
public void MakeParamArrayParameter() |
||||
{ |
||||
Parameter.Stub(p => p.IsParams).Return(true); |
||||
} |
||||
|
||||
public void MakeInParameter() |
||||
{ |
||||
Parameter.Stub(p => p.Modifiers).Return(ParameterModifiers.In); |
||||
} |
||||
|
||||
public void AddAttributeToParameter(string attributeTypeName) |
||||
{ |
||||
var attributeHelper = new AttributeHelper(); |
||||
attributeHelper.CreateAttribute(attributeTypeName); |
||||
attributeHelper.AddAttributeToParameter(Parameter); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class TypeParameterHelper |
||||
{ |
||||
public ITypeParameter TypeParameter; |
||||
|
||||
public TypeParameterHelper() |
||||
{ |
||||
TypeParameter = MockRepository.GenerateMock<ITypeParameter>(); |
||||
} |
||||
|
||||
public void SetName(string name) |
||||
{ |
||||
TypeParameter.Stub(tp => tp.Name); |
||||
} |
||||
|
||||
public List<ITypeParameter> TypeParameterToList() |
||||
{ |
||||
var parameters = new List<ITypeParameter>(); |
||||
parameters.Add(TypeParameter); |
||||
return parameters; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class VirtualMethodUpdaterTests |
||||
{ |
||||
VirtualMethodUpdater updater; |
||||
MethodHelper methodHelper; |
||||
IRefactoringDocument document; |
||||
IDocumentLoader documentLoader; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
methodHelper = new MethodHelper(); |
||||
document = MockRepository.GenerateStub<IRefactoringDocument>(); |
||||
documentLoader = MockRepository.GenerateStub<IDocumentLoader>(); |
||||
} |
||||
|
||||
void CreatePublicCSharpFunction() |
||||
{ |
||||
methodHelper.CreatePublicMethod("MyMethod"); |
||||
methodHelper.ProjectContentHelper.ProjectContentIsForCSharpProject(); |
||||
} |
||||
|
||||
void CreatePublicVisualBasicFunction() |
||||
{ |
||||
methodHelper.CreatePublicMethod("MyMethod"); |
||||
methodHelper.ProjectContentHelper.ProjectContentIsForVisualBasicProject(); |
||||
} |
||||
|
||||
void SetDocumentFileName(string fileName) |
||||
{ |
||||
documentLoader.Stub(loader => loader.LoadRefactoringDocument(fileName)).Return(document); |
||||
} |
||||
|
||||
void CreateVirtualMethodUpdater() |
||||
{ |
||||
updater = new VirtualMethodUpdater(methodHelper.Method, documentLoader); |
||||
} |
||||
|
||||
void SetFileNameForMethod(string fileName) |
||||
{ |
||||
methodHelper.SetCompilationUnitFileName(fileName); |
||||
SetDocumentFileName(fileName); |
||||
} |
||||
|
||||
void SetMethodDeclarationLineWithOffset(int line, string text, int offset) |
||||
{ |
||||
methodHelper.FunctionStartsAtLine(line); |
||||
SetDocumentLineText(line, text, offset); |
||||
} |
||||
|
||||
void SetMethodDeclarationLine(int line, string text) |
||||
{ |
||||
SetMethodDeclarationLineWithOffset(line, text, 0); |
||||
} |
||||
|
||||
void SetDocumentLineText(int lineNumber, string text, int offset) |
||||
{ |
||||
IRefactoringDocumentLine documentLine = MockRepository.GenerateStub<IRefactoringDocumentLine>(); |
||||
documentLine.Stub(line => line.Text).Return(text); |
||||
documentLine.Stub(line => line.Offset).Return(offset); |
||||
document.Stub(doc => doc.GetLine(lineNumber)).Return(documentLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeMethodVirtual_PublicCSharpClassWithNoOtherModifiers_AddsVirtualKeywordToMethodDefinition() |
||||
{ |
||||
CreatePublicCSharpFunction(); |
||||
CreateVirtualMethodUpdater(); |
||||
SetFileNameForMethod(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetMethodDeclarationLine(1, "public void MyMethod()"); |
||||
|
||||
updater.MakeMethodVirtual(); |
||||
|
||||
document.AssertWasCalled(doc => doc.Insert(7, "virtual ")); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeMethodVirtual_MethodAlreadyVirtual_MethodDefinitionIsNotChanged() |
||||
{ |
||||
CreatePublicCSharpFunction(); |
||||
CreateVirtualMethodUpdater(); |
||||
methodHelper.MakeMethodVirtual(); |
||||
SetFileNameForMethod(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetMethodDeclarationLine(1, "public void MyMethod()"); |
||||
|
||||
updater.MakeMethodVirtual(); |
||||
|
||||
document.AssertWasNotCalled(doc => doc.Insert(Arg<int>.Is.Anything, Arg<string>.Is.Anything)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeMethodVirtual_PublicVisualBasicClassWithNoOtherModifiers_AddsOverridableKeywordToMethodDefinition() |
||||
{ |
||||
CreatePublicVisualBasicFunction(); |
||||
CreateVirtualMethodUpdater(); |
||||
SetFileNameForMethod(@"d:\projects\MyProject\MyClass.vb"); |
||||
SetMethodDeclarationLine(1, "Public Sub MyMethod"); |
||||
|
||||
updater.MakeMethodVirtual(); |
||||
|
||||
document.AssertWasCalled(doc => doc.Insert(7, "Overridable ")); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeMethodVirtual_NoPublicKeywordInClassDeclarationLine_ExceptionIsThrown() |
||||
{ |
||||
CreatePublicCSharpFunction(); |
||||
CreateVirtualMethodUpdater(); |
||||
SetFileNameForMethod(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetMethodDeclarationLine(1, "void test()"); |
||||
|
||||
Assert.Throws<ApplicationException>(() => updater.MakeMethodVirtual()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeMethodVirtual_NoPublicKeywordButMethodNameIncludesPublicKeyword_ExceptionIsThrown() |
||||
{ |
||||
CreatePublicCSharpFunction(); |
||||
CreateVirtualMethodUpdater(); |
||||
SetFileNameForMethod(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetMethodDeclarationLine(1, "void publicmethod()"); |
||||
|
||||
Assert.Throws<ApplicationException>(() => updater.MakeMethodVirtual()); |
||||
} |
||||
|
||||
[Test] |
||||
public void MakeMethodVirtual_PublicCSharpMethodNotOnFirstLine_AddsVirtualKeywordToMethodDefinitionAtCorrectOffset() |
||||
{ |
||||
CreatePublicCSharpFunction(); |
||||
CreateVirtualMethodUpdater(); |
||||
SetFileNameForMethod(@"d:\projects\MyProject\MyClass.cs"); |
||||
SetMethodDeclarationLineWithOffset(1, "public void MyMethod()", offset: 10); |
||||
|
||||
updater.MakeMethodVirtual(); |
||||
|
||||
document.AssertWasCalled(doc => doc.Insert(17, "virtual ")); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue