public void Parse_SubtitleParserThrows_ThrowsParsingException( int indexOfCorrectSub, int indexOfIncorrectSub) { var subsToParse = new UnvalidatedSubtitles( new List <UnvalidatedSubtitle> { UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle1(), UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle2() }); var stubSubtitleParser = Substitute.For <ISubtitleParser>(); stubSubtitleParser .Parse(Arg.Is(subsToParse.Value.ElementAt(indexOfCorrectSub))) .Returns(SubtitleTests.CreateSubtitle1()); stubSubtitleParser .Parse(Arg.Is(subsToParse.Value.ElementAt(indexOfIncorrectSub))) .Throws <Exception>(); var parser = CreateParser(stubSubtitleParser); var exception = Assert.Throws <SubtitlesParsingException>( () => parser.Parse(subsToParse)); Assert.AreEqual( indexOfIncorrectSub + 1, exception.IncorrectSubtitleId); }
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); }
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); }