-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a number of simple unit test to test the mapping profile
- Loading branch information
1 parent
f58eb64
commit 4227cbf
Showing
1 changed file
with
127 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
test/Altinn.Profile.Tests/Profile.Integrations/PersonContactDetailsProfileTests.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,127 @@ | ||
using Altinn.Profile.Integrations.Entities; | ||
using Altinn.Profile.Integrations.Mappings; | ||
|
||
using AutoMapper; | ||
|
||
using Xunit; | ||
|
||
namespace Altinn.Profile.Tests.Profile.Integrations; | ||
|
||
public class PersonContactDetailsProfileTests | ||
{ | ||
private readonly IMapper _mapper; | ||
|
||
public PersonContactDetailsProfileTests() | ||
{ | ||
var config = new MapperConfiguration(cfg => cfg.AddProfile<PersonContactDetailsProfile>()); | ||
_mapper = config.CreateMapper(); | ||
} | ||
|
||
[Fact] | ||
public void Map_DifferentValues_CreatesCorrectMappings() | ||
{ | ||
// Arrange | ||
var person = new Person | ||
{ | ||
Reservation = true, | ||
LanguageCode = "no", | ||
FnumberAk = "24021633239", | ||
MobilePhoneNumber = "9876543210", | ||
EmailAddress = "[email protected]", | ||
}; | ||
|
||
// Act | ||
var result = _mapper.Map<PersonContactDetails>(person); | ||
|
||
// Assert | ||
Assert.True(result.IsReserved); | ||
Assert.Equal(person.EmailAddress, result.EmailAddress); | ||
Assert.Equal(person.LanguageCode, result.LanguageCode); | ||
Assert.Equal(person.FnumberAk, result.NationalIdentityNumber); | ||
Assert.Equal(person.MobilePhoneNumber, result.MobilePhoneNumber); | ||
} | ||
|
||
[Fact] | ||
public void Map_NullPerson_ReturnsNullPersonContactDetails() | ||
{ | ||
// Arrange | ||
Person person = null; | ||
|
||
// Act | ||
var result = _mapper.Map<PersonContactDetails>(person); | ||
|
||
// Assert | ||
Assert.Null(result); | ||
} | ||
|
||
[Fact] | ||
public void Map_OptionalProperties_WhenMissing_ReturnsDefaults() | ||
{ | ||
// Arrange | ||
var person = new Person | ||
{ | ||
Reservation = false, | ||
FnumberAk = "06082705358" | ||
}; | ||
|
||
// Act | ||
var result = _mapper.Map<PersonContactDetails>(person); | ||
|
||
// Assert | ||
Assert.Null(result.LanguageCode); | ||
Assert.Null(result.EmailAddress); | ||
Assert.Null(result.MobilePhoneNumber); | ||
Assert.Equal("06082705358", result.NationalIdentityNumber); | ||
} | ||
|
||
[Fact] | ||
public void Map_ReservationFalse_SetsIsReservedToFalse() | ||
{ | ||
// Arrange | ||
var person = new Person { Reservation = false }; | ||
|
||
// Act | ||
var result = _mapper.Map<PersonContactDetails>(person); | ||
|
||
// Assert | ||
Assert.False(result.IsReserved); | ||
} | ||
|
||
[Fact] | ||
public void Map_ReservationTrue_SetsIsReservedToTrue() | ||
{ | ||
// Arrange | ||
var person = new Person { Reservation = true }; | ||
|
||
// Act | ||
var result = _mapper.Map<PersonContactDetails>(person); | ||
|
||
// Assert | ||
Assert.True(result.IsReserved); | ||
} | ||
|
||
[Fact] | ||
public void Map_ValidPerson_ReturnsCorrectPersonContactDetails() | ||
{ | ||
// Arrange | ||
var person = new Person | ||
{ | ||
Reservation = false, | ||
LanguageCode = "en", | ||
FnumberAk = "17080227000", | ||
MobilePhoneNumber = "1234567890", | ||
EmailAddress = "[email protected]" | ||
}; | ||
|
||
// Act | ||
var result = _mapper.Map<PersonContactDetails>(person); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.False(result.IsReserved); | ||
Assert.Equal(person.EmailAddress, result.EmailAddress); | ||
Assert.Equal(person.LanguageCode, result.LanguageCode); | ||
Assert.Equal(person.FnumberAk, result.NationalIdentityNumber); | ||
Assert.Equal(person.MobilePhoneNumber, result.MobilePhoneNumber); | ||
} | ||
} |