1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Prefer record to implementing IEquatable (#5449)

This commit is contained in:
Matt Gibson 2025-02-26 14:41:24 -08:00 committed by GitHub
parent 4a4d256fd9
commit bd66f06bd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 22 deletions

View File

@ -1,23 +1,13 @@
namespace Bit.Core.NotificationHub; namespace Bit.Core.NotificationHub;
public struct WebPushRegistrationData : IEquatable<WebPushRegistrationData> public record struct WebPushRegistrationData
{ {
public string Endpoint { get; init; } public string Endpoint { get; init; }
public string P256dh { get; init; } public string P256dh { get; init; }
public string Auth { get; init; } public string Auth { get; init; }
public bool Equals(WebPushRegistrationData other)
{
return Endpoint == other.Endpoint && P256dh == other.P256dh && Auth == other.Auth;
}
public override int GetHashCode()
{
return HashCode.Combine(Endpoint, P256dh, Auth);
}
} }
public class PushRegistrationData : IEquatable<PushRegistrationData> public record class PushRegistrationData
{ {
public string Token { get; set; } public string Token { get; set; }
public WebPushRegistrationData? WebPush { get; set; } public WebPushRegistrationData? WebPush { get; set; }
@ -38,13 +28,4 @@ public class PushRegistrationData : IEquatable<PushRegistrationData>
{ {
WebPush = webPush; WebPush = webPush;
} }
public bool Equals(PushRegistrationData other)
{
return Token == other.Token && WebPush.Equals(other.WebPush);
}
public override int GetHashCode()
{
return HashCode.Combine(Token, WebPush.GetHashCode());
}
} }

View File

@ -280,7 +280,7 @@ public class PushControllerTests
await sutProvider.Sut.RegisterAsync(model); await sutProvider.Sut.RegisterAsync(model);
await sutProvider.GetDependency<IPushRegistrationService>().Received(1) await sutProvider.GetDependency<IPushRegistrationService>().Received(1)
.CreateOrUpdateRegistrationAsync(Arg.Is<PushRegistrationData>(data => data.Equals(new PushRegistrationData(model.PushToken))), expectedDeviceId, expectedUserId, .CreateOrUpdateRegistrationAsync(Arg.Is<PushRegistrationData>(data => data == new PushRegistrationData(model.PushToken)), expectedDeviceId, expectedUserId,
expectedIdentifier, DeviceType.Android, Arg.Do<IEnumerable<string>>(organizationIds => expectedIdentifier, DeviceType.Android, Arg.Do<IEnumerable<string>>(organizationIds =>
{ {
var organizationIdsList = organizationIds.ToList(); var organizationIdsList = organizationIds.ToList();