示例#1
0
        public void MakeParseOperation_Always_SplitsLinesAndParamsCorrectly(string blockTag, string[][] configData)
        {
            var testContext = new TestContext()
            {
                BlockTag = blockTag,
                Config   = BuildConfig(configData)
            };
            var mockManagedBlockConfigParseHandler = testContext.AddFakeManagedBlockConfigParseHandler(ParseResult.Success);

            var configLines = new List <ManagedBlockConfigLine>();

            mockManagedBlockConfigParseHandler
            .Setup(x => x.OnParsing(It.IsAny <ManagedBlockConfigLine>()))
            .Callback <ManagedBlockConfigLine>(x => configLines.Add(x))
            .Returns(ParseResult.Success);

            testContext.Uut.MakeParseOperation(testContext.MockBlock.Object)
            .ShouldRunToCompletion(testContext.MockBackgroundWorker);

            configLines.Count.ShouldBe(configData.Length);
            foreach (var i in Enumerable.Range(0, configLines.Count))
            {
                var expectedConfigLine = new ManagedBlockConfigLine(configData[i]);

                configLines[i].BlockTag.ShouldBe(expectedConfigLine.BlockTag);
                configLines[i].Option.ShouldBe(expectedConfigLine.Option);
                configLines[i].ParamCount.ShouldBe(expectedConfigLine.ParamCount);

                foreach (var index in Enumerable.Range(0, configLines[i].ParamCount))
                {
                    configLines[i].GetParam(index).ShouldBe(expectedConfigLine.GetParam(index));
                }
            }
        }
            public ParseResult OnParsing(ManagedBlockConfigLine configLine)
            {
                switch (configLine.Option)
                {
                case "auto-close-interval":
                    int autoCloseIntervalMilliseconds;
                    if ((configLine.ParamCount != 1) ||
                        !int.TryParse(configLine.GetParam(0), out autoCloseIntervalMilliseconds) ||
                        (autoCloseIntervalMilliseconds < 1))
                    {
                        return(ParseResult.FromError("Usage: \"<BlockTag>:auto-close-interval:<AutoCloseInterval>\" (> 0) (ms)"));
                    }
                    _settings.AutoCloseInterval = TimeSpan.FromMilliseconds(autoCloseIntervalMilliseconds);
                    return(ParseResult.Success);

                default:
                    return(ParseResult.Ignored);
                }
            }
示例#3
0
        public void GetParam_Always_ReturnsPieceAtIndexPlus2(int index, IReadOnlyList <string> linePieces)
        {
            var uut = new ManagedBlockConfigLine(linePieces);

            uut.GetParam(index).ShouldBe(linePieces[index + 2]);
        }
示例#4
0
 public static void ShouldHaveReceivedOnParsing(this Mock <IManagedBlockConfigParseHandler> mockHandler, ManagedBlockConfigLine expectedConfigLine)
 => mockHandler
 .ShouldHaveReceived(x => x.OnParsing(It.Is <ManagedBlockConfigLine>(configLine =>
                                                                     (configLine.BlockTag == expectedConfigLine.BlockTag) &&
                                                                     (configLine.Option == expectedConfigLine.Option) &&
                                                                     (configLine.ParamCount == expectedConfigLine.ParamCount) &&
                                                                     Enumerable.Range(0, configLine.ParamCount)
                                                                     .All(index => configLine.GetParam(index) == expectedConfigLine.GetParam(index)))));