-
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
Showing
2 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/DbSetExtensionsTests.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,72 @@ | ||
using Digdir.Domain.Dialogporten.Application.Common.Extensions; | ||
using Digdir.Domain.Dialogporten.Application.Externals.AltinnAuthorization; | ||
using FluentAssertions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Unit.Tests; | ||
|
||
public class DbSetExtensionsTests | ||
{ | ||
[Fact] | ||
public void PrefilterAuthorizedDialogs_GeneratesExpectedSql_ForGroupedParties() | ||
{ | ||
// Arrange | ||
var authorizedResources = new DialogSearchAuthorizationResult | ||
{ | ||
DialogIds = [Guid.CreateVersion7()], | ||
ResourcesByParties = new Dictionary<string, HashSet<string>> | ||
{ | ||
{ "Party1", ["Resource1", "Resource2"] }, | ||
{ "Party2", ["Resource1", "Resource2"] }, | ||
{ "Party3", ["Resource1", "Resource2", "Resource3"] }, | ||
{ "Party4", ["Resource3"] }, | ||
{ "Party5", ["Resource4"] } | ||
} | ||
}; | ||
|
||
var expectedSql = """ | ||
SELECT * | ||
FROM "Dialog" | ||
WHERE "Id" = ANY(@p0) | ||
OR ( | ||
"Party" = ANY(@p1) | ||
AND "ServiceResource" = ANY(@p2) | ||
) | ||
OR ( | ||
"Party" = ANY(@p3) | ||
AND "ServiceResource" = ANY(@p4) | ||
) | ||
OR ( | ||
"Party" = ANY(@p5) | ||
AND "ServiceResource" = ANY(@p6) | ||
) | ||
OR ( | ||
"Party" = ANY(@p7) | ||
AND "ServiceResource" = ANY(@p8) | ||
) | ||
"""; | ||
var expectedParameters = new object[] | ||
{ | ||
authorizedResources.DialogIds, | ||
new HashSet<string> { "Party1", "Party2" }, | ||
new HashSet<string> { "Resource1", "Resource2" }, | ||
new HashSet<string> { "Party3" }, | ||
new HashSet<string> { "Resource1", "Resource2", "Resource3" }, | ||
new HashSet<string> { "Party4" }, | ||
new HashSet<string> { "Resource3" }, | ||
new HashSet<string> { "Party5" }, | ||
new HashSet<string> { "Resource4" } | ||
}; | ||
|
||
// Act | ||
var (actualSql, actualParameters) = DbSetExtensions.GeneratePrefilterAuthorizedDialogsSql(authorizedResources); | ||
|
||
// Assert | ||
RemoveWhitespace(actualSql).Should().Be(RemoveWhitespace(expectedSql)); | ||
actualParameters.Should().BeEquivalentTo(expectedParameters); | ||
} | ||
|
||
private static string RemoveWhitespace(string input) | ||
{ | ||
return string.Concat(input.Where(c => !char.IsWhiteSpace(c))); | ||
} | ||
} |