Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: ObsoleteAttribute for soon to be removed API #1062

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]

### Added
- `ObsoleteAttribute` for API that will be removed with `v2`.

## [1.19.14] - 2023-04-26

### Fixed
Expand Down
1 change: 1 addition & 0 deletions src/bunit.core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class EnumerableExtensions
/// <summary>
/// Returns true if the numerable is null or empty.
/// </summary>
[Obsolete("Will be removed in v2.")]
public static bool IsNullOrEmpty<T>([NotNullWhen(false)] this IEnumerable<T>? enumerable)
{
return enumerable is null || !enumerable.Any();
Expand Down
2 changes: 2 additions & 0 deletions src/bunit.web/Asserting/DiffAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class DiffAssertExtensions
/// </summary>
/// <param name="diffs">The collection to be inspected.</param>
/// <returns>The expected single <see cref="IDiff"/> in the collection.</returns>
[Obsolete("Will be removed in v2.")]
public static IDiff ShouldHaveSingleChange(this IEnumerable<IDiff> diffs)
{
if (diffs is null)
Expand All @@ -39,6 +40,7 @@ public static IDiff ShouldHaveSingleChange(this IEnumerable<IDiff> diffs)
/// <param name="diffs">The collection to be inspected.</param>
/// <param name="diffInspectors">The <see cref="IDiff"/> inspectors, which inspect each <see cref="IDiff"/> in turn.
/// The total number of <see cref="IDiff"/> inspectors must exactly match the number of <see cref="IDiff"/>s in the collection.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldHaveChanges(this IEnumerable<IDiff> diffs, params Action<IDiff>[] diffInspectors)
{
if (diffs is null)
Expand Down
3 changes: 3 additions & 0 deletions src/bunit.web/Asserting/ShouldBeAdditionAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class ShouldBeAdditionAssertExtensions
/// <param name="actualChange">The change to verify.</param>
/// <param name="expectedChange">The expected additions to verify against.</param>
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeAddition(this IDiff actualChange, string expectedChange, string? userMessage = null)
{
if (actualChange is null)
Expand Down Expand Up @@ -48,6 +49,7 @@ public static void ShouldBeAddition(this IDiff actualChange, string expectedChan
/// <param name="actualChange">The change to verify.</param>
/// <param name="expectedChange">The expected additions to verify against.</param>
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeAddition(this IDiff actualChange, IRenderedFragment expectedChange, string? userMessage = null)
{
if (expectedChange is null)
Expand All @@ -63,6 +65,7 @@ public static void ShouldBeAddition(this IDiff actualChange, IRenderedFragment e
/// <param name="actualChange">The change to verify.</param>
/// <param name="expectedChange">The expected additions to verify against.</param>
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeAddition(this IDiff actualChange, INodeList expectedChange, string? userMessage = null)
{
if (actualChange is null)
Expand Down
3 changes: 3 additions & 0 deletions src/bunit.web/Asserting/ShouldBeRemovalAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class ShouldBeRemovalAssertExtensions
/// <param name="actualChange">The change to verify.</param>
/// <param name="expectedChange">The expected removal to verify against.</param>
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeRemoval(this IDiff actualChange, string expectedChange, string? userMessage = null)
{
if (actualChange is null)
Expand Down Expand Up @@ -48,6 +49,7 @@ public static void ShouldBeRemoval(this IDiff actualChange, string expectedChang
/// <param name="actualChange">The change to verify.</param>
/// <param name="expectedChange">The expected removal to verify against.</param>
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeRemoval(this IDiff actualChange, IRenderedFragment expectedChange, string? userMessage = null)
{
if (expectedChange is null)
Expand All @@ -63,6 +65,7 @@ public static void ShouldBeRemoval(this IDiff actualChange, IRenderedFragment ex
/// <param name="actualChange">The change to verify.</param>
/// <param name="expectedChange">The expected removal to verify against.</param>
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeRemoval(this IDiff actualChange, INodeList expectedChange, string? userMessage = null)
{
if (actualChange is null)
Expand Down
5 changes: 5 additions & 0 deletions src/bunit.web/Asserting/ShouldBeTextChangeAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class ShouldBeTextChangeAssertExtensions
/// <param name="diffs">The list of diffs to verify against.</param>
/// <param name="expectedChange">The expected text change.</param>
/// <param name="userMessage">A custom error message to show if the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldHaveSingleTextChange(this IEnumerable<IDiff> diffs, string expectedChange, string? userMessage = null)
{
DiffAssertExtensions.ShouldHaveSingleChange(diffs).ShouldBeTextChange(expectedChange, userMessage);
Expand All @@ -27,6 +28,7 @@ public static void ShouldHaveSingleTextChange(this IEnumerable<IDiff> diffs, str
/// <param name="actualChange">The diff to verify.</param>
/// <param name="expectedChange">The expected text change.</param>
/// <param name="userMessage">A custom error message to show if the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeTextChange(this IDiff actualChange, string expectedChange, string? userMessage = null)
{
if (actualChange is null)
Expand Down Expand Up @@ -55,6 +57,7 @@ public static void ShouldBeTextChange(this IDiff actualChange, string expectedCh
/// <param name="actualChange">The diff to verify.</param>
/// <param name="expectedChange">The rendered fragment containing the expected text change.</param>
/// <param name="userMessage">A custom error message to show if the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeTextChange(this IDiff actualChange, IRenderedFragment expectedChange, string? userMessage = null)
{
if (expectedChange is null)
Expand All @@ -68,6 +71,7 @@ public static void ShouldBeTextChange(this IDiff actualChange, IRenderedFragment
/// <param name="actualChange">The diff to verify.</param>
/// <param name="expectedChange">The node list containing the expected text change.</param>
/// <param name="userMessage">A custom error message to show if the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeTextChange(this IDiff actualChange, INodeList expectedChange, string? userMessage = null)
{
if (actualChange is null)
Expand All @@ -94,6 +98,7 @@ public static void ShouldBeTextChange(this IDiff actualChange, INodeList expecte
/// <param name="expectedAttrName">The expected name of the changed attribute.</param>
/// <param name="expectedAttrValue">The expected value of the changed attribute.</param>
/// <param name="userMessage">A custom user message to show when the verification fails.</param>
[Obsolete("Will be removed in v2.")]
public static void ShouldBeAttributeChange(this IDiff actualChange, string expectedAttrName, string expectedAttrValue, string? userMessage = null)
{
if (actualChange is null)
Expand Down
7 changes: 7 additions & 0 deletions src/bunit.web/IRenderedFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ public interface IRenderedFragment : IRenderedFragmentBase
/// or component under test.
/// </summary>
/// <returns>A list of differences found.</returns>
[Obsolete("Will be removed in v2.")]
#pragma warning disable CA1024 // Public API - cannot change structure
IReadOnlyList<IDiff> GetChangesSinceFirstRender();
#pragma warning restore CA1024

/// <summary>
/// Performs a comparison of the markup produced by the rendering of the
/// fragment or component under test at the time the <see cref="SaveSnapshot"/> was called
/// with the current rendering of the fragment or component under test.
/// </summary>
/// <returns>A list of differences found.</returns>
[Obsolete("Will be removed in v2.")]
#pragma warning disable CA1024 // Public API - cannot change structure
IReadOnlyList<IDiff> GetChangesSinceSnapshot();
#pragma warning restore CA1024

/// <summary>
/// Saves the markup from the current rendering of the fragment or component under test.
/// Use the method <see cref="GetChangesSinceSnapshot"/> later to get the difference between
/// the snapshot and the rendered markup at that time.
/// </summary>
[Obsolete("Will be removed in v2.")]
void SaveSnapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? re

private AuthorizationResult VerifyRequiredPolicies(IReadOnlyCollection<IAuthorizationRequirement> requirements)
{
#pragma warning disable CS0618
if (supportedPolicies.IsNullOrEmpty() || requirements.IsNullOrEmpty())
#pragma warning restore CS0618
{
return AuthorizationResult.Failed();
}
Expand Down
1 change: 1 addition & 0 deletions tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ dotnet_diagnostic.CA1849.severity = suggestion # CA1849: Call async methods whe
dotnet_diagnostic.xUnit1026.severity = none # xUnit1026: Theory methods should use all of their parameters
dotnet_diagnostic.S1144.severity = suggestion # S1144: Unused private types or members should be removed
dotnet_diagnostic.S2094.severity = suggestion # S2094: Classes should not be empty
dotnet_diagnostic.CS0618.severity = none # CS0618: 'ObsoleteAttribute' is obsolete: '...'