private void MenuItem_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); UserParser parser = new UserParser(); if (openFileDialog.ShowDialog() == true) { using (StreamReader reader = new StreamReader(openFileDialog.FileName)) { while (!reader.EndOfStream) { try { usersList.Add(parser.Parse(reader.ReadLine())); } catch (FormatException) { MessageBox.Show($"Failed to parse content in file, {openFileDialog.FileName}"); } catch (IndexOutOfRangeException) { MessageBox.Show($"Failed to parse content in file, {openFileDialog.FileName}"); } catch (Exception) { MessageBox.Show($"Could not open file, {openFileDialog.FileName}"); } } } statusBar.NumberOfElements = usersList.Count; } }
public void UserProfileParser_Parse() { string testHtml = FileIO.ReadToEnd("samples/profiles_html.txt"); var parser = new UserParser <UserProfile>(); var profiles = parser.Parse(testHtml); Assert.NotNull(profiles); Assert.NotEmpty(profiles); }