Exemple #1
0
        public void OperateTest()
        {
            string[] catalogFileNames =
            {
                "UseCaseTranslatorユースケースカタログ.yaml",
            };

            var path = Path.GetFullPath(".");

            foreach (var catalogFileName in catalogFileNames)
            {
                UseCaseCatalog catalog;
                using (var reader = new StreamReader(catalogFileName)) {
                    catalog = new UseCaseReader().ReadFrom(reader, catalogFileName, File.GetLastWriteTime(catalogFileName));
                }

                var parameters = new Dictionary <string, object> {
                    { "input", catalogFileName },
                };
                var op = new CsvFileTestSuiteBuilder(parameters);
                op.Operate();

                // CSVはシナリオごとにファイル生成
                var generatedFiles = new List <string>();
                try {
                    foreach (var scenarioSet in catalog.ScenarioSets)
                    {
                        var fileName        = string.Format("{0}-テストスイート-{1}.csv", catalog.Title, scenarioSet.Title);
                        var scenarioSetPath = Path.Combine(path, fileName);
                        Assert.IsTrue(File.Exists(scenarioSetPath));
                        generatedFiles.Add(scenarioSetPath);

                        // 前後の空白をトリムするので注意
                        using (var parser = new TextFieldParser(scenarioSetPath)) {
                            parser.SetDelimiters(",");

                            Assert.IsFalse(parser.EndOfData);

                            var                   asHeader      = true;
                            var                   scenarioIndex = 0;
                            var                   actionIndex   = 0;
                            UseCaseScenario       scenario      = null;
                            UseCaseScenarioAction action        = null;
                            while (parser.EndOfData == false)
                            {
                                var fields = parser.ReadFields();
                                Assert.IsTrue(fields.Length == 9);
                                if (asHeader)
                                {
                                    asHeader = false;

                                    Assert.IsTrue(fields[0] == "テストケース名");
                                    Assert.IsTrue(fields[1] == "サマリー");
                                    Assert.IsTrue(fields[2] == "Preconditions");
                                    Assert.IsTrue(fields[3] == "アクションNo");
                                    Assert.IsTrue(fields[4] == "アクション");
                                    Assert.IsTrue(fields[5] == "期待結果");
                                    Assert.IsTrue(fields[6] == "実行種別");
                                    Assert.IsTrue(fields[7] == "結果");
                                    Assert.IsTrue(fields[8] == "備考・説明");
                                }
                                else
                                {
                                    if (string.IsNullOrWhiteSpace(fields[0]) == false)
                                    {
                                        scenario = scenarioSet.Scenarios.Skip(scenarioIndex).First();
                                        ++scenarioIndex;
                                        actionIndex = 0;
                                        Assert.IsTrue(fields[0] == scenario.Title);
                                        Assert.IsTrue(fields[1] == scenario.Summary);
                                        Assert.IsTrue(fields[2] == TestSuiteBuilder.ConvertCollectionValue(scenario.Preconditions));
                                    }
                                    action = scenario.Actions.Skip(actionIndex).First();
                                    ++actionIndex;
                                    Assert.IsTrue(fields[3] == actionIndex.ToString());
                                    Assert.IsTrue(fields[4] == action.Action);
                                    Assert.IsTrue(fields[5] == TestSuiteBuilder.ConvertCollectionValue(action.Results));
                                    Assert.IsTrue(fields[6] == "手動");
                                    Assert.IsTrue(string.IsNullOrWhiteSpace(fields[7]));
                                    Assert.IsTrue(string.IsNullOrWhiteSpace(fields[8]));
                                }
                            }
                        }
                    }
                }
                finally {
                    foreach (var file in generatedFiles)
                    {
                        try {
                            File.Delete(file);
                        }
                        catch {
                            // Do nothing.
                        }
                    }
                }
            }
        }