コード例 #1
0
        public void AddAddsFromStatLinesCorrectly()
        {
            var expected   = Helper.MockManyModifiers(4);
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Character, Entity.Totem } &&
                                      s.GivenStatLines == new[] { "s1", "s2" } &&
                                      s.GivenModifiers == new IIntermediateModifier[0])
            };
            var parseParameters = new[]
            {
                new CoreParserParameter("s1", GlobalSource, Entity.Character),
                new CoreParserParameter("s2", GlobalSource, Entity.Character),
                new CoreParserParameter("s1", GlobalSource, Entity.Totem),
                new CoreParserParameter("s2", GlobalSource, Entity.Totem)
            };
            var parseResults = expected.Select(m => ParseResult.Success(new[] { m }))
                               .ToList();
            var parser = Mock.Of <ICoreParser>(p =>
                                               p.Parse(parseParameters[0]) == parseResults[0] &&
                                               p.Parse(parseParameters[1]) == parseResults[1] &&
                                               p.Parse(parseParameters[2]) == parseResults[2] &&
                                               p.Parse(parseParameters[3]) == parseResults[3]);

            var actual = GivenStatsParser.Parse(parser, givenStats);

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void AddThrowsIfStatLineIsNotSuccessfullyParsed()
        {
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Character } &&
                                      s.GivenStatLines == new[] { "s1" } &&
                                      s.GivenModifiers == new IIntermediateModifier[0])
            };
            var parseResult = ParseResult.Failure("", "");
            var parser      = Mock.Of <ICoreParser>(p =>
                                                    p.Parse(new CoreParserParameter("s1", GlobalSource, Entity.Character)) == parseResult);

            Assert.Throws <ParseException>(() => GivenStatsParser.Parse(parser, givenStats));
        }
コード例 #3
0
        public void AddAddsFromStatsCorrectly()
        {
            var expectedStats          = new[] { new StatStub(), };
            var expectedForm           = Form.BaseSet;
            var expectedValue          = new Constant(42);
            var expectedModifierSource = GlobalSource;
            var expected = new[]
            {
                new Modifier(expectedStats, expectedForm, expectedValue, expectedModifierSource)
            };

            var buildParams     = new BuildParameters(expectedModifierSource, Entity.Enemy, expectedForm);
            var formBuilderMock = new Mock <IFormBuilder>();

            formBuilderMock.Setup(b => b.Build())
            .Returns((expectedForm, Funcs.Identity));
            var statBuilderMock = new Mock <IStatBuilder>();

            statBuilderMock.Setup(b => b.Build(buildParams))
            .Returns(new[] { new StatBuilderResult(expectedStats, expectedModifierSource, Funcs.Identity), });
            var valueBuilder         = Mock.Of <IValueBuilder>(b => b.Build(buildParams) == expectedValue);
            var intermediateModifier = ModifierBuilder.Empty
                                       .WithForm(formBuilderMock.Object).WithStat(statBuilderMock.Object).WithValue(valueBuilder)
                                       .Build();
            var givenStats = new[]
            {
                Mock.Of <IGivenStats>(s =>
                                      s.AffectedEntities == new[] { Entity.Enemy } &&
                                      s.GivenStatLines == new string[0] &&
                                      s.GivenModifiers == new[] { intermediateModifier })
            };

            var actual = GivenStatsParser.Parse(Mock.Of <ICoreParser>(), givenStats);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
 public IEnumerable <Func <IReadOnlyList <Modifier> > > CreateGivenModifierParseDelegates()
 => _givenStats.Select <IGivenStats, Func <IReadOnlyList <Modifier> > >(
     g => () => GivenStatsParser.Parse(_coreParser, g));
コード例 #5
0
 public IReadOnlyList <Modifier> ParseGivenModifiers()
 => GivenStatsParser.Parse(_coreParser, _givenStats);
コード例 #6
0
        public static IReadOnlyList <Modifier> Parse(ICoreParser coreParser, IEnumerable <IGivenStats> givenStats)
        {
            var givenParser = new GivenStatsParser(coreParser);

            return(givenStats.SelectMany(givenParser.ParseToModifiers).ToList());
        }
コード例 #7
0
        public void ParseIsEmptyWithNoGivenStats()
        {
            var actual = GivenStatsParser.Parse(Mock.Of <ICoreParser>(), new IGivenStats[0]);

            Assert.IsEmpty(actual);
        }