Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/NRefactory.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Ungureanu <marius.ungureanu@xamarin.com>2014-04-08 22:14:47 +0400
committerMarius Ungureanu <marius.ungureanu@xamarin.com>2014-04-08 22:16:08 +0400
commit57898706821c28dc9c645cc477a35aea6a674b1a (patch)
treee78fe4b9d7f098f360a9441f8660b8f0a6835edd /ICSharpCode.NRefactory.Tests
parent28d04aec57712fa57da8815172334cba43c92d2c (diff)
[CodeIssues] Add simplified versions Math functions.
Diffstat (limited to 'ICSharpCode.NRefactory.Tests')
-rw-r--r--ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToAverageIssueTests.cs77
-rw-r--r--ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMaxIssueTests.cs77
-rw-r--r--ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMinIssueTests.cs77
-rw-r--r--ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToSumIssueTests.cs77
-rw-r--r--ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj4
5 files changed, 312 insertions, 0 deletions
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToAverageIssueTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToAverageIssueTests.cs
new file mode 100644
index 00000000..4860400e
--- /dev/null
+++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToAverageIssueTests.cs
@@ -0,0 +1,77 @@
+//
+// ReplaceWithSingleCallToAverageTests.cs
+//
+// Author:
+// Marius Ungureanu <marius.ungureanu@xamarin.com>
+//
+// Copyright (c) 2014 Xamarin <http://xamarin.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using ICSharpCode.NRefactory.CSharp.Refactoring;
+using ICSharpCode.NRefactory.CSharp.CodeActions;
+
+namespace ICSharpCode.NRefactory.CSharp.CodeIssues
+{
+ [TestFixture]
+ public class ReplaceWithSingleCallToAverageIssueTests : InspectionActionTestBase
+ {
+ [Test]
+ public void TestSimpleCase()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Select (x => x * 2).Average ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToAverageIssue(), input, out context);
+ Assert.AreEqual(1, issues.Count);
+ CheckFix(context, issues, @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Average (x => x * 2);
+ }
+}");
+ }
+
+ [Test]
+ public void TestDisable()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+// ReSharper disable ReplaceWithSingleCallToAverage
+ var bla = arr.Select (x => x * 2).Average ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToAverageIssue(), input, out context);
+ Assert.AreEqual(0, issues.Count);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMaxIssueTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMaxIssueTests.cs
new file mode 100644
index 00000000..6ed64113
--- /dev/null
+++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMaxIssueTests.cs
@@ -0,0 +1,77 @@
+//
+// ReplaceWithSingleCallToMaxTests.cs
+//
+// Author:
+// Marius Ungureanu <marius.ungureanu@xamarin.com>
+//
+// Copyright (c) 2014 Xamarin <http://xamarin.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using ICSharpCode.NRefactory.CSharp.Refactoring;
+using ICSharpCode.NRefactory.CSharp.CodeActions;
+
+namespace ICSharpCode.NRefactory.CSharp.CodeIssues
+{
+ [TestFixture]
+ public class ReplaceWithSingleCallToMaxIssueTests : InspectionActionTestBase
+ {
+ [Test]
+ public void TestSimpleCase()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Select (x => x * 2).Max ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToMaxIssue(), input, out context);
+ Assert.AreEqual(1, issues.Count);
+ CheckFix(context, issues, @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Max (x => x * 2);
+ }
+}");
+ }
+
+ [Test]
+ public void TestDisable()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+// ReSharper disable ReplaceWithSingleCallToMax
+ var bla = arr.Select (x => x * 2).Max ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToMaxIssue(), input, out context);
+ Assert.AreEqual(0, issues.Count);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMinIssueTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMinIssueTests.cs
new file mode 100644
index 00000000..d0637960
--- /dev/null
+++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToMinIssueTests.cs
@@ -0,0 +1,77 @@
+//
+// ReplaceWithSingleCallToMinTests.cs
+//
+// Author:
+// Marius Ungureanu <marius.ungureanu@xamarin.com>
+//
+// Copyright (c) 2014 Xamarin <http://xamarin.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using ICSharpCode.NRefactory.CSharp.Refactoring;
+using ICSharpCode.NRefactory.CSharp.CodeActions;
+
+namespace ICSharpCode.NRefactory.CSharp.CodeIssues
+{
+ [TestFixture]
+ public class ReplaceWithSingleCallToMinIssueTests : InspectionActionTestBase
+ {
+ [Test]
+ public void TestSimpleCase()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Select (x => x * 2).Min ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToMinIssue(), input, out context);
+ Assert.AreEqual(1, issues.Count);
+ CheckFix(context, issues, @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Min (x => x * 2);
+ }
+}");
+ }
+
+ [Test]
+ public void TestDisable()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+// ReSharper disable ReplaceWithSingleCallToMin
+ var bla = arr.Select (x => x * 2).Min ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToMinIssue(), input, out context);
+ Assert.AreEqual(0, issues.Count);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToSumIssueTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToSumIssueTests.cs
new file mode 100644
index 00000000..9f953231
--- /dev/null
+++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ReplaceWithSingleCallToSumIssueTests.cs
@@ -0,0 +1,77 @@
+//
+// ReplaceWithSingleCallToSumTests.cs
+//
+// Author:
+// Marius Ungureanu <marius.ungureanu@xamarin.com>
+//
+// Copyright (c) 2014 Xamarin <http://xamarin.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using ICSharpCode.NRefactory.CSharp.Refactoring;
+using ICSharpCode.NRefactory.CSharp.CodeActions;
+
+namespace ICSharpCode.NRefactory.CSharp.CodeIssues
+{
+ [TestFixture]
+ public class ReplaceWithSingleCallToSumIssueTests : InspectionActionTestBase
+ {
+ [Test]
+ public void TestSimpleCase()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Select (x => x * 2).Sum ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToSumIssue(), input, out context);
+ Assert.AreEqual(1, issues.Count);
+ CheckFix(context, issues, @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+ var bla = arr.Sum (x => x * 2);
+ }
+}");
+ }
+
+ [Test]
+ public void TestDisable()
+ {
+ var input = @"using System.Linq;
+public class CSharpDemo {
+ public void Bla () {
+ int[] arr;
+// ReSharper disable ReplaceWithSingleCallToSum
+ var bla = arr.Select (x => x * 2).Sum ();
+ }
+}";
+
+ TestRefactoringContext context;
+ var issues = GetIssues(new ReplaceWithSingleCallToSumIssue(), input, out context);
+ Assert.AreEqual(0, issues.Count);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj b/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
index 3f9cd2b4..4f089f7d 100644
--- a/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
+++ b/ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
@@ -618,6 +618,10 @@
<Compile Include="CSharp\CodeIssues\StaticEventSubscriptionIssueTests.cs" />
<Compile Include="CSharp\CodeActions\CS1105ExtensionMethodMustBeDeclaredStaticActionTests.cs" />
<Compile Include="CSharp\CodeIssues\UnmatchedSizeSpeicificationInArrayCreationTests.cs" />
+ <Compile Include="CSharp\CodeIssues\ReplaceWithSingleCallToMaxIssueTests.cs" />
+ <Compile Include="CSharp\CodeIssues\ReplaceWithSingleCallToMinIssueTests.cs" />
+ <Compile Include="CSharp\CodeIssues\ReplaceWithSingleCallToSumIssueTests.cs" />
+ <Compile Include="CSharp\CodeIssues\ReplaceWithSingleCallToAverageIssueTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\cecil\Mono.Cecil.csproj">