From 38640d411fa74365b37cbe17e6792defaca42842 Mon Sep 17 00:00:00 2001 From: Ahmed-Ghanam Date: Tue, 8 Oct 2024 16:33:23 +0200 Subject: [PATCH] Implement unit tests to verify the functionality of the class responsible for validating national identity numbers --- .../NationalIdentityNumberCheckerTests.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/Altinn.Profile.Tests/Profile.Integrations/NationalIdentityNumberCheckerTests.cs diff --git a/test/Altinn.Profile.Tests/Profile.Integrations/NationalIdentityNumberCheckerTests.cs b/test/Altinn.Profile.Tests/Profile.Integrations/NationalIdentityNumberCheckerTests.cs new file mode 100644 index 0000000..5306f1d --- /dev/null +++ b/test/Altinn.Profile.Tests/Profile.Integrations/NationalIdentityNumberCheckerTests.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; + +using Altinn.Profile.Integrations.Services; + +using Xunit; + +namespace Altinn.Profile.Tests.Profile.Integrations; + +public class NationalIdentityNumberCheckerTests +{ + private readonly NationalIdentityNumberChecker _checker; + + public NationalIdentityNumberCheckerTests() + { + _checker = new NationalIdentityNumberChecker(); + } + + [Fact] + public void Categorize_NullInput_ThrowsArgumentNullException() + { + Assert.Throws(() => _checker.Categorize(null)); + } + + [Fact] + public void Categorize_ValidAndInvalidNumbers_ReturnsCorrectCategorization() + { + var input = new List { "26050711071", "invalid_number", "06010190515" }; + var (valid, invalid) = _checker.Categorize(input); + + Assert.Single(invalid); + Assert.Equal(2, valid.Count); + Assert.Contains("26050711071", valid); + Assert.Contains("06010190515", valid); + Assert.Contains("invalid_number", invalid); + } + + [Fact] + public void GetValid_NullInput_ThrowsArgumentNullException() + { + Assert.Throws(() => _checker.GetValid(null)); + } + + [Fact] + public void GetValid_ValidAndInvalidNumbers_ReturnsOnlyValidNumbers() + { + var input = new List { "05112908325", "031IN0918959", "03110918959" }; + var result = _checker.GetValid(input); + + Assert.Equal(2, result.Count); + Assert.Contains("05112908325", result); + Assert.Contains("03110918959", result); + } + + [Fact] + public void IsValid_ValidNumber_ReturnsTrue() + { + var result = _checker.IsValid("08033201398"); + Assert.True(result); + } + + [Fact] + public void IsValid_InvalidNumber_ReturnsFalse() + { + var result = _checker.IsValid("080332Q1398"); + Assert.False(result); + } +}