2
// ConditionalToNullCoalescingInspectorTests.cs
5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
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
28
using NUnit.Framework;
29
using ICSharpCode.NRefactory.CSharp.Refactoring;
30
using ICSharpCode.NRefactory.CSharp.CodeActions;
32
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
35
public class ConditionalToNullCoalescingInspectorTests : InspectionActionTestBase
38
public void TestInspectorCase1 ()
40
var input = @"class Foo
44
string c = str != null ? str : ""default"";
47
TestRefactoringContext context;
48
var issues = GetIssues (new ConditionalToNullCoalescingIssue (), input, out context);
49
Assert.AreEqual (1, issues.Count);
51
CheckFix (context, issues [0], @"class Foo
55
string c = str ?? ""default"";
62
public void TestInspectorCase2 ()
64
var input = @"class Foo
68
string c = null != str ? str : ""default"";
71
TestRefactoringContext context;
72
var issues = GetIssues (new ConditionalToNullCoalescingIssue (), input, out context);
73
Assert.AreEqual (1, issues.Count);
75
CheckFix (context, issues [0], @"class Foo
79
string c = str ?? ""default"";
86
public void TestInspectorCase3 ()
88
var input = @"class Foo
92
string c = null == str ? ""default"" : str;
95
TestRefactoringContext context;
96
var issues = GetIssues (new ConditionalToNullCoalescingIssue (), input, out context);
97
Assert.AreEqual (1, issues.Count);
99
CheckFix (context, issues [0], @"class Foo
101
void Bar (string str)
103
string c = str ?? ""default"";
109
public void TestInspectorCase4 ()
111
var input = @"class Foo
113
void Bar (string str)
115
string c = str == null ? ""default"" : str;
118
TestRefactoringContext context;
119
var issues = GetIssues (new ConditionalToNullCoalescingIssue (), input, out context);
120
Assert.AreEqual (1, issues.Count);
122
CheckFix (context, issues [0], @"class Foo
124
void Bar (string str)
126
string c = str ?? ""default"";