public void ParseReturnsCorrectResult()
        {
            var untranslatedStats = new[]
            {
                new UntranslatedStat("a", 1),
                new UntranslatedStat("b", 2),
                new UntranslatedStat("c", 3),
            };
            var modifierLines        = new[] { "a1", "b2" };
            var statTranslatorResult = new StatTranslatorResult(modifierLines, new UntranslatedStat[0]);
            var translator           = Mock.Of <IStatTranslator>(t => t.Translate(untranslatedStats) == statTranslatorResult);
            var localSource          = new ModifierSource.Local.Skill();
            var globalSource         = new ModifierSource.Global(localSource);
            var coreParserParameters = new[]
            {
                new CoreParserParameter(modifierLines[0], globalSource, Entity.Character),
                new CoreParserParameter(modifierLines[1], globalSource, Entity.Character),
            };
            var parseResults = new[]
            {
                ParseResult.Empty,
                ParseResult.Failure("b2", ""),
            };
            var coreParser = Mock.Of <ICoreParser>(p =>
                                                   p.Parse(coreParserParameters[0]) == parseResults[0] &&
                                                   p.Parse(coreParserParameters[1]) == parseResults[1]);

            var sut             = new UntranslatedStatParser(translator, coreParser);
            var parserParameter = new UntranslatedStatParserParameter(localSource, untranslatedStats);
            var expected        = ParseResult.Aggregate(parseResults);

            var actual = sut.Parse(parserParameter);

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void TranslateReturnsCorrectResult()
        {
            var untranslatedStats = new[]
            {
                new UntranslatedStat("0", 0),
                new UntranslatedStat("1", 1),
                new UntranslatedStat("2", 2),
                new UntranslatedStat("3", 3),
                new UntranslatedStat("4", 4),
            };
            var componentParameters = new IReadOnlyList <UntranslatedStat>[]
            {
                untranslatedStats,
                untranslatedStats.Skip(2).ToList(),
                untranslatedStats.Skip(3).ToList(),
                untranslatedStats.Skip(4).ToList(),
            };
            var componentResults = new[]
            {
                new StatTranslatorResult(new[] { "t0", "t1" }, componentParameters[1]),
                new StatTranslatorResult(new[] { "t2" }, componentParameters[2]),
                new StatTranslatorResult(new[] { "t3" }, componentParameters[3]),
            };
            var components = new[]
            {
                Mock.Of <IStatTranslator>(t => t.Translate(componentParameters[0]) == componentResults[0]),
                Mock.Of <IStatTranslator>(t => t.Translate(componentParameters[1]) == componentResults[1]),
                Mock.Of <IStatTranslator>(t => t.Translate(componentParameters[2]) == componentResults[2]),
            };
            var expected =
                new StatTranslatorResult(new[] { "t0", "t1", "t2", "t3" }, componentParameters[3]);
            var sut = new CompositeStatTranslator(components);

            var actual = sut.Translate(untranslatedStats);

            Assert.AreEqual(expected, actual);
        }