-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor unnecessary try/catch (#4057)
Co-authored-by: Amaury Levé <[email protected]>
- Loading branch information
1 parent
c203c46
commit bde4e5a
Showing
9 changed files
with
159 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
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
28 changes: 28 additions & 0 deletions
28
src/TestFramework/TestFramework/Interfaces/EmptyDataSourceExceptionInfoExtensions.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,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Globalization; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
internal static class EmptyDataSourceExceptionInfoExtensions | ||
{ | ||
internal static ArgumentException GetExceptionForEmptyDataSource(this ITestDataSource dataSource, MethodInfo testMethodInfo) | ||
=> dataSource is ITestDataSourceEmptyDataSourceExceptionInfo info | ||
? info.GetExceptionForEmptyDataSource(testMethodInfo) | ||
: new ArgumentException( | ||
string.Format( | ||
CultureInfo.InvariantCulture, | ||
FrameworkMessages.DynamicDataIEnumerableEmpty, | ||
"GetData", | ||
dataSource.GetType().Name)); | ||
|
||
private static ArgumentException GetExceptionForEmptyDataSource(this ITestDataSourceEmptyDataSourceExceptionInfo info, MethodInfo testMethodInfo) | ||
=> new( | ||
string.Format( | ||
CultureInfo.InvariantCulture, | ||
FrameworkMessages.DynamicDataIEnumerableEmpty, | ||
info.GetPropertyOrMethodNameForEmptyDataSourceException(), | ||
info.GetPropertyOrMethodContainerTypeNameForEmptyDataSourceException(testMethodInfo))); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/TestFramework/TestFramework/Interfaces/ITestDataSourceEmptyDataSourceExceptionInfo.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,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Reflection; | ||
|
||
namespace Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
internal interface ITestDataSourceEmptyDataSourceExceptionInfo | ||
{ | ||
/// <summary> | ||
/// Returns the method/property name accessed by this data source. | ||
/// For example, for DynamicDataAttribute, that will be attribute argument. | ||
/// </summary> | ||
string? GetPropertyOrMethodNameForEmptyDataSourceException(); | ||
|
||
/// <summary> | ||
/// Returns the type name on which the method/property accessed by this data source exists. | ||
/// </summary> | ||
string? GetPropertyOrMethodContainerTypeNameForEmptyDataSourceException(MethodInfo testMethodInfo); | ||
} |
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
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
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