public async Task <HttpResponseMessage> TranslateToUseCaseScenario() { if (Request.Content.IsMimeMultipartContent() == false) { return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType)); } 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) }); } UseCaseCatalog catalog; using (var reader = new StreamReader(attachmentsProvider.CatalogFileName)) { catalog = new UseCaseReader(workingPath).ReadFrom(reader, attachmentsProvider.CatalogFileName, DateTime.Now); MarkdownConverter.CreateConvertedMarkdownTo(catalog, workingPath); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = CreateUseCaseScenarioResponseContent(workingPath, provider.Contents[0].Headers.ContentDisposition.FileName, catalog), }); } catch (ApplicationException e) { return(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = e.Message }); } finally { try { if (Directory.Exists(workingPath)) { Directory.Delete(workingPath); } } catch { // Do nothing. } } }
public void ReadInvalidMappingKeyTest() { string[] catalogYamlFiles = { "無効ユースケースカタログ(2).yaml", }; foreach (var catalogYamlFile in catalogYamlFiles) { using (var reader = new StreamReader(catalogYamlFile)) { var catalog = new UseCaseReader().ReadFrom(reader, catalogYamlFile, File.GetLastWriteTime(catalogYamlFile)); } } }
public void OperateWithDefaultTemplateTest() { 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 }, }; AssertResult(path, catalog, new ExcelTestSuiteBuilder(parameters)); } }
public void ReadFromTest() { string[] catalogYamlFiles = { "UseCaseTranslatorユースケースカタログ.yaml", }; foreach (var catalogYamlFile in catalogYamlFiles) { using (var reader = new StreamReader(catalogYamlFile)) { var catalog = new UseCaseReader().ReadFrom(reader, catalogYamlFile, File.GetLastWriteTime(catalogYamlFile)); Assert.IsNotNull(catalog); Assert.IsFalse(string.IsNullOrWhiteSpace(catalog.Title)); Assert.IsNotNull(catalog.ScenarioSets); Assert.IsTrue(0 < catalog.ScenarioSets.Count()); foreach (var scenarioSet in catalog.ScenarioSets) { Assert.IsFalse(string.IsNullOrWhiteSpace(scenarioSet.Title)); Assert.IsFalse(string.IsNullOrWhiteSpace(scenarioSet.Summary)); Assert.IsNotNull(scenarioSet.Scenarios); Assert.IsTrue(0 < scenarioSet.Scenarios.Count()); foreach (var scenario in scenarioSet.Scenarios) { Assert.IsFalse(string.IsNullOrWhiteSpace(scenario.Title)); Assert.IsFalse(string.IsNullOrWhiteSpace(scenario.Summary)); Assert.IsNotNull(scenario.Actions); Assert.IsTrue(0 < scenario.Actions.Count()); foreach (var action in scenario.Actions) { Assert.IsFalse(string.IsNullOrWhiteSpace(action.Action)); Assert.IsNotNull(action.Results); Assert.IsTrue(0 < action.Results.Count()); } } } } } }
public void OperateWithDefaultTemplateTest() { 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 } }; new MarkdownConverter(parameters).Operate(); var generatedFiles = new List <string>(); try { var catalogMdFileName = Path.ChangeExtension(catalog.FileName, ".md"); var catalogMdPath = Path.Combine(path, catalogMdFileName); Assert.IsTrue(File.Exists(catalogMdPath)); generatedFiles.Add(catalogMdPath); string catalogMarkdown; using (var reader = new StreamReader(catalogMdPath)) { catalogMarkdown = reader.ReadToEnd(); } Assert.IsNotNull(catalogMarkdown); Assert.IsFalse(string.IsNullOrWhiteSpace(catalogMarkdown)); AssertWithReferenceFile(catalogMarkdown, path, catalogMdFileName); foreach (var scenarioSet in catalog.ScenarioSets) { var scenarioSetMdFileName = Path.ChangeExtension(scenarioSet.FileName, ".md"); var scenarioSetMdPath = Path.Combine(path, scenarioSetMdFileName); Assert.IsTrue(File.Exists(scenarioSetMdPath)); generatedFiles.Add(scenarioSetMdPath); string scenarioSetMarkdown; using (var reader = new StreamReader(scenarioSetMdPath)) { scenarioSetMarkdown = reader.ReadToEnd(); } Assert.IsNotNull(scenarioSetMarkdown); Assert.IsFalse(string.IsNullOrWhiteSpace(scenarioSetMarkdown)); AssertWithReferenceFile(scenarioSetMarkdown, path, scenarioSetMdFileName); } } finally { foreach (var file in generatedFiles) { try { File.Delete(file); } catch { // Do nothing. } } } } }
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. } } } } }