-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code coverage: use nuget package (#1737)
Co-authored-by: Costin Zaharia <[email protected]>
- Loading branch information
1 parent
d0e6ae8
commit 5de4dc7
Showing
11 changed files
with
272 additions
and
787 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
Tests/SonarScanner.MSBuild.TFS.Test/ApplicationCultureInfoTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* SonarScanner for .NET | ||
* Copyright (C) 2016-2023 SonarSource SA | ||
* mailto: info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using System; | ||
using System.Globalization; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using SonarScanner.MSBuild.Common; | ||
|
||
namespace SonarScanner.MSBuild.TFS.Tests | ||
{ | ||
[TestClass] | ||
[DoNotParallelize] | ||
public class ApplicationCultureInfoTests | ||
{ | ||
[TestMethod] | ||
public void ApplicationCultureInfoSetAndResetCultureWithUsing() | ||
{ | ||
var previous = CultureInfo.DefaultThreadCurrentCulture; | ||
var enUs = CultureInfo.GetCultureInfo("en-US"); | ||
var deDe = CultureInfo.GetCultureInfo("de-DE"); | ||
CultureInfo.DefaultThreadCurrentCulture = deDe; | ||
try | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(deDe); | ||
using (new ApplicationCultureInfo(enUs)) | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(enUs); | ||
} | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(deDe); | ||
} | ||
finally | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture = previous; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ApplicationCultureInfoSetAndResetCultureManual() | ||
{ | ||
var previous = CultureInfo.DefaultThreadCurrentCulture; | ||
var enUs = CultureInfo.GetCultureInfo("en-US"); | ||
var deDe = CultureInfo.GetCultureInfo("de-DE"); | ||
CultureInfo.DefaultThreadCurrentCulture = deDe; | ||
try | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(deDe); | ||
var sut = new ApplicationCultureInfo(enUs); | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(enUs); | ||
sut.Dispose(); | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(deDe); | ||
} | ||
finally | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture = previous; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(InvalidOperationException))] | ||
public void ApplicationCultureInfoSetAndResetCultureOnFailure() | ||
{ | ||
var previous = CultureInfo.DefaultThreadCurrentCulture; | ||
var enUs = CultureInfo.GetCultureInfo("en-US"); | ||
var deDe = CultureInfo.GetCultureInfo("de-DE"); | ||
CultureInfo.DefaultThreadCurrentCulture = deDe; | ||
try | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(deDe); | ||
using (new ApplicationCultureInfo(enUs)) | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(enUs); | ||
throw new InvalidOperationException(); | ||
} | ||
} | ||
finally | ||
{ | ||
CultureInfo.DefaultThreadCurrentCulture.Should().Be(deDe); | ||
CultureInfo.DefaultThreadCurrentCulture = previous; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.