-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from quozd/refactor-tests
extract test data factory to separate file
- Loading branch information
Showing
3 changed files
with
63 additions
and
55 deletions.
There are no files selected for viewing
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
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
61 changes: 61 additions & 0 deletions
61
src/NPetrovich.Tests/TestDataProviders/InflectionTestCaseDataFactory.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,61 @@ | ||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace NPetrovich.Tests.TestDataProviders | ||
{ | ||
public class InflectionTestCaseDataFactory | ||
{ | ||
public static IEnumerable LastNamesInflectionData | ||
{ | ||
get | ||
{ | ||
using (var reader = new StreamReader(Path.Combine("Data", "LastNames.csv"))) | ||
{ | ||
foreach (var p in ReadCaseData(reader)) yield return p; | ||
} | ||
} | ||
} | ||
|
||
public static IEnumerable FirstNamesInflectionData | ||
{ | ||
get | ||
{ | ||
using (var reader = new StreamReader(Path.Combine("Data", "FirstNames.csv"))) | ||
{ | ||
foreach (var p in ReadCaseData(reader)) yield return p; | ||
} | ||
} | ||
} | ||
|
||
public static IEnumerable MiddleNamesInflectionData | ||
{ | ||
get | ||
{ | ||
using (var reader = new StreamReader(Path.Combine("Data", "MiddleNames.csv"))) | ||
{ | ||
foreach (var p in ReadCaseData(reader)) yield return p; | ||
} | ||
} | ||
} | ||
|
||
private static IEnumerable ReadCaseData(StreamReader reader) | ||
{ | ||
string line; | ||
while ((line = reader.ReadLine()) != null) | ||
{ | ||
if (string.IsNullOrWhiteSpace(line)) | ||
continue; | ||
|
||
var chunks = line.Split(',').Select(s => s.Trim()).ToList(); | ||
|
||
var gender = (Gender)Enum.Parse(typeof(Gender), chunks[1]); | ||
var @case = (Case)Enum.Parse(typeof(Case), chunks[2]); | ||
|
||
yield return new object[] { chunks[0], gender, @case, chunks[3] }; | ||
} | ||
} | ||
|
||
} | ||
} |