-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06ea710
commit 4f8444e
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/HaveIBeenPwned.Client/Extensions/SubscriptionStatusExtensions.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,34 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Extensions; | ||
|
||
/// <summary> | ||
/// Extensions methods for the <see cref="SubscriptionStatus"/> class. | ||
/// </summary> | ||
public static class SubscriptionStatusExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the <see cref="HibpSubscriptionLevel"/> from the given <paramref name="subscriptionStatus"/>. | ||
/// </summary> | ||
/// <param name="subscriptionStatus">The subscription status instance to evaluate.</param> | ||
/// <returns>The corresponding subscription level.</returns> | ||
/// <exception cref="ArgumentException"> | ||
/// Thrown if the <see cref="SubscriptionStatus.SubscriptionName"/> | ||
/// doesn't map to a level. | ||
/// </exception> | ||
public static HibpSubscriptionLevel GetSubscriptionLevel( | ||
this SubscriptionStatus subscriptionStatus) | ||
{ | ||
return subscriptionStatus.SubscriptionName switch | ||
{ | ||
"Pwned 1" => HibpSubscriptionLevel.One, | ||
"Pwned 2" => HibpSubscriptionLevel.Two, | ||
"Pwned 3" => HibpSubscriptionLevel.Three, | ||
"Pwned 4" => HibpSubscriptionLevel.Four, | ||
|
||
_ => throw new ArgumentException( | ||
$"Unknown subscription level: {subscriptionStatus.SubscriptionName}.") | ||
}; | ||
} | ||
} |