Пример #1
0
        public void ShouldNotGenerateSameBirthNumberWithDiffrerentSeed()
        {
            NorwegianBirthNumber birthNumber1 = NorwegianBirthNumber.CreateRandom("1");
            NorwegianBirthNumber birthNumber2 = NorwegianBirthNumber.CreateRandom("2");

            birthNumber1.Should().NotBe(birthNumber2);
        }
Пример #2
0
 public void ShouldGenerateRandomValidNumbers()
 {
     for (int i = 0; i < 100; i++)
     {
         NorwegianBirthNumber.CreateRandom();
     }
 }
Пример #3
0
        public void ShouldGenerateSameBirthNumberWithSameSeed()
        {
            NorwegianBirthNumber birthNumber1 = NorwegianBirthNumber.CreateRandom("12345678901");
            NorwegianBirthNumber birthNumber2 = NorwegianBirthNumber.CreateRandom("12345678901");

            birthNumber1.Should().Be(birthNumber2);
        }
Пример #4
0
        public void AnonymizeFiskermanntallet()
        {
            var          tmpFileName = Path.GetTempFileName();
            StreamWriter file        = new StreamWriter(tmpFileName, false, Encodings.ISO_8859_1);

            Dictionary <string, string> randomFodselsnummerOgNavn = new Dictionary <string, string>();

            // TODO Rewrite to read test data from a relative location.
            // The file is found in 'Arkivverket.Arkade.Test/TestData/tar/fiskermanntallet-anonymized/dab6c748-8d1a-4b6d-b091-3a7b8b3cb255.tar'
            // and there should probably be a setup step that unpacks those files to a deterministic location.
            string[] allLines = File.ReadAllLines("C:/tmp/_testdata/fiskermanntallet-anon/manntal2000_2009.dat", Encodings.ISO_8859_1);
            foreach (string line in allLines)
            {
                string[] fields = line.Split(';');

                // Anonymize birth number
                string fnr       = fields[1];
                string randomFnr = NorwegianBirthNumber.CreateRandom(fnr).ToString();

                fields[1] = randomFnr;

                // Anonymize name
                string randomName;
                if (randomFodselsnummerOgNavn.ContainsKey(randomFnr))
                {
                    randomName = randomFodselsnummerOgNavn[randomFnr];
                }
                else
                {
                    randomName = NorwegianNameGenerator.RandomLastNameAndFirstName().ToUpper();
                    randomFodselsnummerOgNavn.Add(randomFnr, randomName);
                }
                fields[2] = randomName;

                // Anonymize address
                fields[3] = fields[3].Length > 0 ? "PORTV. 2" : "";

                file.WriteLine(string.Join(";", fields));
            }

            file.Close();
        }
        //[Fact]
        public void AnonymizeFiskermanntallet()
        {
            StreamWriter file = new StreamWriter(@"C:\tmp\file.txt", false, Encodings.ISO_8859_1);

            Dictionary <string, string> randomFodselsnummerOgNavn = new Dictionary <string, string>();

            string[] allLines = File.ReadAllLines("C:\\tmp\\_testdata\\fiskermanntallet-anon\\manntal2000_2009.dat", Encodings.ISO_8859_1);
            foreach (string line in allLines)
            {
                string[] fields = line.Split(';');

                // Anonymize birth number
                string fnr       = fields[1];
                string randomFnr = NorwegianBirthNumber.CreateRandom(fnr).ToString();

                fields[1] = randomFnr;

                // Anonymize name
                string randomName;
                if (randomFodselsnummerOgNavn.ContainsKey(randomFnr))
                {
                    randomName = randomFodselsnummerOgNavn[randomFnr];
                }
                else
                {
                    randomName = NorwegianNameGenerator.RandomLastNameAndFirstName().ToUpper();
                    randomFodselsnummerOgNavn.Add(randomFnr, randomName);
                }
                fields[2] = randomName;

                // Anonymize address
                fields[3] = fields[3].Length > 0 ? "PORTV. 2" : "";

                file.WriteLine(string.Join(";", fields));
            }

            file.Close();
        }