public void Format_Always_ReturnsCostRelatedToGivenCurrency()
        {
            var stubProvider = Substitute.For <ICostForOneMillionCharactersProvider>();

            stubProvider
            .GetCostIn(Arg.Is(Currency.Euro))
            .Returns(20);

            var stubFormatter = Substitute.For <ISubtitleTextFormatter>();

            stubFormatter
            .Format(Arg.Any <SubtitleText>())
            .Returns("25 characters long string");

            var calculator = CreateCalculator(stubProvider, stubFormatter);

            var twoSubtitles = new Subtitles(
                new List <Subtitle> {
                SubtitleTests.CreateSubtitle1(),
                SubtitleTests.CreateSubtitle2()
            });

            var expectedCost = new Price(0.001m, Currency.Euro);

            var actualCost = calculator.Calculate(twoSubtitles, Currency.Euro);

            Assert.AreEqual(expectedCost, actualCost);
        }
예제 #2
0
        public void Parse_SuccessfulParsing_ReturnsSubtitles()
        {
            var unvalidatedSubtitles = new UnvalidatedSubtitles(
                new List <UnvalidatedSubtitle> {
                UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle1(),
                UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle2()
            });

            var expectedSubtitles = new Subtitles(
                new List <Subtitle> {
                SubtitleTests.CreateSubtitle1(),
                SubtitleTests.CreateSubtitle2()
            });

            var stubParser = Substitute.For <ISubtitleParser>();

            stubParser
            .Parse(Arg.Is(unvalidatedSubtitles.Value.ElementAt(0)))
            .Returns(expectedSubtitles.Value.ElementAt(0));

            stubParser
            .Parse(Arg.Is(unvalidatedSubtitles.Value.ElementAt(1)))
            .Returns(expectedSubtitles.Value.ElementAt(1));

            var parser = CreateParser(stubParser);

            var actualSubtitles = parser.Parse(unvalidatedSubtitles);

            Assert.AreEqual(
                expectedSubtitles,
                actualSubtitles);
        }
        public void Map_Always_ReturnsUnvalidatedSubtitles()
        {
            var subsToMap = new Subtitles(
                new List <Subtitle> {
                SubtitleTests.CreateSubtitle1(),
                SubtitleTests.CreateSubtitle2()
            });

            var stubMapper = Substitute.For <ISubtitleToUnvalidatedMapper>();

            var expectedUnvalidatedSubs = new UnvalidatedSubtitles(
                new List <UnvalidatedSubtitle> {
                UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle1(),
                UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle2()
            });

            stubMapper
            .Map(Arg.Is(subsToMap.Value.ElementAt(0)))
            .Returns(expectedUnvalidatedSubs.Value.ElementAt(0));
            stubMapper
            .Map(Arg.Is(subsToMap.Value.ElementAt(1)))
            .Returns(expectedUnvalidatedSubs.Value.ElementAt(1));

            var mapper = CreateMapper(stubMapper);

            var actualUnvalidatedSubs = mapper.Map(subsToMap);

            Assert.AreEqual(
                expectedUnvalidatedSubs,
                actualUnvalidatedSubs);
        }