public void UnformattedExtractionSuccessCaseTest1() { Translation expected = new Translation( new English("Mere", "", "", Language.Types.undefined, new List <string>() { "just", "no more than" }), new French("simple", "", "l’ avion s est écrasé seulement 10 minutes après le décollage", Language.Types.undefined, new List <string>() { "ne … que …", "seulement" }) ); string line = "Mere (= just, no more than)= simple, ne … que …, seulement ( ex: l’ avion s est écrasé seulement 10 minutes après le décollage)"; TranslationDirector director = new TranslationDirector(); TranslationBuilder translationBuilder; translationBuilder = new TranslationUnformattedBuilder(line); director.Construct(translationBuilder); Translation actual = translationBuilder.GetResult(); Assert.IsTrue(AreSameLanguages(expected.Languages[0], actual.Languages[0]) && AreSameLanguages(expected.Languages[1], actual.Languages[1])); }
public void ModidifiedLineUnformattedExtractionSuccessCaseTest1() { string expected = "to run into (= come across)=rencontrer par hasard,croiser, tomber sur"; string line = "to run into (= come across) = rencontrer par hasard,croiser, tomber sur"; TranslationDirector director = new TranslationDirector(); TranslationBuilder translationBuilder; translationBuilder = new TranslationUnformattedBuilder(line); director.Construct(translationBuilder); string actual = translationBuilder.GetResult().Line; Assert.AreEqual(expected, actual); }
private List <Translation> GetWordsFromImport(string path, Import import) { List <Translation> translations = new List <Translation>(); try { using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { String line = sr.ReadLine(); TranslationDirector director = new TranslationDirector(); TranslationBuilder translationBuilder; switch (import) { case Import.Formatted: translationBuilder = new TranslationFormattedBuilder(line); break; case Import.Unformatted: translationBuilder = new TranslationUnformattedBuilder(line); break; default: throw new InvalidDataException(); } director.Construct(translationBuilder); translations.Add(translationBuilder.GetResult()); } } } catch (Exception ex) { Console.WriteLine("Could not read the file"); } return(translations); }