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(); }