2
// Unit Tests for DoNotExposeNestedGenericSignaturesRule
5
// Sebastien Pouliot <sebastien@ximian.com>
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using System.Collections;
31
using System.Collections.Generic;
33
using System.Xml.Linq;
37
using Gendarme.Framework;
38
using Gendarme.Rules.Design.Generic;
40
using NUnit.Framework;
41
using Test.Rules.Fixtures;
43
namespace Test.Rules.Design.Generic {
46
public class DoNotExposeNestedGenericSignaturesTest : MethodRuleTestFixture<DoNotExposeNestedGenericSignaturesRule> {
48
public class IntegerCollection : List<int> {
51
public class Generic<T> {
53
public ICollection NonGenericReturnValue ()
58
public ICollection<string> GenericReturnValue ()
63
public ICollection<KeyValuePair<T, T>> NestedReturnValue ()
68
public void NonGenericParameter (ICollection value)
72
public void GenericParameter (ICollection<int> value)
76
public void NestedParameter (KeyValuePair<T, ICollection<int>> value)
80
public void UnnestedParameter (KeyValuePair<T, IntegerCollection> value)
84
public void TwoNestedParameters (KeyValuePair<T, ICollection<int>> value,
85
int max, int min, ICollection<KeyValuePair<T,string>> template)
89
protected ICollection<KeyValuePair<T, T>> All (KeyValuePair<T, ICollection<int>> value,
90
int max, int min, ICollection<KeyValuePair<T, string>> template)
97
public void ReturnValue ()
99
AssertRuleSuccess<Generic<int>> ("NonGenericReturnValue");
100
AssertRuleSuccess<Generic<int>> ("GenericReturnValue");
101
AssertRuleFailure<Generic<int>> ("NestedReturnValue", 1);
105
public void Parameters ()
107
AssertRuleSuccess<Generic<int>> ("NonGenericParameter");
108
AssertRuleSuccess<Generic<int>> ("GenericParameter");
109
AssertRuleFailure<Generic<int>> ("NestedParameter", 1);
110
AssertRuleSuccess<Generic<int>> ("UnnestedParameter");
111
AssertRuleFailure<Generic<int>> ("TwoNestedParameters", 2);
117
AssertRuleFailure<Generic<int>> ("All", 3);
120
// adapted from XmlResultWriter
122
public XElement CreateDefects ()
124
var query = from n in Runner.Defects
125
group n by n.Rule into a
126
//gmcs bug// orderby a.Key.Name
130
group o by o.Target into r
131
orderby (r.Key == null ? String.Empty : a.Key.Name)
138
return new XElement ("results",
140
select new XElement ("rule",
141
CreateRuleDetails (value.Rule),
142
from v2 in value.Value
143
select new XElement ("target",
144
CreateTargetDetails (v2.Target),
145
from Defect defect in v2.Value
146
select CreateDefect (defect))));
149
static XObject [] CreateRuleDetails (IRule rule)
154
static XObject [] CreateTargetDetails (IMetadataTokenProvider target)
159
static XElement CreateDefect (Defect defect)
167
AssertRuleSuccess<DoNotExposeNestedGenericSignaturesTest> ("CreateDefects");
170
public IEnumerable<int?> NullableReturnValue ()
175
public void NullableParameter (ICollection<DateTime?> value)
180
public void Nullable ()
182
AssertRuleSuccess<DoNotExposeNestedGenericSignaturesTest> ("NullableReturnValue");
183
AssertRuleSuccess<DoNotExposeNestedGenericSignaturesTest> ("NullableParameter");