public void Translate_TranslationSuccessful_ReturnsTranslatedBatch() { var batchToTranslate = new List <Subtitle> { new Subtitle( new SubtitleId(1), new SubtitleTimestamps( TimestampTests.CreateTimestamp(0, 0, 0, 0), TimestampTests.CreateTimestamp(0, 0, 0, 3)), CreateSingleLineText("First subtitle")), new Subtitle( new SubtitleId(2), new SubtitleTimestamps( TimestampTests.CreateTimestamp(0, 0, 0, 4), TimestampTests.CreateTimestamp(0, 0, 0, 7)), CreateSingleLineText("Second subtitle")) }; var expectedTranslation = new List <Subtitle> { SubtitleTests.CopyWithNewText(batchToTranslate[0], "Premier sous-titre"), SubtitleTests.CopyWithNewText(batchToTranslate[1], "Deuxième sous-titre") }; var stubTranslator = Substitute.For <IBatchTextTranslator>(); stubTranslator .Translate( Arg.Is <List <string> >( a => a.SequenceEqual(new List <string> { "First subtitle", "Second subtitle" })), Arg.Is(Language.French)) .Returns( new List <string> { "Premier sous-titre", "Deuxième sous-titre" }); var stubFormatter = Substitute.For <ISubtitleTextFormatter>(); stubFormatter .Format(Arg.Is(CreateSingleLineText("First subtitle"))) .Returns("First subtitle"); stubFormatter .Format(Arg.Is(CreateSingleLineText("Second subtitle"))) .Returns("Second subtitle"); var translator = CreateTranslator(stubTranslator, stubFormatter); var actualTranslation = translator.Translate(batchToTranslate, Language.French); Assert.AreEqual(expectedTranslation, actualTranslation); }
public void Translate_TranslationSuccessful_ReturnsTranslatedSubtitles() { var s1 = new Subtitle( new SubtitleId(1), new SubtitleTimestamps( TimestampTests.CreateTimestamp(0, 0, 0, 0), TimestampTests.CreateTimestamp(0, 0, 0, 3)), CreateSingleLineText("First subtitle")); var translated_s1 = SubtitleTests.CopyWithNewText(s1, "Premier sous-titre"); var s2 = new Subtitle( new SubtitleId(2), new SubtitleTimestamps( TimestampTests.CreateTimestamp(0, 0, 0, 4), TimestampTests.CreateTimestamp(0, 0, 0, 7)), CreateSingleLineText("Second subtitle")); var translated_s2 = SubtitleTests.CopyWithNewText(s2, "Deuxième sous-titre"); var s3 = new Subtitle( new SubtitleId(3), new SubtitleTimestamps( TimestampTests.CreateTimestamp(0, 0, 0, 8), TimestampTests.CreateTimestamp(0, 0, 0, 11)), CreateSingleLineText("Third subtitle")); var translated_s3 = SubtitleTests.CopyWithNewText(s2, "Troisième sous-titre"); var stubBatchTranslator = Substitute.For <ISubtitleBatchTranslator>(); stubBatchTranslator .Translate( Arg.Is <List <Subtitle> >( b => b.SequenceEqual(new List <Subtitle> { s1, s2 })), Arg.Is(Language.French)) .Returns(new List <Subtitle> { translated_s1, translated_s2 }); stubBatchTranslator .Translate( Arg.Is <List <Subtitle> >( b => b.SequenceEqual(new List <Subtitle> { s3 })), Arg.Is(Language.French)) .Returns(new List <Subtitle> { translated_s3 }); var toTranslate = new Subtitles( new List <Subtitle> { s1, s2, s3 }); var expectedTranslation = new Subtitles( new List <Subtitle> { translated_s1, translated_s2, translated_s3 }); var translator = new BatchSubtitlesTranslator(stubBatchTranslator, 2); var actualTranslation = translator.Translate(toTranslate, Language.French); Assert.AreEqual(expectedTranslation, actualTranslation); }