2
// SupportsIndexingCriterionTests.cs
5
// Simon Lindgren <simon.n.lindgren@gmail.com>
7
// Copyright (c) 2012 Simon Lindgren
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using NUnit.Framework;
28
using ICSharpCode.NRefactory.CSharp.CodeActions;
29
using ICSharpCode.NRefactory.TypeSystem;
30
using System.Collections.Generic;
31
using ICSharpCode.NRefactory.CSharp.Refactoring;
32
using ICSharpCode.NRefactory.CSharp.Resolver;
34
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
37
public class SupportsIndexingCriterionTests
39
ITypeResolveContext typeResolveContext;
43
ICompilation compilation;
48
compilation = TestRefactoringContext.Create("").Compilation;
49
typeResolveContext = compilation.TypeResolveContext;
50
intType = GetIType<int>();
55
return typeof(T).ToTypeReference().Resolve(typeResolveContext);
58
void AssertMatches(IType candidateType, IType elementType, bool isWriteAccess, params IType[] indexTypes)
60
var criterion = new SupportsIndexingCriterion(elementType, indexTypes, CSharpConversions.Get(compilation), isWriteAccess);
61
Assert.IsTrue(criterion.SatisfiedBy(candidateType));
64
void AssertDoesNotMatch(IType candidateType, IType elementType, bool isWriteAccess, params IType[] indexTypes)
66
var criterion = new SupportsIndexingCriterion(elementType, indexTypes, CSharpConversions.Get(compilation), isWriteAccess);
67
Assert.IsFalse(criterion.SatisfiedBy(candidateType));
71
public void ListWithOneIntegerIndex()
73
var intListType = GetIType<IList<int>>();
74
AssertMatches(intListType, intType, false, intType);
75
AssertMatches(intListType, intType, true, intType);
79
public void ListWithTwoIntegerIndexes()
81
var intListType = GetIType<IList<int>>();
82
AssertDoesNotMatch(intListType, intType, false, intType, intType);
83
AssertDoesNotMatch(intListType, intType, true, intType, intType);
87
public void ObjectCandidate()
89
AssertDoesNotMatch(GetIType<object>(), intType, false, intType);
90
AssertDoesNotMatch(GetIType<object>(), intType, true, intType);