Skip to content

Commit

Permalink
Merge pull request #73 from jscarle/develop
Browse files Browse the repository at this point in the history
Added new overloads.
  • Loading branch information
jscarle committed Mar 14, 2024
2 parents 951f723 + b75ac49 commit cb08100
Show file tree
Hide file tree
Showing 323 changed files with 38,608 additions and 1,014 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Docs

on:
push:
branches: ["main"]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Setup .NET 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Setup docfx
run: dotnet tool update -g docfx

- name: Build documentation
run: docfx ./docfx/docfx.json

- name: Upload documentation
uses: actions/upload-pages-artifact@v3
with:
path: './docfx/_site'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,9 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb


# Docs
docfx/_site/**
docfx/reference/**
5 changes: 4 additions & 1 deletion OnePassword.NET.Tests/OnePassword.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<PackageReference Include="NUnit" Version="4.1.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="NUnit.Analyzers" Version="4.0.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion OnePassword.NET.Tests/SetUpAccount.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using OnePassword.Accounts;
using OnePassword.Common;

namespace OnePassword;
Expand Down
99 changes: 52 additions & 47 deletions OnePassword.NET/Accounts/Account.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
namespace OnePassword.Accounts;
using System.Diagnostics.CodeAnalysis;

/// <summary>
/// Represents a 1Password account.
/// </summary>
namespace OnePassword.Accounts;

/// <summary>Represents a 1Password account.</summary>
public sealed class Account : IAccount
{
/// <inheritdoc />
[JsonInclude]
[JsonPropertyName("account_uuid")]
public string Id { get; internal init; } = "";

/// <summary>
/// The account shorthand.
/// </summary>
/// <summary>The account shorthand.</summary>
[JsonInclude]
[JsonPropertyName("shorthand")]
public string Shorthand { get; internal init; } = "";

/// <summary>
/// The account URL.
/// </summary>
/// <summary>The account URL.</summary>
[JsonInclude]
[JsonPropertyName("url")]
[SuppressMessage("Design", "CA1056:URI-like properties should not be strings")]
public string Url { get; internal init; } = "";

/// <summary>
/// The user ID for the user associated with the account.
/// </summary>
/// <summary>The user ID for the user associated with the account.</summary>
[JsonInclude]
[JsonPropertyName("user_uuid")]
public string UserId { get; internal init; } = "";

/// <summary>
/// The email address for the user associated with the account.
/// </summary>
/// <summary>The email address for the user associated with the account.</summary>
[JsonInclude]
[JsonPropertyName("email")]
public string Email { get; internal init; } = "";
Expand All @@ -46,28 +39,46 @@ public void Deconstruct(out string id, out string name)
}

/// <inheritdoc />
public override string ToString()
{
return Shorthand;
}

public static bool operator ==(Account a, IAccount b) => a.Equals(b);

public static bool operator !=(Account a, IAccount b) => !a.Equals(b);

public static bool operator <(Account a, IAccount b) => a.CompareTo(b) < 0;

public static bool operator <=(Account a, IAccount b) => a.CompareTo(b) <= 0;

public static bool operator >(Account a, IAccount b) => a.CompareTo(b) > 0;

public static bool operator >=(Account a, IAccount b) => a.CompareTo(b) >= 0;
public override string ToString() => Shorthand;

/// <summary>Equality operator.</summary>
/// <param name="a">The first account to compare.</param>
/// <param name="b">The second account to compare.</param>
/// <returns>True if the accounts are equal, false otherwise.</returns>
public static bool operator ==(Account a, IAccount b) => a?.Equals(b) ?? false;

/// <summary>Inequality operator.</summary>
/// <param name="a">The first account to compare.</param>
/// <param name="b">The second account to compare.</param>
/// <returns>True if the accounts are not equal, false otherwise.</returns>
public static bool operator !=(Account a, IAccount b) => !a?.Equals(b) ?? false;

/// <summary>Less than operator.</summary>
/// <param name="a">The first account to compare.</param>
/// <param name="b">The second account to compare.</param>
/// <returns>True if the first account is less than the second one, false otherwise.</returns>
public static bool operator <(Account a, IAccount b) => a?.CompareTo(b) < 0;

/// <summary>Less than or equal to operator.</summary>
/// <param name="a">The first account to compare.</param>
/// <param name="b">The second account to compare.</param>
/// <returns>True if the first account is less than or equal to the second one, false otherwise.</returns>
public static bool operator <=(Account a, IAccount b) => a?.CompareTo(b) <= 0;

/// <summary>Greater than operator.</summary>
/// <param name="a">The first account to compare.</param>
/// <param name="b">The second account to compare.</param>
/// <returns>True if the first account is greater than the second one, false otherwise.</returns>
public static bool operator >(Account a, IAccount b) => a?.CompareTo(b) > 0;

/// <summary>Greater than or equal to operator.</summary>
/// <param name="a">The first account to compare.</param>
/// <param name="b">The second account to compare.</param>
/// <returns>True if the first account is greater than or equal to the second one, false otherwise.</returns>
public static bool operator >=(Account a, IAccount b) => a?.CompareTo(b) >= 0;

/// <inheritdoc />
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is IAccount other && Equals(other);
}
public override bool Equals(object? obj) => ReferenceEquals(this, obj) || obj is IAccount other && Equals(other);

/// <inheritdoc />
public bool Equals(IAccount? other)
Expand Down Expand Up @@ -97,20 +108,14 @@ public int CompareTo(IAccount? other)
};
}

/// <inheritdoc />
public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Id);

private int CompareTo(Account? other)
{
if (other is null) return 1;
return ReferenceEquals(this, other) ? 0 : string.Compare(Shorthand, other.Shorthand, StringComparison.Ordinal);
}

private int CompareTo(AccountDetails? other)
{
return other is null ? 1 : string.Compare(Shorthand, other.Domain, StringComparison.Ordinal);
}

/// <inheritdoc />
public override int GetHashCode()
{
return StringComparer.OrdinalIgnoreCase.GetHashCode(Id);
}
}
private int CompareTo(AccountDetails? other) => other is null ? 1 : string.Compare(Shorthand, other.Domain, StringComparison.Ordinal);
}
98 changes: 49 additions & 49 deletions OnePassword.NET/Accounts/AccountDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,35 @@

namespace OnePassword.Accounts;

/// <summary>
/// Represents a 1Password account with details.
/// </summary>
/// <summary>Represents a 1Password account with details.</summary>
public sealed class AccountDetails : IAccount
{
/// <inheritdoc />
[JsonInclude]
[JsonPropertyName("id")]
public string Id { get; internal init; } = "";

/// <summary>
/// The account name.
/// </summary>
/// <summary>The account name.</summary>
[JsonInclude]
[JsonPropertyName("name")]
public string Name { get; internal init; } = "";

/// <summary>
/// The account domain.
/// </summary>
/// <summary>The account domain.</summary>
[JsonInclude]
[JsonPropertyName("domain")]
public string Domain { get; internal init; } = "";

/// <summary>
/// The account type.
/// </summary>
/// <summary>The account type.</summary>
[JsonInclude]
[JsonPropertyName("type")]
public AccountType Type { get; internal init; } = AccountType.Unknown;

/// <summary>
/// The state of the account.
/// </summary>
/// <summary>The state of the account.</summary>
[JsonInclude]
[JsonPropertyName("state")]
public State State { get; internal init; } = State.Unknown;

/// <summary>
/// The date and time when the account was created.
/// </summary>
/// <summary>The date and time when the account was created.</summary>
[JsonInclude]
[JsonPropertyName("created_at")]
public DateTimeOffset Created { get; internal init; }
Expand All @@ -55,28 +43,46 @@ public void Deconstruct(out string id, out string name)
}

/// <inheritdoc />
public override string ToString()
{
return Name;
}

public static bool operator ==(AccountDetails a, IAccount b) => a.Equals(b);

public static bool operator !=(AccountDetails a, IAccount b) => !a.Equals(b);

public static bool operator <(AccountDetails a, IAccount b) => a.CompareTo(b) < 0;

public static bool operator <=(AccountDetails a, IAccount b) => a.CompareTo(b) <= 0;

public static bool operator >(AccountDetails a, IAccount b) => a.CompareTo(b) > 0;

public static bool operator >=(AccountDetails a, IAccount b) => a.CompareTo(b) >= 0;
public override string ToString() => Name;

/// <summary>Equality operator.</summary>
/// <param name="a">The <see cref="AccountDetails" /> object.</param>
/// <param name="b">The <see cref="IAccount" /> object to compare.</param>
/// <returns>True if the <paramref name="a" /> is equal to <paramref name="b" />; otherwise, false.</returns>
public static bool operator ==(AccountDetails a, IAccount b) => a?.Equals(b) ?? false;

/// <summary>Inequality operator.</summary>
/// <param name="a">The <see cref="AccountDetails" /> object.</param>
/// <param name="b">The <see cref="IAccount" /> object to compare.</param>
/// <returns>True if the <paramref name="a" /> is not equal to <paramref name="b" />; otherwise, false.</returns>
public static bool operator !=(AccountDetails a, IAccount b) => !a?.Equals(b) ?? false;

/// <summary>Less than operator.</summary>
/// <param name="a">The <see cref="AccountDetails" /> object.</param>
/// <param name="b">The <see cref="IAccount" /> object to compare.</param>
/// <returns>True if the <paramref name="a" /> is less than <paramref name="b" />; otherwise, false.</returns>
public static bool operator <(AccountDetails a, IAccount b) => a?.CompareTo(b) < 0;

/// <summary>Less than or equal to operator.</summary>
/// <param name="a">The <see cref="AccountDetails" /> object.</param>
/// <param name="b">The <see cref="IAccount" /> object to compare.</param>
/// <returns>True if the <paramref name="a" /> is less than or equal to <paramref name="b" />; otherwise, false.</returns>
public static bool operator <=(AccountDetails a, IAccount b) => a?.CompareTo(b) <= 0;

/// <summary>Greater than operator.</summary>
/// <param name="a">The <see cref="AccountDetails" /> object.</param>
/// <param name="b">The <see cref="IAccount" /> object to compare.</param>
/// <returns>True if the <paramref name="a" /> is greater than <paramref name="b" />; otherwise, false.</returns>
public static bool operator >(AccountDetails a, IAccount b) => a?.CompareTo(b) > 0;

/// <summary>Greater than or equal to operator.</summary>
/// <param name="a">The <see cref="AccountDetails" /> object.</param>
/// <param name="b">The <see cref="IAccount" /> object to compare.</param>
/// <returns>True if the <paramref name="a" /> is greater than or equal to <paramref name="b" />; otherwise, false.</returns>
public static bool operator >=(AccountDetails a, IAccount b) => a?.CompareTo(b) >= 0;

/// <inheritdoc />
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is IAccount other && Equals(other);
}
public override bool Equals(object? obj) => ReferenceEquals(this, obj) || obj is IAccount other && Equals(other);

/// <inheritdoc />
public bool Equals(IAccount? other)
Expand Down Expand Up @@ -106,20 +112,14 @@ public int CompareTo(IAccount? other)
};
}

private int CompareTo(Account? other)
{
return other is null ? 1 : string.Compare(Domain, other.Shorthand, StringComparison.Ordinal);
}
/// <inheritdoc />
public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Id);

private int CompareTo(Account? other) => other is null ? 1 : string.Compare(Domain, other.Shorthand, StringComparison.Ordinal);

private int CompareTo(AccountDetails? other)
{
if (other is null) return 1;
return ReferenceEquals(this, other) ? 0 : string.Compare(Domain, other.Domain, StringComparison.Ordinal);
}

/// <inheritdoc />
public override int GetHashCode()
{
return StringComparer.OrdinalIgnoreCase.GetHashCode(Id);
}
}
}
6 changes: 3 additions & 3 deletions OnePassword.NET/Common/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal static class CommonExtensions
/// <param name="field">The enum field.</param>
/// <typeparam name="TField">The type of enum field.</typeparam>
/// <returns>A string representation of the enum field.</returns>
/// <exception cref="ArgumentNullException">Thrown when <see cref="field"/> is null.</exception>
/// <exception cref="NotImplementedException">Thrown when <see cref="field"/> is not correctly annotated with a <see cref="EnumMemberAttribute"/>.</exception>
/// <exception cref="ArgumentNullException">Thrown when field is null.</exception>
/// <exception cref="NotImplementedException">Thrown when field is not correctly annotated with a <see cref="EnumMemberAttribute"/>.</exception>
internal static string ToEnumString<TField>(this TField field)
where TField : Enum
{
Expand Down Expand Up @@ -57,4 +57,4 @@ internal static string ToCommaSeparated(this IEnumerable<string> items, bool rep
var commaSeparated = string.Join(",", items);
return replaceUnderscoresWithSpaces ? commaSeparated.Replace("_", " ", StringComparison.InvariantCulture) : commaSeparated;
}
}
}

0 comments on commit cb08100

Please sign in to comment.