-
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.
#545 Validate the constructors and JSON serialization behavior of the…
… PartyDetailsLookupRequest class across diverse scenarios.
- Loading branch information
1 parent
b562e4b
commit 7a8c64b
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
...nn.Notifications.Tests/Notifications.Core/TestingModels/PartyDetailsLookupRequestTests.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,105 @@ | ||
using System; | ||
using System.Text.Json; | ||
|
||
using Altinn.Notifications.Core.Models.Parties; | ||
|
||
using Xunit; | ||
|
||
namespace Altinn.Notifications.Tests.Notifications.Core.TestingModels; | ||
|
||
public class PartyDetailsLookupRequestTests | ||
{ | ||
[Fact] | ||
public void Constructor_WithBothOrganizationNumberAndSocialSecurityNumber_ThrowsArgumentException() | ||
{ | ||
// Arrange | ||
var organizationNumber = "314204298"; | ||
var socialSecurityNumber = "09827398702"; | ||
|
||
// Act & Assert | ||
var exception = Assert.Throws<ArgumentException>(() => new PartyDetailsLookupRequest(organizationNumber, socialSecurityNumber)); | ||
Assert.Equal("You can specify either an OrganizationNumber or a SocialSecurityNumber, but not both.", exception.Message); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithNoParameters_SetsBothPropertiesToNull() | ||
{ | ||
// Act | ||
var request = new PartyDetailsLookupRequest(); | ||
|
||
// Assert | ||
Assert.Null(request.OrganizationNumber); | ||
Assert.Null(request.SocialSecurityNumber); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithOrganizationNumberOnly_SetsOrganizationNumber() | ||
{ | ||
// Arrange | ||
var organizationNumber = "314204298"; | ||
|
||
// Act | ||
var request = new PartyDetailsLookupRequest(organizationNumber: organizationNumber); | ||
|
||
// Assert | ||
Assert.Equal(organizationNumber, request.OrganizationNumber); | ||
Assert.Null(request.SocialSecurityNumber); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithSocialSecurityNumberOnly_SetsSocialSecurityNumber() | ||
{ | ||
// Arrange | ||
var socialSecurityNumber = "09827398702"; | ||
|
||
// Act | ||
var request = new PartyDetailsLookupRequest(socialSecurityNumber: socialSecurityNumber); | ||
|
||
// Assert | ||
Assert.Equal(socialSecurityNumber, request.SocialSecurityNumber); | ||
Assert.Null(request.OrganizationNumber); | ||
} | ||
|
||
[Fact] | ||
public void JsonSerialization_WithNullProperties_ExcludesNullProperties() | ||
{ | ||
// Arrange | ||
var request = new PartyDetailsLookupRequest(); | ||
|
||
// Act | ||
var json = JsonSerializer.Serialize(request); | ||
|
||
// Assert | ||
Assert.DoesNotContain("\"orgNo\"", json); | ||
Assert.DoesNotContain("\"ssn\"", json); | ||
Assert.Equal("{}", json); | ||
} | ||
|
||
[Fact] | ||
public void JsonSerialization_WithOrganizationNumber_OnlyIncludesOrganizationNumber() | ||
{ | ||
// Arrange | ||
var request = new PartyDetailsLookupRequest(organizationNumber: "314204298"); | ||
|
||
// Act | ||
var json = JsonSerializer.Serialize(request); | ||
|
||
// Assert | ||
Assert.Contains("\"orgNo\":\"314204298\"", json); | ||
Assert.DoesNotContain("\"ssn\"", json); | ||
} | ||
|
||
[Fact] | ||
public void JsonSerialization_WithSocialSecurityNumber_OnlyIncludesSocialSecurityNumber() | ||
{ | ||
// Arrange | ||
var request = new PartyDetailsLookupRequest(socialSecurityNumber: "09827398702"); | ||
|
||
// Act | ||
var json = JsonSerializer.Serialize(request); | ||
|
||
// Assert | ||
Assert.Contains("\"ssn\":\"09827398702\"", json); | ||
Assert.DoesNotContain("\"orgNo\"", json); | ||
} | ||
} |