Skip to content

Commit

Permalink
Merge pull request #81 from knippers/master
Browse files Browse the repository at this point in the history
including the UUID in templates
  • Loading branch information
jscarle committed Jun 18, 2024
2 parents a91a440 + 443ca04 commit 7536293
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
9 changes: 4 additions & 5 deletions OnePassword.NET.Tests/TestTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ public void GetTemplatesByEnum()

Run(RunType.Test, () =>
{
foreach (var enumValue in Enum.GetValues(typeof(Category)))
foreach (var enumValue in Enum.GetValues<Category>())
{
var enumMember = (Category)enumValue;
if (enumMember is Category.Custom or Category.Unknown)
if (enumValue is Category.Custom or Category.Unknown)
continue;
var enumMemberString = enumMember.ToEnumString();
var enumMemberString = enumValue.ToEnumString();
var template = OnePassword.GetTemplate(enumMember);
var template = OnePassword.GetTemplate(enumValue);
Assert.Multiple(() =>
{
Expand Down
5 changes: 5 additions & 0 deletions OnePassword.NET/Templates/ITemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/// </summary>
public interface ITemplate : IEquatable<ITemplate>, IComparable<ITemplate>, IComparable
{
/// <summary>
/// The template UUID.
/// </summary>
string Uuid { get; }

/// <summary>
/// The template name.
/// </summary>
Expand Down
11 changes: 8 additions & 3 deletions OnePassword.NET/Templates/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace OnePassword.Templates;
/// <summary>Represents a 1Password template.</summary>
public sealed class Template : ItemBase, ITemplate, ICloneable
{
/// <inheritdoc />
[JsonInclude]
[JsonPropertyName("uuid")]
public string Uuid { get; internal set; } = "";

/// <inheritdoc />
[JsonInclude]
[JsonPropertyName("name")]
Expand Down Expand Up @@ -67,7 +72,7 @@ public Template Clone()
public bool Equals(ITemplate? other)
{
if (other is null) return false;
return ReferenceEquals(this, other) || string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
return ReferenceEquals(this, other) || string.Equals(Uuid, other.Uuid, StringComparison.OrdinalIgnoreCase);
}

/// <inheritdoc />
Expand All @@ -82,14 +87,14 @@ public int CompareTo(object? obj)
public int CompareTo(ITemplate? other)
{
if (other is null) return 1;
return ReferenceEquals(this, other) ? 0 : string.Compare(Name, other.Name, StringComparison.Ordinal);
return ReferenceEquals(this, other) ? 0 : string.Compare(Uuid, other.Uuid, StringComparison.Ordinal);
}

/// <inheritdoc />
public override int GetHashCode() =>
// ReSharper disable once NonReadonlyMemberInGetHashCode
// Name can only be set by internal methods.
StringComparer.OrdinalIgnoreCase.GetHashCode(Name);
StringComparer.OrdinalIgnoreCase.GetHashCode(Uuid) + StringComparer.OrdinalIgnoreCase.GetHashCode(Name);

/// <inheritdoc />
object ICloneable.Clone() => Clone();
Expand Down
11 changes: 8 additions & 3 deletions OnePassword.NET/Templates/TemplateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
/// <summary>Describes a 1Password template.</summary>
public sealed class TemplateInfo : ITemplate
{
/// <inheritdoc />
[JsonInclude]
[JsonPropertyName("uuid")]
public string Uuid { get; internal set; } = "";

/// <inheritdoc />
[JsonInclude]
[JsonPropertyName("name")]
Expand Down Expand Up @@ -54,7 +59,7 @@ public sealed class TemplateInfo : ITemplate
public bool Equals(ITemplate? other)
{
if (other is null) return false;
return ReferenceEquals(this, other) || string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
return ReferenceEquals(this, other) || string.Equals(Uuid, other.Uuid, StringComparison.OrdinalIgnoreCase);
}

/// <inheritdoc />
Expand All @@ -69,14 +74,14 @@ public int CompareTo(object? obj)
public int CompareTo(ITemplate? other)
{
if (other is null) return 1;
return ReferenceEquals(this, other) ? 0 : string.Compare(Name, other.Name, StringComparison.Ordinal);
return ReferenceEquals(this, other) ? 0 : string.Compare(Uuid, other.Uuid, StringComparison.Ordinal);
}

/// <inheritdoc />
public override int GetHashCode() =>
// ReSharper disable once NonReadonlyMemberInGetHashCode
// Name can only be set by internal methods.
StringComparer.OrdinalIgnoreCase.GetHashCode(Name);
StringComparer.OrdinalIgnoreCase.GetHashCode(Uuid) + StringComparer.OrdinalIgnoreCase.GetHashCode(Name);

private static int NullSafeCompareTo(TemplateInfo? a, ITemplate? b)
{
Expand Down

0 comments on commit 7536293

Please sign in to comment.