12 changed files with 296 additions and 70 deletions
@ -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.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public class CodeAttributes : CodeElementsList |
||||
{ |
||||
IEntity entity; |
||||
|
||||
public CodeAttributes(IEntity entity) |
||||
{ |
||||
this.entity = entity; |
||||
GetAttributes(); |
||||
} |
||||
|
||||
void GetAttributes() |
||||
{ |
||||
foreach (IAttribute attribute in entity.Attributes) { |
||||
AddAttribute(attribute); |
||||
} |
||||
} |
||||
|
||||
void AddAttribute(IAttribute attribute) |
||||
{ |
||||
AddCodeElement(new CodeAttribute2(attribute)); |
||||
} |
||||
} |
||||
} |
||||
@ -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 System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.PackageManagement.EnvDTE |
||||
{ |
||||
public abstract class CodeElementsList : CodeElements |
||||
{ |
||||
List<CodeElement> elements = new List<CodeElement>(); |
||||
|
||||
public CodeElementsList() |
||||
{ |
||||
} |
||||
|
||||
protected virtual void AddCodeElement(CodeElement element) |
||||
{ |
||||
elements.Add(element); |
||||
} |
||||
|
||||
public int Count { |
||||
get { return elements.Count; } |
||||
} |
||||
|
||||
public IEnumerator GetEnumerator() |
||||
{ |
||||
return elements.GetEnumerator(); |
||||
} |
||||
|
||||
public CodeElement Item(object index) |
||||
{ |
||||
if (index is int) { |
||||
return Item((int)index); |
||||
} |
||||
return Item((string)index); |
||||
} |
||||
|
||||
CodeElement Item(int index) |
||||
{ |
||||
return elements[index - 1]; |
||||
} |
||||
|
||||
CodeElement Item(string name) |
||||
{ |
||||
return elements.Single(item => item.Name == name); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
// 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.Linq; |
||||
using ICSharpCode.PackageManagement.EnvDTE; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class CodeAttributesTests |
||||
{ |
||||
IClass fakeClass; |
||||
CodeAttributes attributes; |
||||
ProjectContentHelper helper; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
helper = new ProjectContentHelper(); |
||||
} |
||||
|
||||
void CreateCodeAttributes() |
||||
{ |
||||
attributes = new CodeAttributes(fakeClass); |
||||
} |
||||
|
||||
void CreateMSBuildClass() |
||||
{ |
||||
fakeClass = helper.AddClassToProjectContent("MyClass"); |
||||
} |
||||
|
||||
void AddAttributeToClass(string name) |
||||
{ |
||||
var attributeHelper = new AttributeHelper(); |
||||
attributeHelper.CreateAttribute(name); |
||||
attributeHelper.AddAttributeToClass(fakeClass); |
||||
} |
||||
|
||||
List<CodeElement> GetEnumerator() |
||||
{ |
||||
return attributes.ToList(); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetEnumerator_ClassHasOneAttribute_ReturnsOneAttribute() |
||||
{ |
||||
CreateMSBuildClass(); |
||||
AddAttributeToClass("TestAttribute"); |
||||
CreateCodeAttributes(); |
||||
|
||||
List<CodeElement> attributeList = GetEnumerator(); |
||||
|
||||
CodeAttribute2 attribute = attributeList.FirstOrDefault() as CodeAttribute2; |
||||
|
||||
Assert.AreEqual(1, attributeList.Count); |
||||
Assert.AreEqual("Test", attribute.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void Item_GetItemByNameWhenClassHasOneAttribute_ReturnsOneAttribute() |
||||
{ |
||||
CreateMSBuildClass(); |
||||
AddAttributeToClass("TestAttribute"); |
||||
CreateCodeAttributes(); |
||||
|
||||
CodeAttribute2 attribute = attributes.Item("Test") as CodeAttribute2; |
||||
|
||||
Assert.AreEqual("Test", attribute.Name); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// 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.Dom; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.EnvDTE |
||||
{ |
||||
[TestFixture] |
||||
public class CodeTypeTests |
||||
{ |
||||
CodeType codeType; |
||||
ProjectContentHelper helper; |
||||
IClass fakeClass; |
||||
|
||||
void CreateProjectContent() |
||||
{ |
||||
helper = new ProjectContentHelper(); |
||||
} |
||||
|
||||
void CreateClass(string name) |
||||
{ |
||||
fakeClass = helper.AddClassToProjectContent(name); |
||||
} |
||||
|
||||
void CreateCodeType() |
||||
{ |
||||
codeType = new CodeType(helper.FakeProjectContent, fakeClass); |
||||
} |
||||
|
||||
void AddAttributeToClass(string name) |
||||
{ |
||||
var attributeHelper = new AttributeHelper(); |
||||
attributeHelper.CreateAttribute(name); |
||||
attributeHelper.AddAttributeToClass(fakeClass); |
||||
} |
||||
|
||||
[Test] |
||||
public void Attributes_ClassHasOneAttribute_ReturnsOneAttribute() |
||||
{ |
||||
CreateProjectContent(); |
||||
CreateClass("TestClass"); |
||||
AddAttributeToClass("TestAttribute"); |
||||
CreateCodeType(); |
||||
|
||||
CodeElements attributes = codeType.Attributes; |
||||
|
||||
CodeAttribute2 attribute = attributes.Item(1) as CodeAttribute2; |
||||
|
||||
Assert.AreEqual(1, attributes.Count); |
||||
Assert.AreEqual("Test", attribute.Name); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue