Browse Source
The T4MVC template checks whether a parameter is optional so it can determine which controller action methods can be called without any parameters.pull/28/head
9 changed files with 193 additions and 7 deletions
@ -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,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,44 @@ |
|||||||
|
// 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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue