Exemple #1
0
        public async Task <HttpResponseMessage> TranslateToTestSuite()
        {
            if (Request.Content.IsMimeMultipartContent() == false)
            {
                return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
            }

            string outputFilePath = null;

            var workingPath = string.Empty;

            try {
                workingPath = CreateWorkingDirectory();

                var provider = new MultipartFormDataStreamProvider(workingPath);
                await Request.Content.ReadAsMultipartAsync(provider);

                var attachmentsProvider = new AttachmentsProvider(provider);
                var phrases             = attachmentsProvider.Validate();
                if (phrases.Any())
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        ReasonPhrase = string.Join(Environment.NewLine, phrases)
                    });
                }

                using (var reader = new StreamReader(attachmentsProvider.CatalogFileName)) {
                    outputFilePath = ExcelTestSuiteBuilder.CreateExcelTestSuiteTo(new UseCaseReader(workingPath).ReadFrom(reader, attachmentsProvider.CatalogFileName, DateTime.Now), workingPath, attachmentsProvider.TemplateFileName);
                }

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = CreateTestSuiteResponseContent(outputFilePath),
                });
            }
            catch (ApplicationException e) {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = e.Message
                });
            }
            finally {
                try {
                    if (File.Exists(outputFilePath))
                    {
                        File.Delete(outputFilePath);
                    }
                    if (Directory.Exists(workingPath))
                    {
                        Directory.Delete(workingPath);
                    }
                }
                catch {
                    // Do nothing.
                }
            }
        }
Exemple #2
0
        //
        // クラスメソッド
        //

        /// <summary>
        /// 結果を検証する
        /// </summary>
        /// <param name="path">出力ファイルパス</param>
        /// <param name="catalog">ユースケースカタログ</param>
        /// <param name="op">テストスイートビルダー</param>
        private static void AssertResult(string path, UseCaseCatalog catalog, ExcelTestSuiteBuilder op)
        {
            op.Operate();

            var fileName      = string.Format("{0}-テストスイート.xlsx", catalog.Title);
            var testSuitePath = Path.Combine(path, fileName);

            Assert.IsTrue(File.Exists(testSuitePath));
            try {
                using (var testSuite = new XLWorkbook(testSuitePath)) {
                    Assert.IsTrue(2 <= testSuite.Worksheets.Count());

                    var summarySheet = testSuite.Worksheets.First();

                    Assert.IsTrue(summarySheet.Cell(1, 1).Value.ToString() == string.Format("{0} テストスイート", catalog.Title));
                    Assert.IsTrue(summarySheet.Cell(2, 1).Value.ToString() == string.Format("最終更新日時: {0:yyyy-MM-dd}", catalog.LastUpdateTime));

                    var scenarioSetIndex = 0;
                    foreach (var testCaseSetSheet in testSuite.Worksheets.Skip(1))
                    {
                        var scenarioSet = catalog.ScenarioSets.Skip(scenarioSetIndex).First();
                        ++scenarioSetIndex;

                        Assert.IsTrue(testCaseSetSheet.Cell(1, 2).Value.ToString() == scenarioSet.Title);
                        Assert.IsTrue(testCaseSetSheet.Cell(2, 2).Value.ToString() == scenarioSet.Summary);

                        var                   scenarioIndex = 0;
                        var                   actionIndex   = 0;
                        UseCaseScenario       scenario      = null;
                        UseCaseScenarioAction action        = null;
                        var                   rowIndex      = 6;
                        while ((scenarioIndex + 1) < scenarioSet.Scenarios.Count() || (actionIndex + 1) < scenario.Actions.Count())
                        {
                            var row = testCaseSetSheet.Row(rowIndex);
                            ++rowIndex;
                            if (row.CellCount() == 0 || row.Cells().All(cell => string.IsNullOrWhiteSpace(cell.Value.ToString())))
                            {
                                continue;
                            }

                            if (string.IsNullOrWhiteSpace(row.Cell(1).Value.ToString()) == false)
                            {
                                scenario = scenarioSet.Scenarios.Skip(scenarioIndex).First();
                                ++scenarioIndex;
                                actionIndex = 0;
                                Assert.IsTrue(row.Cell(1).Value.ToString() == scenario.Title);
                                Assert.IsTrue(row.Cell(2).Value.ToString() == scenario.Summary);
                                var testCasePreconditions = row.Cell(3).Value.ToString();
                                foreach (var precondition in scenario.Preconditions)
                                {
                                    Assert.IsTrue(testCasePreconditions.Contains(precondition));
                                }
                            }
                            action = scenario.Actions.Skip(actionIndex).First();
                            ++actionIndex;
                            Assert.IsTrue(row.Cell(4).Value.ToString() == actionIndex.ToString());
                            Assert.IsTrue(row.Cell(5).Value.ToString() == action.Action);
                            var testCaseResults = row.Cell(6).Value.ToString();
                            foreach (var result in action.Results)
                            {
                                Assert.IsTrue(testCaseResults.Contains(result));
                            }
                            Assert.IsTrue(row.Cell(7).Value.ToString() == "手動");
                            Assert.IsTrue(string.IsNullOrWhiteSpace(row.Cell(8).Value.ToString()));
                            Assert.IsTrue(string.IsNullOrWhiteSpace(row.Cell(9).Value.ToString()));
                        }
                    }
                }
            }
            finally
            {
                try {
                    File.Delete(testSuitePath);
                }
                catch {
                    // Do nothing.
                }
            }
        }