5 changed files with 148 additions and 207 deletions
@ -1,93 +1,141 @@ |
|||||||
//// 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 NUnit.Framework;
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
//using PackageManagement.Tests.Helpers;
|
using ICSharpCode.PackageManagement.EnvDTE; |
||||||
//
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
//namespace PackageManagement.Tests.EnvDTE
|
using NUnit.Framework; |
||||||
//{
|
using PackageManagement.Tests.Helpers; |
||||||
// [TestFixture]
|
|
||||||
// public class CodeParameter2Tests
|
namespace PackageManagement.Tests.EnvDTE |
||||||
// {
|
{ |
||||||
// ParameterHelper helper;
|
[TestFixture] |
||||||
// CodeParameter2 parameter;
|
public class CodeParameter2Tests : CodeModelTestBase |
||||||
//
|
{ |
||||||
// [SetUp]
|
CodeParameter2 parameter; |
||||||
// public void Init()
|
|
||||||
// {
|
void CreateParameter(string code) |
||||||
// helper = new ParameterHelper();
|
{ |
||||||
// }
|
AddCodeFile("class.cs", code); |
||||||
//
|
IMethod method = assemblyModel |
||||||
// void CreateParameter()
|
.TopLevelTypeDefinitions |
||||||
// {
|
.First() |
||||||
// parameter = new CodeParameter2(null, helper.Parameter);
|
.Members |
||||||
// }
|
.First() |
||||||
//
|
.Resolve() as IMethod; |
||||||
// [Test]
|
|
||||||
// public void ParameterKind_NormalParameter_ReturnsNone()
|
IParameter member = method.Parameters.First(); |
||||||
// {
|
parameter = new CodeParameter2(codeModelContext, member); |
||||||
// CreateParameter();
|
} |
||||||
//
|
|
||||||
// global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind;
|
[Test] |
||||||
//
|
public void ParameterKind_NormalParameter_ReturnsNone() |
||||||
// Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindNone, kind);
|
{ |
||||||
// }
|
CreateParameter( |
||||||
//
|
"public class MyClass {\r\n" + |
||||||
// [Test]
|
" public void MyMethod(int parameter) {}\r\n" + |
||||||
// public void ParameterKind_OptionalParameter_ReturnsOptional()
|
"}"); |
||||||
// {
|
|
||||||
// CreateParameter();
|
global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind; |
||||||
// helper.MakeOptionalParameter();
|
|
||||||
//
|
Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindNone, kind); |
||||||
// global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind;
|
} |
||||||
//
|
|
||||||
// Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindOptional, kind);
|
[Test] |
||||||
// }
|
public void ParameterKind_OptionalParameter_ReturnsOptional() |
||||||
//
|
{ |
||||||
// [Test]
|
CreateParameter( |
||||||
// public void ParameterKind_OutParameter_ReturnsOut()
|
"public class MyClass {\r\n" + |
||||||
// {
|
" public void MyMethod(int parameter = 0) {}\r\n" + |
||||||
// CreateParameter();
|
"}"); |
||||||
// helper.MakeOutParameter();
|
|
||||||
//
|
global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind; |
||||||
// global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind;
|
|
||||||
//
|
Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindOptional, kind); |
||||||
// Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindOut, kind);
|
} |
||||||
// }
|
|
||||||
//
|
[Test] |
||||||
// [Test]
|
public void ParameterKind_OutParameter_ReturnsOut() |
||||||
// public void ParameterKind_RefParameter_ReturnsRef()
|
{ |
||||||
// {
|
CreateParameter( |
||||||
// CreateParameter();
|
"public class MyClass {\r\n" + |
||||||
// helper.MakeRefParameter();
|
" public void MyMethod(out int parameter) { parameter = 2; }\r\n" + |
||||||
//
|
"}"); |
||||||
// global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind;
|
|
||||||
//
|
global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind; |
||||||
// Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindRef, kind);
|
|
||||||
// }
|
Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindOut, kind); |
||||||
//
|
} |
||||||
// [Test]
|
|
||||||
// public void ParameterKind_ParamArrayParameter_ReturnsParamArray()
|
[Test] |
||||||
// {
|
public void ParameterKind_RefParameter_ReturnsRef() |
||||||
// CreateParameter();
|
{ |
||||||
// helper.MakeParamArrayParameter();
|
CreateParameter( |
||||||
//
|
"public class MyClass {\r\n" + |
||||||
// global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind;
|
" public void MyMethod(ref int parameter) {}\r\n" + |
||||||
//
|
"}"); |
||||||
// Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindParamArray, kind);
|
|
||||||
// }
|
global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind; |
||||||
//
|
|
||||||
// [Test]
|
Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindRef, kind); |
||||||
// public void ParameterKind_InParameter_ReturnsIn()
|
} |
||||||
// {
|
|
||||||
// CreateParameter();
|
[Test] |
||||||
// helper.MakeInParameter();
|
public void ParameterKind_ParamArrayParameter_ReturnsParamArray() |
||||||
//
|
{ |
||||||
// global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind;
|
CreateParameter( |
||||||
//
|
"public class MyClass {\r\n" + |
||||||
// Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindIn, kind);
|
" public void MyMethod(params int[] parameters) {}\r\n" + |
||||||
// }
|
"}"); |
||||||
// }
|
|
||||||
//}
|
global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind; |
||||||
|
|
||||||
|
Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindParamArray, kind); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
[Ignore("Not supported by NRefactory. Maps to VB.NET's ByVal. For C# vsCMParameterKindNone is returned.")] |
||||||
|
public void ParameterKind_InParameter_ReturnsIn() |
||||||
|
{ |
||||||
|
CreateParameter( |
||||||
|
"public class MyClass {\r\n" + |
||||||
|
" public void MyMethod(int parameter) {}\r\n" + |
||||||
|
"}"); |
||||||
|
|
||||||
|
global::EnvDTE.vsCMParameterKind kind = parameter.ParameterKind; |
||||||
|
|
||||||
|
Assert.AreEqual(global::EnvDTE.vsCMParameterKind.vsCMParameterKindIn, kind); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Kind_Parameter_ReturnsParameter() |
||||||
|
{ |
||||||
|
CreateParameter( |
||||||
|
"public class MyClass {\r\n" + |
||||||
|
" public void MyMethod(int parameter) {}\r\n" + |
||||||
|
"}"); |
||||||
|
|
||||||
|
global::EnvDTE.vsCMElement kind = parameter.Kind; |
||||||
|
|
||||||
|
Assert.AreEqual(global::EnvDTE.vsCMElement.vsCMElementParameter, kind); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Attributes_ParameterHasOneAttribute_ReturnsOneAttribute() |
||||||
|
{ |
||||||
|
CreateParameter( |
||||||
|
"using System;\r\n" + |
||||||
|
"public class MyClass {\r\n" + |
||||||
|
" public void MyMethod([Obsolete] int parameter) {}\r\n" + |
||||||
|
"}"); |
||||||
|
|
||||||
|
global::EnvDTE.CodeElements attributes = parameter.Attributes; |
||||||
|
|
||||||
|
CodeAttribute2 attribute = parameter.Attributes.FirstCodeAttribute2OrDefault(); |
||||||
|
Assert.AreEqual(1, attributes.Count); |
||||||
|
Assert.AreEqual("System.ObsoleteAttribute", attribute.FullName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,51 +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.EnvDTE;
|
|
||||||
//using NUnit.Framework;
|
|
||||||
//using PackageManagement.Tests.Helpers;
|
|
||||||
//
|
|
||||||
//namespace PackageManagement.Tests.EnvDTE
|
|
||||||
//{
|
|
||||||
// [TestFixture]
|
|
||||||
// public class CodeParameterTests
|
|
||||||
// {
|
|
||||||
// ParameterHelper helper;
|
|
||||||
// CodeParameter parameter;
|
|
||||||
//
|
|
||||||
// [SetUp]
|
|
||||||
// public void Init()
|
|
||||||
// {
|
|
||||||
// helper = new ParameterHelper();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void CreateParameter()
|
|
||||||
// {
|
|
||||||
// parameter = new CodeParameter(null, helper.Parameter);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// [Test]
|
|
||||||
// public void Kind_Parameter_ReturnsParameter()
|
|
||||||
// {
|
|
||||||
// CreateParameter();
|
|
||||||
//
|
|
||||||
// global::EnvDTE.vsCMElement kind = parameter.Kind;
|
|
||||||
//
|
|
||||||
// Assert.AreEqual(global::EnvDTE.vsCMElement.vsCMElementParameter, kind);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// [Test]
|
|
||||||
// public void Attributes_ParameterHasOneAttribute_ReturnsOneAttribute()
|
|
||||||
// {
|
|
||||||
// CreateParameter();
|
|
||||||
// helper.AddAttributeToParameter("System.Web.Mvc.BindAttribute");
|
|
||||||
//
|
|
||||||
// global::EnvDTE.CodeElements attributes = parameter.Attributes;
|
|
||||||
//
|
|
||||||
// CodeAttribute2 attribute = parameter.Attributes.FirstCodeAttribute2OrDefault();
|
|
||||||
// Assert.AreEqual(1, attributes.Count);
|
|
||||||
// Assert.AreEqual("System.Web.Mvc.BindAttribute", attribute.FullName);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@ -1,51 +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.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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
Loading…
Reference in new issue