Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class LicensedEndpointDetails
public string? ServiceEndDate { get; set; }
public Product[] Products { get; set; } = [];
public bool ValidId { get; set; }
public bool IsAmended { get; set; }
}

public class LicensedEndpointDetailsAmendment
Expand All @@ -21,6 +22,12 @@ public class LicensedEndpointDetailsAmendment
public QueueIdentity[] UnassignedQueues { get; set; } = [];
public QueueIdentity[] UnmappedQueues { get; set; } = [];

public bool IsEmpty() => Endpoints.Length == 0
&& RemovedEndpointIds.Length == 0
&& InfrastructureQueues.Length == 0
&& ExcludedQueues.Length == 0
&& UnassignedQueues.Length == 0
&& UnmappedQueues.Length == 0;
}

public class Product
Expand All @@ -45,6 +52,7 @@ public record LicensedEndpoint
public string? EndpointSize { get; set; }

public QueueIdentity[] Queues { get; set; } = [];
public QueueIdentity[] ExcludeThroughput { get; set; } = [];
}

public class LicensedEndpointAmendment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class LicenseMetadata
{
public LicensedEndpointDetails Amend(LicensedEndpointDetailsAmendment? amendments)
{
if (amendments is null)
if (amendments is null || amendments.IsEmpty())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to do

if (amendments is null or { .IsEmpty() })

Not sure how that works with a method. If it was a property I'm pretty sure you could do:

if (amendments is null or { IsEmpty: true })

You could also do:

if (amendments?.IsEmpty() ?? false)

Not requiring a change, just looking at opportunities to use new language features.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered doing the last one, but found this way more readable

{
return baseDetails;
}
Expand Down Expand Up @@ -50,7 +50,7 @@ .. baseDetails.Endpoints.Where(endpoint => !amendments.RemovedEndpointIds.Contai
.. amendments.InfrastructureQueues,
.. amendments.Endpoints.SelectMany(queue => queue.AmendedQueues)]),
.. amendment?.AmendedQueues ?? []
]
],
};
}),
.. amendments.Endpoints.Where(endpoint => !baseDetails.Endpoints.Any(baseEndpoint => baseEndpoint.ClientId == endpoint.ClientId))
Expand All @@ -59,8 +59,9 @@ .. amendments.Endpoints.Where(endpoint => !baseDetails.Endpoints.Any(baseEndpoin
ClientId = endpoint.ClientId,
Name = endpoint.Name,
Classification = endpoint.Classification,
Queues = endpoint.AmendedQueues
Queues = endpoint.AmendedQueues,
})];
baseDetails.IsAmended = true;
Comment thread
PhilBastian marked this conversation as resolved.
Resolved

return baseDetails;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void Amend_should_apply_client_queue_moves(string source, string destinat
: Does.Contain(queue));
Assert.That(amended.LicenseId, Is.EqualTo("license-id"));
Assert.That(amended.ServiceEndDate, Is.EqualTo("2026-12-31"));
Assert.That(amended.IsAmended, Is.EqualTo(!amendment.IsEmpty()));
}
}

Expand All @@ -123,22 +124,28 @@ public void Amend_should_apply_successive_client_saves(string source, string int
{
Assert.That(AllQueues(amended).Count(q => q.NameHash == queue.NameHash && q.ScopeHash == queue.ScopeHash), Is.EqualTo(shouldBeSaved ? 1 : 0));
Assert.That(QueuesAt(amended, destination), shouldBeSaved ? Does.Contain(savedQueue) : Does.Not.Contain(savedQueue));
Assert.That(amended.IsAmended, Is.EqualTo(!amendment.IsEmpty()));
}
}

[Test]
public void Null_amendment_should_return_unchanged_details()
[TestCase(false, false)]
[TestCase(false, true)]
[TestCase(true, false)]
[TestCase(true, true)]
public void Null_or_empty_amendment_should_return_unchanged_details(bool emptyAmendment, bool isAmended)
{
var details = DetailsWithQueue(Queue("moving-queue", "first"), "first");
details.IsAmended = isAmended;
var queues = AllQueues(details).ToArray();

var amended = details.Amend(null);
var amended = details.Amend(emptyAmendment ? new LicensedEndpointDetailsAmendment() : null);

using (Assert.EnterMultipleScope())
{
Assert.That(amended, Is.SameAs(details));
Assert.That(AllQueues(amended), Is.EqualTo(queues));
Assert.That(amended.Endpoints.All(endpoint => !endpoint.Amended), Is.True);
Assert.That(amended.IsAmended, Is.EqualTo(isAmended));
}
}

Expand Down Expand Up @@ -171,6 +178,7 @@ public void Amend_should_apply_endpoint_name_and_classification_changes(bool ren
Assert.That(endpoint.EndpointSize, Is.EqualTo("size"));
Assert.That(endpoint.Queues, Does.Contain(queue));
Assert.That(amended.Endpoints.Single(e => e.ClientId == "second").Amended, Is.False);
Assert.That(amended.IsAmended, Is.True);
}
}

Expand All @@ -195,6 +203,7 @@ public void Amend_should_remove_endpoint_and_relocate_its_queues(string destinat
Assert.That(amended.Endpoints.Select(e => e.ClientId), Does.Not.Contain("first"));
Assert.That(AllQueues(amended).Count(q => q == queue), Is.EqualTo(destination == "unmapped" ? 0 : 1));
Assert.That(QueuesAt(amended, destination), destination == "unmapped" ? Does.Not.Contain(queue) : Does.Contain(queue));
Assert.That(amended.IsAmended, Is.True);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Particular.LicensingComponent/ThroughputCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ public async Task<SignedReport> GenerateThroughputReport(string spVersion, DateT
CustomerLicenseAmendments = (endpointMetadata, endpointMetadataAmendments) switch
{
(null, null) => null,
(_, null) => null,
(null, _) => null,
(_, null) => null,
(_, LicensedEndpointDetailsAmendment amendments) when amendments.IsEmpty() => null,
(LicensedEndpointDetails baseDetails, LicensedEndpointDetailsAmendment amendments) => new LicenseAmendments
{
ExcludedQueues = [.. amendments.ExcludedQueues.Select(qId => new Report.QueueIdentity { NameHash = qId.NameHash, ScopeHash = qId.ScopeHash })],
Expand Down
Loading