16 changed files with 331 additions and 369 deletions
@ -1,198 +1,175 @@ |
|||||||
//// 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.Core; |
||||||
//using SDProject = ICSharpCode.SharpDevelop.Project;
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
//using NUnit.Framework;
|
using ICSharpCode.PackageManagement.EnvDTE; |
||||||
//using PackageManagement.Tests.Helpers;
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
//
|
using FileProjectItem = ICSharpCode.SharpDevelop.Project.FileProjectItem; |
||||||
//namespace PackageManagement.Tests.EnvDTE
|
using NUnit.Framework; |
||||||
//{
|
using PackageManagement.Tests.Helpers; |
||||||
// [TestFixture]
|
using Rhino.Mocks; |
||||||
// public class CodeTypeTests
|
using SDProject = ICSharpCode.SharpDevelop.Project; |
||||||
// {
|
|
||||||
// CodeType codeType;
|
namespace PackageManagement.Tests.EnvDTE |
||||||
// ClassHelper helper;
|
{ |
||||||
//
|
[TestFixture] |
||||||
// void CreateProjectContent()
|
public class CodeTypeTests : CodeModelTestBase |
||||||
// {
|
{ |
||||||
// helper = new ClassHelper();
|
CodeType codeType; |
||||||
// }
|
|
||||||
//
|
void CreateCodeType(string code, string fileName = "class.cs") |
||||||
// void CreateClass(string name)
|
{ |
||||||
// {
|
AddCodeFile(fileName, code); |
||||||
// helper.CreateClass(name);
|
ITypeDefinition typeDefinition = assemblyModel.TopLevelTypeDefinitions.Single().Resolve(); |
||||||
// }
|
CreateCodeType(typeDefinition); |
||||||
//
|
} |
||||||
// void CreateCodeType()
|
|
||||||
// {
|
void CreateCodeType(ITypeDefinition typeDefinition) |
||||||
// codeType = new CodeType(helper.ProjectContentHelper.ProjectContent, helper.Class);
|
{ |
||||||
// }
|
codeType = new CodeType(codeModelContext, typeDefinition); |
||||||
//
|
} |
||||||
// TestableProject AddProjectToProjectContent()
|
|
||||||
// {
|
FileProjectItem AddFileToProject(string fileName) |
||||||
// TestableProject project = ProjectHelper.CreateTestProject();
|
{ |
||||||
// helper.ProjectContentHelper.SetProjectForProjectContent(project);
|
var projectItem = new FileProjectItem(project, ICSharpCode.SharpDevelop.Project.ItemType.Compile); |
||||||
// return project;
|
project |
||||||
// }
|
.Stub(p => p.FindFile(new FileName(fileName))) |
||||||
//
|
.Return(projectItem); |
||||||
// void AddAttributeToClass(string name)
|
|
||||||
// {
|
project |
||||||
// helper.AddAttributeToClass(name);
|
.Stub(p => p.SyncRoot) |
||||||
// }
|
.Return(new object()); |
||||||
//
|
|
||||||
// SDProject.FileProjectItem AddFileToProjectAndProjectContent(TestableProject project, string fileName)
|
return projectItem; |
||||||
// {
|
} |
||||||
// helper.CompilationUnitHelper.SetFileName(fileName);
|
|
||||||
// return project.AddFile(fileName);
|
[Test] |
||||||
// }
|
public void Attributes_ClassHasOneAttribute_ReturnsOneAttribute() |
||||||
//
|
{ |
||||||
// /// <summary>
|
CreateCodeType("[TestAttribute] public class TestClass {}"); |
||||||
// /// Classes at the end of the array are at the top of the inheritance tree.
|
|
||||||
// /// </summary>
|
global::EnvDTE.CodeElements attributes = codeType.Attributes; |
||||||
// void AddClassInheritanceTree(params string[] classNames)
|
|
||||||
// {
|
CodeAttribute2 attribute = attributes.Item(1) as CodeAttribute2; |
||||||
// helper.AddClassInheritanceTreeClassesOnly(classNames);
|
Assert.AreEqual(1, attributes.Count); |
||||||
// }
|
Assert.AreEqual("Test", attribute.Name); |
||||||
//
|
} |
||||||
// [Test]
|
|
||||||
// public void Attributes_ClassHasOneAttribute_ReturnsOneAttribute()
|
[Test] |
||||||
// {
|
public void ProjectItem_TypeNotFromProject_ReturnsNull() |
||||||
// CreateProjectContent();
|
{ |
||||||
// CreateClass("TestClass");
|
AddCodeFile("class.cs", "public class TestClass {}"); |
||||||
// AddAttributeToClass("TestAttribute");
|
ITypeDefinition typeDefinition = projectContent |
||||||
// CreateCodeType();
|
.CreateCompilation() |
||||||
//
|
.ReferencedAssemblies |
||||||
// global::EnvDTE.CodeElements attributes = codeType.Attributes;
|
.FirstOrDefault() |
||||||
//
|
.TopLevelTypeDefinitions.First(); |
||||||
// CodeAttribute2 attribute = attributes.Item(1) as CodeAttribute2;
|
CreateCodeType(typeDefinition); |
||||||
//
|
|
||||||
// Assert.AreEqual(1, attributes.Count);
|
global::EnvDTE.ProjectItem item = codeType.ProjectItem; |
||||||
// Assert.AreEqual("Test", attribute.Name);
|
|
||||||
// }
|
Assert.IsNull(item); |
||||||
//
|
} |
||||||
// [Test]
|
|
||||||
// public void ProjectItem_ProjectContentHasNullProject_ReturnsNull()
|
[Test] |
||||||
// {
|
public void ProjectItem_TypeIsFromProject_ReturnsNonNullProjectItem() |
||||||
// CreateProjectContent();
|
{ |
||||||
// CreateClass("Class1");
|
string fileName = @"d:\projects\MyProject\class1.cs"; |
||||||
// CreateCodeType();
|
CreateCodeType("public class TestClass {}", fileName); |
||||||
//
|
AddFileToProject(fileName); |
||||||
// global::EnvDTE.ProjectItem item = codeType.ProjectItem;
|
|
||||||
//
|
global::EnvDTE.ProjectItem item = codeType.ProjectItem; |
||||||
// Assert.IsNull(item);
|
|
||||||
// }
|
Assert.IsNotNull(item); |
||||||
//
|
} |
||||||
// [Test]
|
|
||||||
// public void ProjectItem_ProjectContentHasProject_ReturnsNonNullProjectItem()
|
[Test] |
||||||
// {
|
public void ProjectItem_TypeIsFromProject_ReturnsProjectItemThatUsesProject() |
||||||
// CreateProjectContent();
|
{ |
||||||
// TestableProject project = AddProjectToProjectContent();
|
string fileName = @"d:\projects\MyProject\class1.cs"; |
||||||
// AddFileToProjectAndProjectContent(project, @"d:\projects\MyProject\class1.cs");
|
CreateCodeType("public class TestClass {}", fileName); |
||||||
// CreateClass("Class1");
|
TestableProject testableProject = ProjectHelper.CreateTestProject(); |
||||||
// CreateCodeType();
|
testableProject.FileName = new FileName(@"d:\projects\MyProject\MyProject.csproj"); |
||||||
//
|
codeModelContext.CurrentProject = testableProject; |
||||||
// global::EnvDTE.ProjectItem item = codeType.ProjectItem;
|
testableProject.AddFile(fileName); |
||||||
//
|
|
||||||
// Assert.IsNotNull(item);
|
global::EnvDTE.ProjectItem item = codeType.ProjectItem; |
||||||
// }
|
|
||||||
//
|
Assert.AreEqual(@"d:\projects\MyProject\MyProject.csproj", item.ContainingProject.FileName); |
||||||
// [Test]
|
} |
||||||
// public void ProjectItem_ProjectContentHasProject_ReturnsProjectItemThatUsesProject()
|
|
||||||
// {
|
[Test] |
||||||
// CreateProjectContent();
|
public void ProjectItem_ProjectContentHasProject_ReturnsProjectItemThatUsesProjectFileItem() |
||||||
// TestableProject project = AddProjectToProjectContent();
|
{ |
||||||
// project.FileName = @"d:\projects\MyProject\MyProject.csproj";
|
string fileName = @"d:\projects\MyProject\test.cs"; |
||||||
// AddFileToProjectAndProjectContent(project, @"d:\projects\MyProject\class1.cs");
|
CreateCodeType("public class TestClass {}", fileName); |
||||||
// CreateClass("Class1");
|
TestableProject testableProject = ProjectHelper.CreateTestProject(); |
||||||
// CreateCodeType();
|
testableProject.FileName = new FileName(@"d:\projects\MyProject\MyProject.csproj"); |
||||||
//
|
codeModelContext.CurrentProject = testableProject; |
||||||
// global::EnvDTE.ProjectItem item = codeType.ProjectItem;
|
testableProject.AddFile(fileName); |
||||||
//
|
|
||||||
// Assert.AreEqual(@"d:\projects\MyProject\MyProject.csproj", item.ContainingProject.FileName);
|
global::EnvDTE.ProjectItem item = codeType.ProjectItem; |
||||||
// }
|
|
||||||
//
|
Assert.AreEqual("test.cs", item.Name); |
||||||
// [Test]
|
} |
||||||
// public void ProjectItem_ProjectContentHasProject_ReturnsProjectItemThatUsesProjectFileItem()
|
|
||||||
// {
|
[Test] |
||||||
// CreateProjectContent();
|
public void IsDerivedFrom_ClassFullyQualifiedNameMatchesTypeNameBeingChecked_ReturnsTrue() |
||||||
// TestableProject project = AddProjectToProjectContent();
|
{ |
||||||
// string fileName = @"d:\projects\MyProject\test.cs";
|
CreateCodeType( |
||||||
// SDProject.FileProjectItem fileProjectItem = AddFileToProjectAndProjectContent(project, fileName);
|
"namespace System.Web.Mvc {\r\n" + |
||||||
//
|
" public class ActionResult {}\r\n" + |
||||||
// CreateClass("Class1");
|
"}"); |
||||||
// CreateCodeType();
|
|
||||||
//
|
bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult"); |
||||||
// global::EnvDTE.ProjectItem item = codeType.ProjectItem;
|
|
||||||
//
|
Assert.IsTrue(derivedFrom); |
||||||
// Assert.AreEqual("test.cs", item.Name);
|
} |
||||||
// }
|
|
||||||
//
|
[Test] |
||||||
// [Test]
|
public void IsDerivedFrom_ClassFullyQualifiedNameDoesNotMatchTypeNameBeingChecked_ReturnsFalse() |
||||||
// public void IsDerivedFrom_ClassFullyQualifiedNameMatchesTypeNameBeingChecked_ReturnsTrue()
|
{ |
||||||
// {
|
CreateCodeType("public class Test {}"); |
||||||
// CreateProjectContent();
|
|
||||||
// CreateClass("System.Web.Mvc.ActionResult");
|
bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult"); |
||||||
// CreateCodeType();
|
|
||||||
//
|
Assert.IsFalse(derivedFrom); |
||||||
// bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult");
|
} |
||||||
//
|
|
||||||
// Assert.IsTrue(derivedFrom);
|
[Test] |
||||||
// }
|
public void IsDerivedFrom_ClassBaseTypeFullyQualifiedNameMatchesTypeName_ReturnsTrue() |
||||||
//
|
{ |
||||||
// [Test]
|
AddCodeFile( |
||||||
// public void IsDerivedFrom_ClassFullyQualifiedNameDoesNotMatcheTypeNameBeingChecked_ReturnsFalse()
|
"class.cs", |
||||||
// {
|
"namespace System.Web.Mvc {\r\n" + |
||||||
// CreateProjectContent();
|
" public class CustomActionResult : ActionResult {}\r\n" + |
||||||
// CreateClass("TestClass");
|
" public class ActionResult {}\r\n" + |
||||||
// AddClassInheritanceTree("System.Object");
|
"}"); |
||||||
// CreateCodeType();
|
CreateCodeType(assemblyModel.TopLevelTypeDefinitions.First().Resolve()); |
||||||
//
|
|
||||||
// bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult");
|
bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult"); |
||||||
//
|
|
||||||
// Assert.IsFalse(derivedFrom);
|
Assert.IsTrue(derivedFrom); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// [Test]
|
[Test] |
||||||
// public void IsDerivedFrom_ClassBaseTypeFullyQualifiedNameMatchesTypeName_ReturnsTrue()
|
public void IsDerivedFrom_ClassHasTypeInClassInheritanceTreeButNotImmediateBaseType_ReturnsTrue() |
||||||
// {
|
{ |
||||||
// CreateProjectContent();
|
AddCodeFile( |
||||||
// CreateClass("CustomActionResult");
|
"class.cs", |
||||||
// helper.AddBaseTypeToClass("System.Web.Mvc.ActionResult");
|
"namespace System.Web.Mvc {\r\n" + |
||||||
// CreateCodeType();
|
" public class CustomActionResult : CustomActionResultBase {}\r\n" + |
||||||
//
|
" public class CustomActionResultBase : ActionResult {}\r\n" + |
||||||
// bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult");
|
" public class ActionResult {}\r\n" + |
||||||
//
|
"}"); |
||||||
// Assert.IsTrue(derivedFrom);
|
CreateCodeType(assemblyModel.TopLevelTypeDefinitions.First().Resolve()); |
||||||
// }
|
|
||||||
//
|
bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult"); |
||||||
// [Test]
|
|
||||||
// public void IsDerivedFrom_ClassHasTypeInClassInheritanceTreeButNotImmediateBaseType_ReturnsTrue()
|
Assert.IsTrue(derivedFrom); |
||||||
// {
|
} |
||||||
// CreateProjectContent();
|
} |
||||||
// CreateClass("CustomActionResult");
|
} |
||||||
// AddClassInheritanceTree("CustomActionResultBase", "System.Web.Mvc.ActionResult");
|
|
||||||
// CreateCodeType();
|
|
||||||
//
|
|
||||||
// bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult");
|
|
||||||
//
|
|
||||||
// Assert.IsTrue(derivedFrom);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// [Test]
|
|
||||||
// public void IsDerivedFrom_ClassHasClassInInheritanceTreeButNotImmediateParentAndClassBaseTypePropertyIsNotNull_ReturnsTrue()
|
|
||||||
// {
|
|
||||||
// CreateProjectContent();
|
|
||||||
// CreateClass("CustomActionResult");
|
|
||||||
// helper.AddBaseTypeToClass("CustomActionResultBase");
|
|
||||||
// AddClassInheritanceTree("CustomActionResultBase", "System.Web.Mvc.ActionResult");
|
|
||||||
// CreateCodeType();
|
|
||||||
//
|
|
||||||
// bool derivedFrom = codeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult");
|
|
||||||
//
|
|
||||||
// Assert.IsTrue(derivedFrom);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|||||||
Loading…
Reference in new issue