public Add ( DocumentType type, IEnumerable |
||
type | DocumentType | |
files | IEnumerable |
|
sourceDir | string | |
destinationDir | string | |
리턴 | void |
public void ProcessMarkdownTocWithAbsoluteHrefShouldSucceed() { var content = @" #[Topic1](/href1) ##Topic1.1 ###[Topic1.1.1](/href1.1.1) ##[Topic1.2]() #[Topic2](http://href.com) "; var toc = _fileCreator.CreateFile(content, FileType.MarkdownToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath); var expectedModel = new TocItemViewModel { Items = new TocViewModel { new TocItemViewModel { Name = "Topic1", Href = "/href1", TopicHref = "/href1", Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1", Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1.1", Href = "/href1.1.1", TopicHref = "/href1.1.1" } } }, new TocItemViewModel { Name = "Topic1.2", Href = string.Empty, TopicHref = string.Empty } } }, new TocItemViewModel { Name = "Topic2", Href = "http://href.com", TopicHref = "http://href.com" } } }; AssertTocEqual(expectedModel, model); }
public RestApiDocumentProcessorTest() { _outputFolder = GetRandomFolder(); _inputFolder = GetRandomFolder(); _templateFolder = GetRandomFolder(); _defaultFiles = new FileCollection(Directory.GetCurrentDirectory()); _defaultFiles.Add(DocumentType.Article, new[] { "TestData/contacts.json" }, "TestData/"); _applyTemplateSettings = new ApplyTemplateSettings(_inputFolder, _outputFolder); _applyTemplateSettings.RawModelExportSettings.Export = true; }
public void ProcessYamlTocWithTocHrefShouldSucceed() { var file1 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent); var file2 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub1/sub2"); var referencedToc = _fileCreator.CreateFile($@" - name: Topic href: {Path.GetFileName(file2)} ", FileType.YamlToc, "sub1/sub2"); var content = $@" - name: Topic1 tocHref: /Topic1/ topicHref: /Topic1/index.html items: - name: Topic1.1 tocHref: /Topic1.1/ topicHref: /Topic1.1/index.html - name: Topic1.2 tocHref: /Topic1.2/ topicHref: /Topic1.2/index.html - name: Topic2 tocHref: {referencedToc} topicHref: {file2} "; var toc = _fileCreator.CreateFile(content, FileType.YamlToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { file1, file2, toc, referencedToc }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath); var expectedModel = new TocItemViewModel { Items = new TocViewModel { new TocItemViewModel { Name = "Topic1", Href = "/Topic1/", TocHref = "/Topic1/", Homepage = "/Topic1/index.html", TopicHref = "/Topic1/index.html", Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1", Href = "/Topic1.1/", TocHref = "/Topic1.1/", Homepage = "/Topic1.1/index.html", TopicHref = "/Topic1.1/index.html", }, new TocItemViewModel { Name = "Topic1.2", Href = "/Topic1.2/", TocHref = "/Topic1.2/", Homepage = "/Topic1.2/index.html", TopicHref = "/Topic1.2/index.html", } } }, new TocItemViewModel { Name = "Topic2", TocHref = referencedToc, Href = referencedToc, TopicHref = file2, Homepage = file2, } } }; AssertTocEqual(expectedModel, model); }
public void ProcessTocWithCircularReferenceShouldFail() { var referencedToc = _fileCreator.CreateFile($@" - name: Topic href: TOC.md ", FileType.YamlToc, "sub1"); var subToc = _fileCreator.CreateFile($@" #Topic ##[ReferencedToc](Toc.yml) ", FileType.MarkdownToc, "sub1"); var content = $@" - name: Topic1 href: {subToc} "; var toc = _fileCreator.CreateFile(content, FileType.YamlToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc, subToc }); var e = Assert.Throws<DocumentException>(() => BuildDocument(files)); Assert.Equal($"Circular reference to {StringExtension.ToDisplayPath(Path.GetFullPath(Path.Combine(_inputFolder, subToc)))} is found in {StringExtension.ToDisplayPath(Path.GetFullPath(Path.Combine(_inputFolder, referencedToc)))}", e.Message, true); }
public void ProcessYamlTocWithReferencedTocShouldSucceed() { var file1 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent); var file2 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub1"); var file3 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub1/sub2"); var referencedToc = _fileCreator.CreateFile($@" - name: Topic href: {Path.GetFileName(file3)} ", FileType.YamlToc, "sub1/sub2"); var subToc = _fileCreator.CreateFile($@" #[Topic]({Path.GetFileName(file2)}) #[ReferencedToc](sub2/{Path.GetFileName(referencedToc)}) ", FileType.MarkdownToc, "sub1"); var content = $@" - name: Topic1 href: {file1} items: - name: Topic1.1 href: {subToc} items: - name: Topic1.1.1 - name: Topic1.1.2 - name: Topic1.2 href: {subToc} homepage: {file1} - name: Topic2 href: {referencedToc} "; var toc = _fileCreator.CreateFile(content, FileType.YamlToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { file1, file2, file3, toc, subToc }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath); var expectedModel = new TocItemViewModel { Items = new TocViewModel { new TocItemViewModel { Name = "Topic1", Href = file1, TopicHref = file1, Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1", Href = null, // For referenced toc, the content from the referenced toc is expanded as the items of current toc, and href is cleared TopicHref = null, Items = new TocViewModel { new TocItemViewModel { Name = "Topic", Href = file2, TopicHref = file2, }, new TocItemViewModel { Name = "ReferencedToc", Items = new TocViewModel { new TocItemViewModel { Name = "Topic", Href = file3, TopicHref = file3, } } } } }, new TocItemViewModel { Name = "Topic1.2", Href = file1, // For referenced toc, href should be overwritten by homepage TopicHref = file1, Homepage = file1, Items = new TocViewModel { new TocItemViewModel { Name = "Topic", Href = file2, TopicHref = file2, }, new TocItemViewModel { Name = "ReferencedToc", Items = new TocViewModel { new TocItemViewModel { Name = "Topic", Href = file3, TopicHref = file3, } } } } } } }, new TocItemViewModel { Name = "Topic2", Href = null, Items = new TocViewModel { new TocItemViewModel { Name = "Topic", Href = file3, TopicHref = file3, } } } } }; AssertTocEqual(expectedModel, model); // Referenced TOC File should not exist var referencedTocPath = Path.Combine(_outputFolder, Path.ChangeExtension(subToc, RawModelFileExtension)); Assert.False(File.Exists(referencedTocPath)); }
public void ProcessYamlTocWithFolderShouldSucceed() { var file1 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent); var file2 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub"); var subToc = _fileCreator.CreateFile($@" #[Topic]({Path.GetFileName(file2)}) ", FileType.MarkdownToc, "sub"); var content = $@" - name: Topic1 href: {file1} items: - name: Topic1.1 href: {file1} homepage: {file2} - name: Topic1.2 href: sub/ homepage: {file1} - name: Topic2 href: sub/ "; var toc = _fileCreator.CreateFile(content, FileType.YamlToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { file1, file2, toc, subToc }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath); var expectedModel = new TocItemViewModel { Items = new TocViewModel { new TocItemViewModel { Name = "Topic1", Href = file1, TopicHref = file1, Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1", Href = file1, // For relative file, href keeps unchanged Homepage = file2, // Homepage always keeps unchanged TopicHref = file2, }, new TocItemViewModel { Name = "Topic1.2", Href = file1, // For relative folder, href should be overwritten by homepage Homepage = file1, TopicHref = file1, TocHref = "sub/toc.md", } } }, new TocItemViewModel { Name = "Topic2", Href = file2, TopicHref = file2, TocHref = "sub/toc.md", } } }; AssertTocEqual(expectedModel, model); }
private static FileCollection GetFileCollectionFromFileMapping(string baseDirectory, DocumentType type, FileMapping files) { var result = new FileCollection(baseDirectory); foreach (var mapping in files.Items) { result.Add(type, mapping.Files, mapping.SourceFolder, mapping.DestinationFolder); } return result; }
public void ProcessSwaggerWithRemarksOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.remarks.md" }); BuildDocument(files); { var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.remarks.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Remarks content</p>\n", model.Remarks); } }
public void ProcessSwaggerWithMultiUidOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.multi.uid.md" }); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.unmergable.md" }); BuildDocument(files); { var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.multi.uid.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content1</p>\n", model.Conceptual); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.multi.uid.md\" sourcestartlinenumber=\"13\" sourceendlinenumber=\"13\">Overwrite "content2"</p>\n", model.Summary); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.multi.uid.md\" sourcestartlinenumber=\"20\" sourceendlinenumber=\"20\">Overwrite 'content3'</p>\n", model.Metadata["not_defined_property"]); } }
public void ProcessSwaggerWithUnmergableOverwriteShouldSucceed() { FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.unmergable.md" }); BuildDocument(files); { var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); } }
public void ProcessSwaggerWithInvalidOverwriteShouldFail() { FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.invalid.md" }); Assert.Throws<DocumentException>(() => BuildDocument(files)); }
public void ProcessSwaggerWithNotPredefinedOverwriteShouldSucceed() { FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.not.predefined.md" }); BuildDocument(files); { var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.not.predefined.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content</p>\n", model.Metadata["not_defined_property"]); Assert.Null(model.Conceptual); } }
public void ProcessSwaggerWithSimpleOverwriteShouldSucceed() { FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.simple.md" }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.simple.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content</p>\n", model.Summary); Assert.Null(model.Conceptual); // Verify overwrite parameters var parametersForUpdate = model.Children.Single(c => c.OperationId == "update contact").Parameters; Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.simple.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new object_id description</p>\n", parametersForUpdate.Single(p => p.Name == "object_id").Description); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.simple.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new bodyparam description</p>\n", parametersForUpdate.Single(p => p.Name == "bodyparam").Description); }
public void ProcessSwaggerWithTagsOverwriteShouldSucceed() { FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.tags.md" }); BuildDocument(files); { var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); var tag1 = model.Tags[0]; Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.tags.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite <em>description</em> content</p>\n", tag1.Description); Assert.Null(tag1.Conceptual); var tag2 = model.Tags[1]; Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">Access to Petstore orders</p>\n", tag2.Description); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.tags.md\" sourcestartlinenumber=\"12\" sourceendlinenumber=\"12\">Overwrite <strong>conceptual</strong> content</p>\n", tag2.Conceptual); } }
public void RelativePathToTocShouldChooseTheNearestReferenceToc() { // |-toc.md // |-sub1 // |-sub2 // |-file // |-sub3 // |-toc.md // Arrange const string fileFolder = "sub1/sub2"; var file = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, fileFolder); var toc1 = _fileCreator.CreateFile($"#[Topic]({file})", FileType.MarkdownToc); const string toc2Folder = "sub1/sub2/sub3"; var filePathRelativeToToc2 = ((RelativePath) file).MakeRelativeTo((RelativePath)toc2Folder); var toc2 = _fileCreator.CreateFile($"#[Same Topic]({filePathRelativeToToc2.FileName}", FileType.MarkdownToc, toc2Folder); var files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { file, toc1, toc2 }); // Act BuildDocument(files); // Assert var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(file, RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<Dictionary<string, object>>(outputRawModelPath); Assert.Equal("../../toc.md", model["_tocRel"]); }
public void ProcessYamlTocWithTocHrefAndHomepageShouldFail() { var content = $@" - name: Topic1 tocHref: /Topic1/ href: /Topic1/index.html homepage: /Topic1/index.html "; var toc = _fileCreator.CreateFile(content, FileType.YamlToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc }); var e = Assert.Throws<DocumentException>(() => BuildDocument(files)); Assert.Equal("TopicHref should be used to specify the homepage for /Topic1/ when tocHref is used.", e.Message); }
public void ProcessSwaggerWithParametersOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.parameters.md" }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath); // Verify overwrite parameters var parametersForUpdate = model.Children.Single(c => c.OperationId == "update contact").Parameters; Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.parameters.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new object_id description</p>\n", parametersForUpdate.Single(p => p.Name == "object_id").Description); var bodyparam = parametersForUpdate.Single(p => p.Name == "bodyparam"); Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.parameters.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new bodyparam description</p>\n", bodyparam.Description); var properties = (JObject)(((JObject)bodyparam.Metadata["schema"])["properties"]); var objectType = properties["objectType"]; Assert.Equal("string", objectType["type"]); Assert.Equal("this is overwrite objectType description", objectType["description"]); var errorDetail = properties["provisioningErrors"]["items"]["schema"]["properties"]["errorDetail"]; Assert.Equal(JTokenType.Boolean, errorDetail["readOnly"].Type); Assert.Equal("false", errorDetail["readOnly"].ToString().ToLower()); Assert.Equal("this is overwrite errorDetail description", errorDetail["description"]); var paramForUpdateManager = model.Children.Single(c => c.OperationId == "get contact memberOf links").Parameters.Single(p => p.Name == "bodyparam"); var paramForAllOf = ((JObject)paramForUpdateManager.Metadata["schema"])["allOf"]; // First allOf item is not overwritten Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">original first allOf description</p>\n", paramForAllOf[0]["description"]); // Second allOf item is overwritten Assert.Equal("this is second overwrite allOf description", paramForAllOf[1]["description"]); Assert.Equal("this is overwrite location description", paramForAllOf[1]["properties"]["location"]["description"]); // Third allOf item's enum value is overwritten var paramForLevel = paramForAllOf[2]["properties"]["level"]; Assert.Equal("this is overwrite level description", paramForLevel["description"]); Assert.Equal(3, paramForLevel["enum"].Count()); Assert.Equal("Verbose", paramForLevel["enum"][0].ToString()); Assert.Equal("Info", paramForLevel["enum"][1].ToString()); Assert.Equal("Warning", paramForLevel["enum"][2].ToString()); }