diff --git a/tests/UpgradeAssistant.Mappings.Tests/ApiMapValidationTests.cs b/tests/UpgradeAssistant.Mappings.Tests/ApiMapValidationTests.cs
index 411ea4540..c47c94454 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/ApiMapValidationTests.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/ApiMapValidationTests.cs
@@ -2,15 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text.Json;
-
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
public partial class ValidationTests
{
- private static readonly string[] Kinds = new string[] { "property", "method", "namespace", "type", "xmlnamespace" };
- private static readonly string[] States = new string[] { "NotImplemented", "Removed", "Replaced" };
+ private static readonly string[] Kinds = ["property", "method", "namespace", "type", "xmlnamespace"];
+ private static readonly string[] States = ["NotImplemented", "Removed", "Replaced"];
[TestMethod]
public void ValidateApiMaps()
@@ -25,7 +24,7 @@ public void ValidateApiMaps()
foreach (var path in jsonFiles)
{
var fileName = Path.GetFileName(path);
-
+
if (fileName.Equals("apimap.json", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".apimap.json", StringComparison.OrdinalIgnoreCase))
{
AssertApiMap(options, path);
diff --git a/tests/UpgradeAssistant.Mappings.Tests/MetadataValidationTests.cs b/tests/UpgradeAssistant.Mappings.Tests/MetadataValidationTests.cs
index d5f05c4a5..fa725a342 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/MetadataValidationTests.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/MetadataValidationTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text.Json;
-
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
@@ -70,7 +69,7 @@ private static void AssertMetadataFile(JsonSerializerOptions options, string ful
else if (property.NameEquals("order"))
{
AssertPropertyType(relativePath, string.Empty, property, JsonValueKind.Number);
- Assert.IsTrue(property.Value.TryGetInt32(out int order), $"Failed to parse \"{property.Name}\" property in `{relativePath}': {property}");
+ Assert.IsTrue(property.Value.TryGetInt32(out var order), $"Failed to parse \"{property.Name}\" property in `{relativePath}': {property}");
Assert.IsTrue(order >= 0, $"`{relativePath}' - [\"{property.Name}\"] must be greater than or equal to 0.");
}
else
diff --git a/tests/UpgradeAssistant.Mappings.Tests/PackageMapValidationTests.cs b/tests/UpgradeAssistant.Mappings.Tests/PackageMapValidationTests.cs
index 18d09bbe0..52acc9dfd 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/PackageMapValidationTests.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/PackageMapValidationTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text.Json;
-
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
@@ -37,7 +36,7 @@ private static void AssertPackageMapEntry(string relativePath, string packagePat
foreach (var framework in package.Frameworks)
{
var count = framework.Value.Count;
- int index = 0;
+ var index = 0;
foreach (var frameworkEntry in framework.Value)
{
@@ -85,7 +84,7 @@ private static void AssertPackageMap(JsonSerializerOptions options, string fullP
if (config.Packages != null)
{
- int index = 0;
+ var index = 0;
foreach (var package in config.Packages)
{
diff --git a/tests/UpgradeAssistant.Mappings.Tests/SchemaValidationTests.cs b/tests/UpgradeAssistant.Mappings.Tests/SchemaValidationTests.cs
index 7aafbe96a..9cb732bfc 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/SchemaValidationTests.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/SchemaValidationTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text.Json;
-
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
@@ -36,10 +35,10 @@ public void ValidateSchemas()
{
AssertConfigSchema(options, path);
}
- else
+ /*else
{
- //Assert.Fail($"Unknown file type: {fileName}");
- }
+ Assert.Fail($"Unknown file type: {fileName}");
+ }*/
}
}
@@ -64,7 +63,7 @@ private static void AssertPropertyTypeIsBoolean(string relativePath, string elem
{
var propertyPath = GetPropertyPath(elementPath, property);
- Assert.IsTrue(property.Value.ValueKind == JsonValueKind.True || property.Value.ValueKind == JsonValueKind.False, $"The {propertyPath} property in `{relativePath}' is expected to be a boolean.");
+ Assert.IsTrue(property.Value.ValueKind is JsonValueKind.True or JsonValueKind.False, $"The {propertyPath} property in `{relativePath}' is expected to be a boolean.");
}
private static void AssertUnknownProperty(string relativePath, string elementPath, JsonProperty property)
@@ -74,7 +73,7 @@ private static void AssertUnknownProperty(string relativePath, string elementPat
private static void AssertPackageMapEntryFramework(string relativePath, string frameworkPath, JsonElement framework)
{
- int index = 0;
+ var index = 0;
foreach (var element in framework.EnumerateArray())
{
@@ -135,7 +134,7 @@ private static void AssertPackageMapEntry(string relativePath, string elementPat
private static void AssertPackageMapPackages(string relativePath, string packagesPath, JsonElement packages)
{
- int index = 0;
+ var index = 0;
foreach (var element in packages.EnumerateArray())
{
@@ -224,7 +223,7 @@ private static void AssertApiMapEntry(string relativePath, string elementPath, J
AssertPropertyType(relativePath, elementPath, property, JsonValueKind.Array);
var propertyPath = GetPropertyPath(elementPath, property);
- int index = 0;
+ var index = 0;
foreach (var paramElement in property.Value.EnumerateArray())
{
diff --git a/tests/UpgradeAssistant.Mappings.Tests/TestHelper.cs b/tests/UpgradeAssistant.Mappings.Tests/TestHelper.cs
index d726023a9..40676331b 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/TestHelper.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/TestHelper.cs
@@ -3,7 +3,7 @@
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
-static class TestHelper
+internal static class TestHelper
{
public static readonly string MappingsDir;
diff --git a/tests/UpgradeAssistant.Mappings.Tests/TraitToken.cs b/tests/UpgradeAssistant.Mappings.Tests/TraitToken.cs
index c4a074a87..9e00b5e31 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/TraitToken.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/TraitToken.cs
@@ -1,14 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-using System.Collections.Generic;
-
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
internal class TraitToken
{
- private static readonly char[] DotSeparator = new[] { '.' };
+ private static readonly char[] DotSeparator = ['.'];
public static string? GetPropertyName(TraitToken token, string id)
{
@@ -48,8 +45,8 @@ public static bool TryParse(string input, out TraitToken? token)
return false;
}
- int i = 0;
- int begin = i;
+ var i = 0;
+ var begin = i;
while (i < input.Length && !IsOperatorCharacter(input[i])) { i++; }
@@ -58,7 +55,7 @@ public static bool TryParse(string input, out TraitToken? token)
return false;
}
- string key = input.Substring(begin, i).Trim();
+ var key = input.Substring(begin, i).Trim();
if (string.IsNullOrEmpty(key))
{
return false;
@@ -68,13 +65,13 @@ public static bool TryParse(string input, out TraitToken? token)
while (i < input.Length && IsOperatorCharacter(input[i])) { i++; }
- string @operator = input.Substring(begin, i - begin);
+ var @operator = input.Substring(begin, i - begin);
if (!Operators.Contains(@operator))
{
return false;
}
- string value = i < input.Length ? input.Substring(i) : string.Empty;
+ var value = i < input.Length ? input.Substring(i) : string.Empty;
token = new TraitToken(key, value.Trim(), @operator);
@@ -112,7 +109,7 @@ public string? TraitName
if (_traitName is null)
{
var parts = Key.Trim().Split(DotSeparator, StringSplitOptions.RemoveEmptyEntries);
- if (parts.Length < 1 || parts.Length > 2)
+ if (parts.Length is < 1 or > 2)
{
return null;
}
@@ -138,7 +135,7 @@ public string? PropertyName
if (_propertyName is null)
{
var parts = Key.Trim().Split(DotSeparator, StringSplitOptions.RemoveEmptyEntries);
- if (parts.Length < 1 || parts.Length > 2)
+ if (parts.Length is < 1 or > 2)
{
return null;
}
diff --git a/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionParser.cs b/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionParser.cs
index f43d0941c..b9f51d385 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionParser.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionParser.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
internal struct TraitsExpressionParser
@@ -85,7 +83,7 @@ private void ValidateAndTerm()
///
private void ValidateTerm()
{
- int notCount = 0;
+ var notCount = 0;
while (_tokenizer.Peek() == "!")
{
_tokenizer.Next();
@@ -107,7 +105,7 @@ private void ValidateTerm()
}
else if (_tokenizer.Peek() != null && IsSymbolCharacter(_tokenizer.Peek()![0]))
{
- string ident = _tokenizer.Next()!;
+ var ident = _tokenizer.Next()!;
}
else if (_tokenizer.Peek() != null && _tokenizer.Peek()![0] == '{')
{
@@ -122,7 +120,7 @@ private void ValidateTerm()
///
/// Process special tokens like {key:value} where ':' should be =, <, >, <=, >=, !=.
///
- private void ProcessToken(string input)
+ private static void ProcessToken(string input)
{
input = input.TrimStart('{').TrimEnd('}');
@@ -193,7 +191,7 @@ internal Tokenizer(string input)
// the Peek() doesn't impact the token stream.
if (_peeked != null)
{
- string token = _peeked;
+ var token = _peeked;
_peeked = null;
return token;
}
@@ -211,59 +209,63 @@ internal Tokenizer(string input)
if (IsSymbolCharacter(Input[Position]))
{
- int begin = Position;
+ var begin = Position;
while (Position < Input.Length && IsSymbolCharacter(Input[Position]))
{
Position++;
}
- int end = Position;
+ var end = Position;
return Input.Substring(begin, end - begin);
}
- else if (Input[Position] == '&' || Input[Position] == '+') // we prefer & but also accept + so that XML manifest files don't have to write the & escape sequence.
+
+ if (Input[Position] == '&' || Input[Position] == '+') // we prefer & but also accept + so that XML manifest files don't have to write the & escape sequence.
{
Position++;
return "&"; // always return '&' to simplify the parser logic by consolidating on only one of the two possible operators.
}
- else if (Input[Position] == '|')
+
+ if (Input[Position] == '|')
{
Position++;
return "|";
}
- else if (Input[Position] == '(')
+
+ if (Input[Position] == '(')
{
Position++;
return "(";
}
- else if (Input[Position] == ')')
+
+ if (Input[Position] == ')')
{
Position++;
return ")";
}
- else if (Input[Position] == '!')
+
+ if (Input[Position] == '!')
{
Position++;
return "!";
}
- else if (Input[Position] == '{')
+
+ if (Input[Position] == '{')
{
// read special tokens like {xxx:vvv}
- int begin = Position;
+ var begin = Position;
while (Position < Input.Length && Input[Position] != '}')
{
Position++;
}
- int end = Position;
+ var end = Position;
Position++;
return Input.Substring(begin, end - begin);
}
- else
- {
- throw new TraitsExpressionSyntaxException(string.Format(InvalidTraitExpression, Position, Input));
- }
+
+ throw new TraitsExpressionSyntaxException(string.Format(InvalidTraitExpression, Position, Input));
}
///
diff --git a/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionSyntaxException.cs b/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionSyntaxException.cs
index 1d359138c..d362c9744 100644
--- a/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionSyntaxException.cs
+++ b/tests/UpgradeAssistant.Mappings.Tests/TraitsExpressionSyntaxException.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace Microsoft.UpgradeAssistant.Mappings.Tests;
internal class TraitsExpressionSyntaxException : FormatException