public void Map_Always_ReturnsUnvalidatedSubtitle()
        {
            var subtitleToMap = new Subtitle(
                new SubtitleId(1),
                new SubtitleTimestamps(
                    TimestampTests.CreateTimestamp(1, 2, 3, 4),
                    TimestampTests.CreateTimestamp(1, 2, 4, 0)),
                new SubtitleText(
                    new List <CharacterLine> {
                new CharacterLine("A line"),
                new CharacterLine("Another line")
            }));

            var expectedUnvalidatedSubtitle = new UnvalidatedSubtitle(
                new List <CharacterLine> {
                new CharacterLine("1"),
                new CharacterLine("01:02:03,004 --> 01:02:04,000"),
                new CharacterLine("A line"),
                new CharacterLine("Another line")
            });

            var stubTimestampsMapper = Substitute.For <ITimestampsMapper>();

            stubTimestampsMapper
            .Map(Arg.Any <SubtitleTimestamps>())
            .Returns(new CharacterLine("01:02:03,004 --> 01:02:04,000"));

            var mapper = new SubtitleToUnvalidatedMapper(stubTimestampsMapper);

            var actualUnvalidatedSubtitle = mapper.Map(subtitleToMap);

            Assert.AreEqual(
                expectedUnvalidatedSubtitle,
                actualUnvalidatedSubtitle);
        }
        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);
        }
Esempio n. 3
0
        public void Map_Always_ReturnsCharacterLine()
        {
            var mapper = CreateMapper();

            var timestampsToMap = new SubtitleTimestamps(
                TimestampTests.CreateTimestamp(5, 4, 3, 2),
                TimestampTests.CreateTimestamp(5, 4, 4, 0));
            var expectedLine = new CharacterLine("05:04:03,002 --> 05:04:04,000");

            var actualLine = mapper.Map(timestampsToMap);

            Assert.AreEqual(expectedLine, actualLine);
        }
        public void Parse_SuccessfulParsing_ReturnsTimestamps(string timestamps)
        {
            var timestampParser = Substitute.For <ITimestampParser>();

            timestampParser
            .Parse(Arg.Any <SubcharacterLine>())
            .Returns(TimestampTests.CreateTimestamp(5, 5, 5, 5));
            var expectedTimestamps = new SubtitleTimestamps(
                TimestampTests.CreateTimestamp(5, 5, 5, 5),
                TimestampTests.CreateTimestamp(5, 5, 5, 5));

            var timestampsParser = CreateParser(timestampParser);

            var actualTimestamps = timestampsParser.Parse(
                new CharacterLine(timestamps));

            Assert.AreEqual(
                expectedTimestamps,
                actualTimestamps);
        }
Esempio n. 5
0
        public void Parse_SuccessfulParsing_ReturnsSubtitle()
        {
            var subtitleToParse = new UnvalidatedSubtitle(
                new List <CharacterLine> {
                new CharacterLine("1"),
                new CharacterLine("00:00:01,100 --> 00:00:03,200"),
                new CharacterLine("Some text"),
                new CharacterLine("More text")
            });

            var stubIdParser = Substitute.For <ISubtitleIdParser>();

            stubIdParser
            .Parse(Arg.Is(new CharacterLine("1")))
            .Returns(new SubtitleId(1));

            var expectedTimestamps = new SubtitleTimestamps(
                TimestampTests.CreateTimestamp(0, 0, 1, 100),
                TimestampTests.CreateTimestamp(0, 0, 3, 200));

            var stubTimestampsParser = Substitute.For <ISubtitleTimestampsParser>();

            stubTimestampsParser
            .Parse(Arg.Is(new CharacterLine("00:00:01,100 --> 00:00:03,200")))
            .Returns(expectedTimestamps);

            var parser = CreateParser(stubIdParser, stubTimestampsParser);

            var expectedSubtitle = new Subtitle(
                new SubtitleId(1),
                expectedTimestamps,
                new SubtitleText(
                    new List <CharacterLine> {
                new CharacterLine("Some text"),
                new CharacterLine("More text")
            }));

            var actualSubtitle = parser.Parse(subtitleToParse);

            Assert.AreEqual(expectedSubtitle, actualSubtitle);
        }
Esempio n. 6
0
        public void Parse_ParsingSuccessful_ReturnsTimestamp()
        {
            var stubValidator = Substitute.For <ITimestampFormatValidator>();

            stubValidator
            .IsFormatCorrect(Arg.Any <SubcharacterLine>())
            .Returns(true);

            var parser = CreateParser(
                CreateParserReturning(new HoursTimestamp(4)),
                CreateParserReturning(new MinutesTimestamp(3)),
                CreateParserReturning(new SecondsTimestamp(2)),
                CreateParserReturning(new MillisecondsTimestamp(1)),
                stubValidator);
            var expectedTimestamp = TimestampTests.CreateTimestamp(4, 3, 2, 1);

            var actualTimestamp = parser.Parse(new SubcharacterLine("04:03:02,001"));

            Assert.AreEqual(
                expectedTimestamp,
                actualTimestamp);
        }
Esempio n. 7
0
        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);
        }