Browse Source

Update EnvDTE.CodeVariable tests.

pull/375/head
Matt Ward 12 years ago
parent
commit
e8338ae539
  1. 21
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeClass.cs
  2. 10
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs
  3. 12
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs
  4. 1
      src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
  5. 247
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeVariableTests.cs
  6. 75
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FieldHelper.cs

21
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeClass.cs

@ -46,16 +46,17 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null) public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null)
{ {
var fieldTypeName = new FullTypeName((string)type); // var fieldTypeName = new FullTypeName((string)type);
var td = typeModel.Resolve(); // var typeDefinition = typeModel.Resolve();
if (td == null) // if (typeDefinition == null)
return null; // return null;
IType fieldType = td.Compilation.FindType(fieldTypeName); //
context.CodeGenerator.AddField(td, Access.ToAccessibility(), fieldType, name); // IType fieldType = typeDefinition.Compilation.FindType(fieldTypeName);
var fieldModel = typeModel.Members.OfType<IFieldModel>().FirstOrDefault(f => f.Name == name); // context.CodeGenerator.AddField(typeDefinition, Access.ToAccessibility(), fieldType, name);
if (fieldModel != null) { // var fieldModel = typeModel.Members.OfType<IFieldModel>().FirstOrDefault(f => f.Name == name);
return new CodeVariable(context, fieldModel); // if (fieldModel != null) {
} // return new CodeVariable(context, fieldModel);
// }
return null; return null;
} }
} }

10
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElement.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{ {
switch (m.SymbolKind) { switch (m.SymbolKind) {
case SymbolKind.Field: case SymbolKind.Field:
return new CodeVariable(context, (IFieldModel)m); return new CodeVariable(context, m.Resolve() as IField);
case SymbolKind.Property: case SymbolKind.Property:
case SymbolKind.Indexer: case SymbolKind.Indexer:
// return new CodeProperty2(m); // return new CodeProperty2(m);
@ -76,16 +76,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE
// default is vsCMPart.vsCMPartWholeWithAttributes // default is vsCMPart.vsCMPartWholeWithAttributes
public virtual global::EnvDTE.TextPoint GetStartPoint() public virtual global::EnvDTE.TextPoint GetStartPoint()
{ {
// if (symbolModel != null) return TextPoint.CreateStartPoint(context, entity.Region);
// return TextPoint.CreateStartPoint(context, symbolModel.Region);
return null;
} }
public virtual global::EnvDTE.TextPoint GetEndPoint() public virtual global::EnvDTE.TextPoint GetEndPoint()
{ {
// if (symbolModel != null) return TextPoint.CreateEndPoint(context, entity.Region);
// return TextPoint.CreateEndPoint(context, symbolModel.Region);
return null;
} }
public virtual global::EnvDTE.vsCMInfoLocation InfoLocation { get; protected set; } public virtual global::EnvDTE.vsCMInfoLocation InfoLocation { get; protected set; }

12
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs

@ -2,19 +2,20 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement.EnvDTE namespace ICSharpCode.PackageManagement.EnvDTE
{ {
public class CodeVariable : CodeElement, global::EnvDTE.CodeVariable public class CodeVariable : CodeElement, global::EnvDTE.CodeVariable
{ {
readonly IFieldModel field; readonly IField field;
public CodeVariable() public CodeVariable()
{ {
} }
public CodeVariable(CodeModelContext context, IFieldModel field) public CodeVariable(CodeModelContext context, IField field)
: base(context, field) : base(context, field)
{ {
this.field = field; this.field = field;
@ -26,12 +27,7 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public global::EnvDTE.vsCMAccess Access { public global::EnvDTE.vsCMAccess Access {
get { return field.Accessibility.ToAccess(); } get { return field.Accessibility.ToAccess(); }
set { set { }
var f = field.Resolve();
if (f != null) {
context.CodeGenerator.ChangeAccessibility(f, value.ToAccessibility());
}
}
} }
} }
} }

1
src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj

@ -122,7 +122,6 @@
<Compile Include="Src\Helpers\ExceptionThrowingProcessPackageAction.cs" /> <Compile Include="Src\Helpers\ExceptionThrowingProcessPackageAction.cs" />
<Compile Include="Src\Helpers\FakeCodeGenerator.cs" /> <Compile Include="Src\Helpers\FakeCodeGenerator.cs" />
<Compile Include="Src\Helpers\FakeOperationAwarePackageRepository.cs" /> <Compile Include="Src\Helpers\FakeOperationAwarePackageRepository.cs" />
<Compile Include="Src\Helpers\FieldHelper.cs" />
<Compile Include="Src\Helpers\FakeSelectProjectsService.cs" /> <Compile Include="Src\Helpers\FakeSelectProjectsService.cs" />
<Compile Include="Src\Helpers\FakeSolutionPackageRepositoryFactory.cs" /> <Compile Include="Src\Helpers\FakeSolutionPackageRepositoryFactory.cs" />
<Compile Include="Src\Helpers\FakeUpdatePackageActions.cs" /> <Compile Include="Src\Helpers\FakeUpdatePackageActions.cs" />

247
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeVariableTests.cs

@ -1,140 +1,107 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // 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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System; using System;
//using ICSharpCode.PackageManagement.EnvDTE; using System.Linq;
//using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.NRefactory.TypeSystem;
//using NUnit.Framework; using ICSharpCode.PackageManagement.EnvDTE;
//using PackageManagement.Tests.Helpers; using ICSharpCode.SharpDevelop.Dom;
//using Rhino.Mocks; using NUnit.Framework;
// using PackageManagement.Tests.Helpers;
//namespace PackageManagement.Tests.EnvDTE using Rhino.Mocks;
//{
// [TestFixture] namespace PackageManagement.Tests.EnvDTE
// public class CodeVariableTests {
// { [TestFixture]
// CodeVariable codeVariable; public class CodeVariableTests : CodeModelTestBase
// FieldHelper helper; {
// CodeVariable codeVariable;
// [SetUp]
// public void Init() void CreateCodeVariable(string code)
// { {
// helper = new FieldHelper(); AddCodeFile("class.cs", code);
// } ITypeDefinition typeDefinition = assemblyModel.TopLevelTypeDefinitions.Single().Resolve();
// codeVariable = new CodeVariable(codeModelContext, typeDefinition.Fields.First());
// void CreatePublicVariable(string name) }
// {
// helper.CreatePublicField(name); [Test]
// CreateVariable(); public void Access_PublicVariable_ReturnsPublic()
// } {
// CreateCodeVariable(
// void CreatePrivateVariable(string name) "public class MyClass {\r\n" +
// { " public int MyVariable;\r\n" +
// helper.CreatePrivateField(name); "}");
// CreateVariable();
// } global::EnvDTE.vsCMAccess access = codeVariable.Access;
//
// void CreateVariable() Assert.AreEqual(global::EnvDTE.vsCMAccess.vsCMAccessPublic, access);
// { }
// codeVariable = new CodeVariable(helper.Field);
// } [Test]
// public void Access_PrivateVariable_ReturnsPrivate()
// void VariableStartsAtColumn(int column) {
// { CreateCodeVariable(
// helper.VariableStartsAtColumn(column); "public class MyClass {\r\n" +
// } " private int MyVariable;\r\n" +
// "}");
// void VariableStartsAtLine(int line)
// { global::EnvDTE.vsCMAccess access = codeVariable.Access;
// helper.VariableStartsAtLine(line);
// } Assert.AreEqual(global::EnvDTE.vsCMAccess.vsCMAccessPrivate, access);
// }
// void VariableEndsAtColumn(int column)
// { [Test]
// helper.VariableEndsAtColumn(column); public void GetStartPoint_VariableStartsAtColumnOneOnLineTwo_ReturnsTextPointWithLineCharOffsetOneAndLineTwo()
// } {
// CreateCodeVariable(
// void VariableEndsAtLine(int line) "public class Foo {\r\n" +
// { "int V;\r\n" +
// helper.VariableEndsAtLine(line); "}");
// }
// global::EnvDTE.TextPoint point = codeVariable.GetStartPoint();
// [Test]
// public void Access_PublicVariable_ReturnsPublic() Assert.AreEqual(1, point.LineCharOffset);
// { Assert.AreEqual(2, point.Line);
// CreatePublicVariable("MyVariable"); }
//
// global::EnvDTE.vsCMAccess access = codeVariable.Access; [Test]
// public void GetEndPoint_VariableEndsAtColumnSevenOnLineTwo_ReturnsTextPointWithLineCharOffsetSevenOnLineTwo()
// Assert.AreEqual(global::EnvDTE.vsCMAccess.vsCMAccessPublic, access); {
// } CreateCodeVariable(
// "public class Foo {\r\n" +
// [Test] "int V;\r\n" +
// public void Access_PrivateVariable_ReturnsPrivate() "}");
// {
// CreatePrivateVariable("MyVariable"); global::EnvDTE.TextPoint point = codeVariable.GetEndPoint();
//
// global::EnvDTE.vsCMAccess access = codeVariable.Access; Assert.AreEqual(7, point.LineCharOffset);
// Assert.AreEqual(2, point.Line);
// Assert.AreEqual(global::EnvDTE.vsCMAccess.vsCMAccessPrivate, access); }
// }
// [Test]
// [Test] public void Kind_PublicVariable_ReturnsVariable()
// public void GetStartPoint_VariableStartsAtColumn5_ReturnsTextPointWithLineCharOffset5() {
// { CreateCodeVariable(
// CreatePublicVariable("MyVariable"); "public class MyClass {\r\n" +
// VariableStartsAtColumn(5); " private int MyVariable;\r\n" +
// "}");
// global::EnvDTE.TextPoint point = codeVariable.GetStartPoint();
// int offset = point.LineCharOffset; global::EnvDTE.vsCMElement kind = codeVariable.Kind;
//
// Assert.AreEqual(5, offset); Assert.AreEqual(global::EnvDTE.vsCMElement.vsCMElementVariable, kind);
// } }
//
// [Test] [Test]
// public void GetStartPoint_VariableStartsAtLine1_ReturnsTextPointWithLine1() public void GetEndPoint_VariableHasSpaceBeforeSemiColon_ReturnsTextPointThatIncludesSemiColon()
// { {
// CreatePublicVariable("MyVariable"); CreateCodeVariable(
// VariableStartsAtLine(1); "public class Foo {\r\n" +
// "int V ;\r\n" +
// global::EnvDTE.TextPoint point = codeVariable.GetStartPoint(); "}");
// int line = point.Line;
// global::EnvDTE.TextPoint point = codeVariable.GetEndPoint();
// Assert.AreEqual(1, line);
// } Assert.AreEqual(8, point.LineCharOffset);
// }
// [Test] }
// public void GetEndPoint_VariableEndsAtColumn10_ReturnsTextPointWithLineCharOffset10() }
// {
// CreatePublicVariable("MyVariable");
// VariableEndsAtColumn(10);
//
// global::EnvDTE.TextPoint point = codeVariable.GetEndPoint();
// int offset = point.LineCharOffset;
//
// Assert.AreEqual(10, offset);
// }
//
// [Test]
// public void GetEndPoint_VariableEndsAtLine2_ReturnsTextPointWithLine2()
// {
// CreatePublicVariable("MyVariable");
// VariableEndsAtLine(2);
//
// global::EnvDTE.TextPoint point = codeVariable.GetEndPoint();
// int line = point.Line;
//
// Assert.AreEqual(2, line);
// }
//
// [Test]
// public void Kind_PublicVariable_ReturnsVariable()
// {
// CreatePublicVariable("MyVariable");
//
// global::EnvDTE.vsCMElement kind = codeVariable.Kind;
//
// Assert.AreEqual(global::EnvDTE.vsCMElement.vsCMElementVariable, kind);
// }
// }
//}

75
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FieldHelper.cs

@ -1,75 +0,0 @@
//// 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;
//using Rhino.Mocks;
//
//namespace PackageManagement.Tests.Helpers
//{
// public class FieldHelper
// {
// public IField Field;
// public ProjectContentHelper ProjectContentHelper = new ProjectContentHelper();
//
// /// <summary>
// /// Field name should include the class prefix (e.g. "Class1.MyField")
// /// </summary>
// public void CreateField(string fullyQualifiedName)
// {
// Field = MockRepository.GenerateMock<IField, IEntity>();
// Field.Stub(f => f.ProjectContent).Return(ProjectContentHelper.ProjectContent);
// Field.Stub(f => f.FullyQualifiedName).Return(fullyQualifiedName);
// }
//
// public void CreatePublicField(string fullyQualifiedName)
// {
// CreateField(fullyQualifiedName);
// Field.Stub(f => f.IsPublic).Return(true);
// }
//
// public void CreatePrivateField(string fullyQualifiedName)
// {
// CreateField(fullyQualifiedName);
// Field.Stub(f => f.IsPublic).Return(false);
// Field.Stub(f => f.IsPrivate).Return(true);
// }
//
// public void SetRegion(DomRegion region)
// {
// Field.Stub(f => f.Region).Return(region);
// }
//
// public void VariableStartsAtColumn(int column)
// {
// var region = new DomRegion(1, column);
// SetRegion(region);
// }
//
// public void VariableStartsAtLine(int line)
// {
// var region = new DomRegion(line, 1);
// SetRegion(region);
// }
//
// public void VariableEndsAtColumn(int column)
// {
// var region = new DomRegion(1, 1, 1, column);
// SetRegion(region);
// }
//
// public void VariableEndsAtLine(int line)
// {
// var region = new DomRegion(1, 1, line, 1);
// SetRegion(region);
// }
//
// public void SetCompilationUnitFileName(string fileName)
// {
// var helper = new CompilationUnitHelper();
// helper.SetFileName(fileName);
// Field.Stub(f => f.CompilationUnit).Return(helper.CompilationUnit);
// }
// }
//}
Loading…
Cancel
Save