public void ProcessSwaggerWithExternalEmbeddedReferenceShouldSucceed() { var files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { "TestData/swagger/contactsForExternalRef.json" }, "TestData/"); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contactsForExternalRef.json"); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <RestApiRootItemViewModel>(outputRawModelPath); var operation = model.Children.Single(c => c.OperationId == "update_contact_manager"); var externalSchema = (JObject)operation.Parameters[2].Metadata["schema"]; Assert.Equal("<p sourcefile=\"TestData/swagger/contactsForExternalRef.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"><strong>uri</strong> description.</p>\n", externalSchema["description"]); Assert.Equal("string", externalSchema["type"]); Assert.Equal("uri", externalSchema["format"]); Assert.Equal("refUrl", externalSchema["x-internal-ref-name"]); }
public void SystemKeysListShouldBeComplete() { var fileName = "test.md"; var file = _fileCreator.CreateFile("# test", fileName); var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { file }); BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <Dictionary <string, object> >(outputRawModelPath); var systemKeys = (JArray)model[Constants.PropertyName.SystemKeys]; Assert.NotEmpty(systemKeys); foreach (var key in model.Keys.Where(key => key[0] != '_' && key != "meta")) { Assert.Contains(key, systemKeys); } } }
public void ProcessMrefWithNotPredefinedOverwriteShouldSucceed() { FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.not.predefined.md" }); BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <ApiBuildOutput>(outputRawModelPath); Assert.Equal("<p sourcefile=\"TestData/overwrite/mref.overwrite.not.predefined.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content</p>\n" , model.Metadata["not_defined_property"]); var method = model.Children.First(s => s.Uid == "CatLibrary.Cat`2.#ctor"); Assert.Equal("<p sourcefile=\"TestData/overwrite/mref.overwrite.not.predefined.md\" sourcestartlinenumber=\"13\" sourceendlinenumber=\"13\">Overwrite content</p>\n" , method.Metadata["not_defined_property"]); } }
public void TestInvalidMetadataReference() { using (var listener = new TestListenerScope("TestGeneralFeaturesInSDP")) { var schemaFile = CreateFile("template/schemas/mta.reference.test.schema.json", @" { ""$schema"": ""http://dotnet.github.io/docfx/schemas/v1.0/schema.json#"", ""version"": ""1.0.0"", ""title"": ""MetadataReferenceTest"", ""description"": ""A simple test schema for sdp"", ""type"": ""object"", ""properties"": { ""metadata"": { ""type"": ""string"" } }, ""metadata"": ""/metadata"" } ", _templateFolder); var inputFileName1 = "page1.yml"; var inputFile1 = CreateFile(inputFileName1, @"### YamlMime:MetadataReferenceTest title: Web Apps Documentation metadata: title: Azure Web Apps Documentation - Tutorials, API Reference meta.description: Learn how to use App Service Web Apps to build and host websites and web applications. ms.service: app-service ms.tgt_pltfrm: na ms.author: carolz sections: - title: 5-Minute Quickstarts toc_rel: ../a b/toc.md uhfHeaderId: MSDocsHeader-DotNet searchScope: - .NET ", _inputFolder); FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { inputFile1 }, _inputFolder); Assert.Throws <InvalidJsonPointerException>(() => BuildDocument(files)); } }
protected virtual FileCollection GetAllChildrenFiles(File file, FileCollection allfiles) { FileCollection files = new FileCollection(); foreach (Sprite sprite in file.Sprites.SortByOrder()) { if (sprite.RelatiedFile == file.FileID) { continue; } File relatiedFile = allfiles.TryGetItem(sprite.RelatiedFile); if (relatiedFile != null && !files.Contains(relatiedFile.FileID)) { files.Add(relatiedFile); } } return(files.SortByOrder()); }
public void ProcessSwaggerWithInvalidOverwriteShouldFail() { FileCollection files = new FileCollection(_defaultFiles); var parameters = new DocumentBuildParameters { Files = files, OutputBaseDir = _outputFolder, ApplyTemplateSettings = _applyTemplateSettings, Metadata = new Dictionary <string, object> { ["meta"] = "Hello world!", }.ToImmutableDictionary() }; files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.invalid.md" }); parameters.Files = files; using (var builder = new DocumentBuilder()) { Assert.Throws <DocumentException>(() => builder.Build(parameters)); } }
public void ProcessMrefEnumShouldSucceed() { var files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { "TestData/mref/Microsoft.DocAsCode.Build.SchemaDriven.MergeType.yml" }, "TestData/"); BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("Microsoft.DocAsCode.Build.SchemaDriven.MergeType.yml"); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <ApiBuildOutput>(outputRawModelPath); Assert.NotNull(model); Assert.Equal("Hello world!", model.Metadata["meta"]); Assert.False(model.Metadata.TryGetValue("_splitReference", out var split)); Assert.False(model.Metadata.TryGetValue("_splitFrom", out var from)); Assert.Equal(4, model.Children.Count); } { var xrefmap = YamlUtility.Deserialize <XRefMap>(Path.Combine(_outputFolder, "xrefmap.yml")); Assert.Equal(5, xrefmap.References.Count); } }
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 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); }
private void RenderFavorites(ObservableCollection <cc310_reference_centre_file> favorites) { IsCheckIOBusy = true; FileCollection.Clear(); foreach (var mFile in favorites) { //Get Icons string shortCutPath = mFile.file_full_nm; string icon = IconUtilities.GetIconString(shortCutPath); FileInfo fileInfo = new FileInfo(mFile.file_path_txt); TCFile file = new TCFile(fileInfo.Name, fileInfo.FullName, previousFolder, TCFile.TCType.FAVORITE, icon); //new TCFile(fileInfo, image, true); file.DoubleClickEvent += File_DoubleClickEvent; file.FileClickedEvent += File_FileClickedEvent; file.InfoPanelClickEvent += File_InfoPanelClickEvent; file.FavouriteClickEvent += File_FavouriteClickEvent; FileCollection.Add(file); } IsCheckIOBusy = false; }
public void ProcessMarkdownFileWithBreakLinkInTokenShouldSucceed() { var fileName = "normal.md"; var tokenFileName = "token.md"; var file = _fileCreator.CreateFile($"[!include[]({tokenFileName})]", fileName); _fileCreator.CreateFile("[Main](a#b)", tokenFileName); var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { file }); BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file); Assert.True(File.Exists(outputRawModelPath)); var outputHtml = GetOutputFilePath(file); Assert.True(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); Assert.Equal($@"<!-- BEGIN INCLUDE: Include content from "{tokenFileName}" --><p><a href=""a#b"">Main</a></p> <!--END INCLUDE -->".Replace("\r\n", "\n"), content); } }
public FileCollection OpenFiles() { var dialog = new Microsoft.Win32.OpenFileDialog { Multiselect = true }; if (dialog.ShowDialog() == true) { var collection = new FileCollection(); foreach (var file in dialog.FileNames) { var fileInfo = new FileInfo(file); collection.Add(fileInfo); } return(collection); } return(null); }
public void WarningShouldBeFromIncludedToc() { // Arrange var masterContent = @" - name: TOC2 href: ../included/toc.yml"; var includedContent = @" - name: Article2 href: not-existing2.md - name: Article3ByUid uid: not-existing-uid"; var files = new FileCollection(_inputFolder); var masterFile = _fileCreator.CreateFile(masterContent, FileType.YamlToc, "master"); var includedFile = _fileCreator.CreateFile(includedContent, FileType.YamlToc, "included"); files.Add(DocumentType.Article, new[] { masterFile }); // Act var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter( new List <string> { WarningCodes.Build.InvalidFileLink, WarningCodes.Build.UidNotFound }); Logger.RegisterListener(listener); using (new LoggerPhaseScope(nameof(TocDocumentProcessorTest))) { BuildDocument(files); } Logger.UnregisterListener(listener); // Assert Assert.NotNull(listener.Items); Assert.Equal(2, listener.Items.Count); Assert.Equal(WarningCodes.Build.InvalidFileLink, listener.Items[0].Code); Assert.Equal("~/included/toc.yml", listener.Items[0].File); Assert.Equal(WarningCodes.Build.UidNotFound, listener.Items[1].Code); Assert.Equal("~/included/toc.yml", listener.Items[1].File); }
public void RelativePathToTocShouldExistWithUrlEncodedHref() { // Arrange const string fileFolder = "sub1()"; const string fileFolderEncoded = "sub1%28%29"; var file = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, fileFolder); var toc1 = _fileCreator.CreateFile($"#[Topic]({Path.Combine(fileFolderEncoded, Path.GetFileName(file))})", FileType.MarkdownToc); var toc2 = _fileCreator.CreateFile($"# a nearer toc", FileType.MarkdownToc, fileFolder); var files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { file, toc1, toc2 }); // Act BuildDocument(files); // Assert var outputRawModelPath = Path.GetFullPath(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 LoadTocYamlWithEmptyNodeShouldSucceed() { // Arrange var content = @" - name: x href: a.md -"; var files = new FileCollection(_inputFolder); var file = _fileCreator.CreateFile(content, FileType.YamlToc); files.Add(DocumentType.Article, new[] { file }); // Act BuildDocument(files); // Assert var outputRawModelPath = Path.GetFullPath(Path.Combine(_outputFolder, Path.ChangeExtension(file, RawModelFileExtension))); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <TocRootViewModel>(outputRawModelPath); Assert.Single(model.Items); // empty node is removed }
public void ProcessMrefWithDynamicDevLangsShouldSucceed() { FileCollection files = new FileCollection(_defaultFiles); files.RemoveAll(s => true); files.Add(DocumentType.Article, new [] { "TestData/mref/System.String.yml" }, "TestData/"); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("System.String.yml"); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <ApiBuildOutput>(outputRawModelPath); Assert.NotNull(model); Assert.NotNull(model.Syntax); Assert.NotNull(model.Syntax.Content); Assert.Equal(4, model.Syntax.Content.Count); Assert.Equal("public ref class String sealed", model.Syntax.Content.First(c => c.Language == "cpp").Value); Assert.Equal("public sealed class String", model.Syntax.Content.First(c => c.Language == "csharp").Value); Assert.Equal("type String", model.Syntax.Content.First(c => c.Language == "fsharp").Value); Assert.Equal("Public NotInheritable Class String", model.Syntax.Content.First(c => c.Language == "vb").Value); }
public MergeMarkdownFragmentsTest() { _outputFolder = GetRandomFolder(); _inputFolder = GetRandomFolder(); _templateFolder = GetRandomFolder(); _defaultFiles = new FileCollection(Directory.GetCurrentDirectory()); _applyTemplateSettings = new ApplyTemplateSettings(_inputFolder, _outputFolder) { RawModelExportSettings = { Export = true }, TransformDocument = true, }; _templateManager = new TemplateManager(null, null, new List <string> { "template" }, null, _templateFolder); _listener = TestLoggerListener.CreateLoggerListenerWithPhaseEqualFilter(null); _rawModelFilePath = GetRawModelFilePath("Suppressions.yml"); var schemaFile = CreateFile("template/schemas/rest.mixed.schema.json", File.ReadAllText("TestData/schemas/rest.mixed.schema.json"), _templateFolder); var yamlFile = CreateFile("Suppressions.yml", File.ReadAllText("TestData/inputs/Suppressions.yml"), _inputFolder); _files = new FileCollection(_defaultFiles); _files.Add(DocumentType.Article, new[] { yamlFile }, _inputFolder); }
public void ProcessMarkdownFileWithComplexCharsShouldSucceed() { var fileName1 = "A#ctor.md"; var fileName2 = "normal.md"; var file1 = _fileCreator.CreateFile($@" [Main]({HttpUtility.UrlEncode(fileName2)}) ", fileName1); var file2 = _fileCreator.CreateFile($@" [Constructor]({HttpUtility.UrlEncode(fileName1)}) ", fileName2); var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { file1, file2 }); BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file2); Assert.True(File.Exists(outputRawModelPath)); var outputHtml = GetOutputFilePath(file2); Assert.True(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); Assert.Equal("<p><a href=\"A%23ctor.html\">Constructor</a></p>\n", content); } }
/// <summary> /// 分析所有文件 /// </summary> public virtual void AnalyseAllFile() { FileCollection mResults = new FileCollection(); mResults.AnalyseTime = System.DateTime.Now; mResults.Document = this; int iTick = System.Environment.TickCount; foreach (ProjectFileEntity item in this.files) { FileEntity mResult = mResults.Add(item.FileName); mResult.Analysed = false; if (item.CanAnalyse == false) { continue; } foreach (FileAnalyser mAnalyser in this.analysers) { mAnalyser.Document = this; if (mAnalyser.CheckFileName(mResult.FullName)) { if (System.IO.File.Exists(mResult.FullName)) { mAnalyser.Analyse(mResult); mResult.Analysed = true; } else { mResult.Analysed = false; } } } } this.results.Add(mResults); this.tick = System.Environment.TickCount - iTick; }
public void TestValidMetadataReferenceWithIncremental() { using (var listener = new TestListenerScope("TestGeneralFeaturesInSDP")) { var schemaFile = CreateFile("template/schemas/mta.reference.test.schema.json", @" { ""$schema"": ""http://dotnet.github.io/docfx/schemas/v1.0/schema.json#"", ""version"": ""1.0.0"", ""title"": ""MetadataReferenceTest"", ""description"": ""A simple test schema for sdp"", ""type"": ""object"", ""properties"": { ""metadata"": { ""type"": ""object"" }, ""href"": { ""type"": ""string"", ""contentType"": ""href"" } }, ""metadata"": ""/metadata"" } ", _templateFolder); var inputFileName1 = "page1.yml"; var inputFile1 = CreateFile(inputFileName1, @"### YamlMime:MetadataReferenceTest title: Web Apps Documentation metadata: title: Azure Web Apps Documentation - Tutorials, API Reference meta.description: Learn how to use App Service Web Apps to build and host websites and web applications. ms.service: app-service ms.tgt_pltfrm: na ms.author: carolz href: toc.md sections: - title: 5-Minute Quickstarts toc_rel: ../a b/toc.md uhfHeaderId: MSDocsHeader-DotNet searchScope: - .NET ", _inputFolder); var dependentMarkdown = CreateFile("toc.md", "# Hello", _inputFolder); var inputFileName2 = "page2.yml"; var inputFile2 = CreateFile(inputFileName2, @"### YamlMime:MetadataReferenceTest title: Web Apps Documentation ", _inputFolder); FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { inputFile1, inputFile2, dependentMarkdown }, _inputFolder); using (new LoggerPhaseScope("FirstRound")) { BuildDocument(files); } Assert.Equal(3, listener.Items.Count); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): MetadataReferenceTest,Toc"))); listener.Items.Clear(); var rawModelFilePath = GetRawModelFilePath(inputFileName1); Assert.True(File.Exists(rawModelFilePath)); var rawModel = JsonUtility.Deserialize <JObject>(rawModelFilePath); Assert.Equal("overwritten", rawModel["metadata"]["meta"].ToString()); Assert.Equal("postbuild1", rawModel["metadata"]["postMeta"].ToString()); Assert.Equal("1", rawModel["metadata"]["another"].ToString()); Assert.Equal("app-service", rawModel["metadata"]["ms.service"].ToString()); var rawModelFilePath2 = GetRawModelFilePath(inputFileName2); Assert.True(File.Exists(rawModelFilePath2)); var rawModel2 = JsonUtility.Deserialize <JObject>(rawModelFilePath2); Assert.Equal("Hello world!", rawModel2["metadata"]["meta"].ToString()); Assert.Equal("2", rawModel2["metadata"]["another"].ToString()); Assert.Equal("postbuild2", rawModel2["metadata"]["postMeta"].ToString()); // change dependent markdown UpdateFile("toc.md", new string[] { "# Updated" }, _inputFolder); using (new LoggerPhaseScope("SecondRound")) { BuildDocument(files); } rawModel = JsonUtility.Deserialize <JObject>(rawModelFilePath); Assert.Equal("overwritten", rawModel["metadata"]["meta"].ToString()); Assert.Equal("1", rawModel["metadata"]["another"].ToString()); Assert.Equal("app-service", rawModel["metadata"]["ms.service"].ToString()); Assert.Equal("postbuild1", rawModel["metadata"]["postMeta"].ToString()); rawModel2 = JsonUtility.Deserialize <JObject>(rawModelFilePath2); Assert.Equal("Hello world!", rawModel2["metadata"]["meta"].ToString()); Assert.Equal("2", rawModel2["metadata"]["another"].ToString()); Assert.Equal("postbuild2", rawModel2["metadata"]["postMeta"].ToString()); } }
public void TestRef() { using (var listener = new TestListenerScope("TestRef")) { var schemaFile = CreateFile("template/schemas/general.test.schema.json", File.ReadAllText("TestData/schemas/general.test.schema.json"), _templateFolder); var templateFile = CreateFile("template/General.html.tmpl", @"{{#items}} {{#aggregatedExceptions}} {{{message}}} {{{inner.message}}} {{{inner.inner.message}}} {{/aggregatedExceptions}} {{#exception}} {{{message}}} {{/exception}} {{{description}}} {{/items}} ", _templateFolder); var inputFileName = "inputs/exp1.yml"; var inputFile = CreateFile(inputFileName, @"### YamlMime:General items: - exception: message: ""**Hello**"" - aggregatedExceptions: - message: ""1**Hello**"" inner: message: ""1.1**Hello**"" inner: message: ""1.1.1**Hello**"" - message: ""2**Hello**"" inner: message: ""2.1**Hello**"" inner: message: ""2.1.1**Hello**"" - message: ""3**Hello**"" inner: message: ""3.1**Hello**"" inner: message: ""3.1.1**Hello**"" - description: ""**outside**"" ", _inputFolder); FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { inputFile }, _inputFolder); BuildDocument(files); Assert.Equal(1, listener.Items.Count); var xrefspec = Path.Combine(_outputFolder, "xrefmap.yml"); var xrefmap = YamlUtility.Deserialize <XRefMap>(xrefspec); Assert.Equal(0, xrefmap.References.Count); var outputFileName = Path.ChangeExtension(inputFileName, ".html"); var outputFilePath = Path.Combine(_outputFolder, outputFileName); Assert.True(File.Exists(outputFilePath)); Assert.Equal($@" <p><strong>Hello</strong></p> <p>1<strong>Hello</strong></p> <p>1.1<strong>Hello</strong></p> <p>1.1.1<strong>Hello</strong></p> <p>2<strong>Hello</strong></p> <p>2.1<strong>Hello</strong></p> <p>2.1.1<strong>Hello</strong></p> <p>3<strong>Hello</strong></p> <p>3.1<strong>Hello</strong></p> <p>3.1.1<strong>Hello</strong></p> <p><strong>outside</strong></p> " .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries), File.ReadAllLines(outputFilePath).Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToArray()); } }
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.GetFullPath(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 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.GetFullPath(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 static UserFile UploadUserFile(string fileName, FrameworkElement image, FrameworkElement focus, PropertyChangedEventHandler eventHandler) { FileCollection _files = new FileCollection("1", 1024000); WriteableBitmap bmp = new WriteableBitmap(image, null); System.IO.Stream dstStream = new System.IO.MemoryStream(); JpegHelper.EncodeJpeg(bmp, dstStream); dstStream.Position = 0;//用于上传时从新读取 MixObjectsSoapClient.Point point = new MixObjectsSoapClient.Point(); point.X = (int) Double.Parse(focus.GetValue(Canvas.LeftProperty).ToString()); point.Y = (int) Double.Parse(focus.GetValue(Canvas.TopProperty).ToString()); MixObjectsSoapClient.Size size = new MixObjectsSoapClient.Size(); size.Width = (int)Double.Parse(focus.Width.ToString()); size.Height = (int)Double.Parse(focus.Height.ToString()); UserFile imageFile = new UserFile() { FileName = fileName, FileStream = dstStream, GrabPoint = point, GrabSize = size };// ofd.File; imageFile.PropertyChanged += eventHandler; _files.Add(imageFile); _files.UploadFiles(); _files.RemoveAt(0); return imageFile; }
public void TestBuild() { #region Prepare test data var resourceFile = Path.GetFileName(typeof(DocumentBuilderTest).Assembly.Location); var resourceMetaFile = resourceFile + ".meta"; CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var tocFile = CreateFile("toc.md", new[] { "# [test1](test.md)", "## [test2](test/test.md)", "# Api", "## [Console](@System.Console)", "## [ConsoleColor](xref:System.ConsoleColor)", }, _inputFolder); var conceptualFile = CreateFile("test.md", new[] { "---", "uid: XRef1", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef1", "Test link: [link text](test/test.md)", "Test link: [link text 2](../" + resourceFile + ")", "Test link style xref: [link text 3](xref:XRef2 \"title\")", "Test link style xref with anchor: [link text 4](xref:XRef2#anchor \"title\")", "Test encoded link style xref with anchor: [link text 5](xref:%58%52%65%66%32#anchor \"title\")", "Test invalid link style xref with anchor: [link text 6](xref:invalid#anchor \"title\")", "Test autolink style xref: <xref:XRef2>", "Test autolink style xref with anchor: <xref:XRef2#anchor>", "Test encoded autolink style xref with anchor: <xref:%58%52%65%66%32#anchor>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: @XRef2", "Test xref with query string: <xref href=\"XRef2?text=Foo%3CT%3E\"/>", "Test invalid xref with query string: <xref href=\"invalid?alt=Foo%3CT%3E\"/>", "Test xref with attribute: <xref href=\"XRef2\" text=\"Foo<T>\"/>", "Test xref with attribute: <xref href=\"XRef2\" name=\"Foo<T>\"/>", "Test invalid xref with attribute: <xref href=\"invalid\" alt=\"Foo<T>\"/>", "Test invalid xref with attribute: <xref href=\"invalid\" fullname=\"Foo<T>\"/>", "<p>", "test", }, _inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "---", "uid: XRef2", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef2", "Test link: [link text](../test.md)", "<p>", "test", }, _inputFolder); File.WriteAllText(resourceMetaFile, @"{ abc: ""xyz"", uid: ""r1"" }"); File.WriteAllText(MarkdownSytleConfig.MarkdownStyleFileName, @"{ rules : [ ""foo"", { name: ""bar"", disable: true} ], tagRules : [ { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: true } ] }"); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { tocFile, conceptualFile, conceptualFile2 }); files.Add(DocumentType.Article, new[] { "TestData/System.Console.csyml", "TestData/System.ConsoleColor.csyml" }, "TestData/", null); files.Add(DocumentType.Resource, new[] { resourceFile }); #endregion Init(MarkdownValidatorBuilder.MarkdownValidatePhaseName); try { using (new LoggerPhaseScope(nameof(DocumentBuilderTest))) { BuildDocument( files, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: _templateFolder); } { // check log for markdown stylecop. Assert.Equal(2, Listener.Items.Count); Assert.Equal("Tag p is not valid.", Listener.Items[0].Message); Assert.Equal(LogLevel.Warning, Listener.Items[0].LogLevel); Assert.Equal("Tag p is not valid.", Listener.Items[1].Message); Assert.Equal(LogLevel.Warning, Listener.Items[1].LogLevel); } { // check toc. Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize<TocItemViewModel>(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))).Items; Assert.NotNull(model); Assert.Equal("test1", model[0].Name); Assert.Equal("test.html", model[0].Href); Assert.NotNull(model[0].Items); Assert.Equal("test2", model[0].Items[0].Name); Assert.Equal("test/test.html", model[0].Items[0].Href); Assert.Equal("Api", model[1].Name); Assert.Null(model[1].Href); Assert.NotNull(model[1].Items); Assert.Equal("Console", model[1].Items[0].Name); Assert.Equal("../System.Console.csyml", model[1].Items[0].Href); Assert.Equal("ConsoleColor", model[1].Items[1].Name); Assert.Equal("../System.ConsoleColor.csyml", model[1].Items[1].Href); } { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); Assert.True(File.Exists(conceptualOutputPath)); Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize<Dictionary<string, object>>(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); Assert.Equal( $"<h1 id=\"hello-world\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"7\" sourceendlinenumber=\"7\">Hello World</h1>", model["rawTitle"]); Assert.Equal( string.Join( "\n", "", $"<p sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"8\" sourceendlinenumber=\"27\">Test XRef: <xref href=\"XRef1\" data-throw-if-not-resolved=\"False\" data-raw-source=\"@XRef1\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"8\" sourceendlinenumber=\"8\"></xref>", $"Test link: <a href=\"~/{_inputFolder}/test/test.md\" data-raw-source=\"[link text](test/test.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"9\" sourceendlinenumber=\"9\">link text</a>", $"Test link: <a href=\"~/{resourceFile}\" data-raw-source=\"[link text 2](../Microsoft.DocAsCode.Build.Engine.Tests.dll)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"10\" sourceendlinenumber=\"10\">link text 2</a>", $"Test link style xref: <a href=\"xref:XRef2\" title=\"title\" data-raw-source=\"[link text 3](xref:XRef2 "title")\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"11\" sourceendlinenumber=\"11\">link text 3</a>", $"Test link style xref with anchor: <a href=\"xref:XRef2#anchor\" title=\"title\" data-raw-source=\"[link text 4](xref:XRef2#anchor "title")\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"12\" sourceendlinenumber=\"12\">link text 4</a>", $"Test encoded link style xref with anchor: <a href=\"xref:%58%52%65%66%32#anchor\" title=\"title\" data-raw-source=\"[link text 5](xref:%58%52%65%66%32#anchor "title")\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"13\" sourceendlinenumber=\"13\">link text 5</a>", $"Test invalid link style xref with anchor: <a href=\"xref:invalid#anchor\" title=\"title\" data-raw-source=\"[link text 6](xref:invalid#anchor "title")\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"14\" sourceendlinenumber=\"14\">link text 6</a>", $"Test autolink style xref: <xref href=\"XRef2\" data-throw-if-not-resolved=\"True\" data-raw-source=\"<xref:XRef2>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"15\" sourceendlinenumber=\"15\"></xref>", $"Test autolink style xref with anchor: <xref href=\"XRef2#anchor\" data-throw-if-not-resolved=\"True\" data-raw-source=\"<xref:XRef2#anchor>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"16\" sourceendlinenumber=\"16\"></xref>", $"Test encoded autolink style xref with anchor: <xref href=\"%58%52%65%66%32#anchor\" data-throw-if-not-resolved=\"True\" data-raw-source=\"<xref:%58%52%65%66%32#anchor>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"17\" sourceendlinenumber=\"17\"></xref>", $"Test invalid autolink style xref with anchor: <xref href=\"invalid#anchor\" data-throw-if-not-resolved=\"True\" data-raw-source=\"<xref:invalid#anchor>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"18\" sourceendlinenumber=\"18\"></xref>", $"Test short xref: <xref href=\"XRef2\" data-throw-if-not-resolved=\"False\" data-raw-source=\"@XRef2\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"19\" sourceendlinenumber=\"19\"></xref>", "Test xref with query string: <xref href=\"XRef2?text=Foo%3CT%3E\"></xref>", "Test invalid xref with query string: <xref href=\"invalid?alt=Foo%3CT%3E\"></xref>", "Test xref with attribute: <xref href=\"XRef2\" text=\"Foo<T>\"></xref>", "Test xref with attribute: <xref href=\"XRef2\" name=\"Foo<T>\"></xref>", "Test invalid xref with attribute: <xref href=\"invalid\" alt=\"Foo<T>\"></xref>", "Test invalid xref with attribute: <xref href=\"invalid\" fullname=\"Foo<T>\"></xref>", "<p>", "test</p>", ""), model[Constants.PropertyName.Conceptual]); Assert.Equal( string.Join( "\n", "", "<p>Test XRef: <a class=\"xref\" href=\"test.html\">Hello World</a>", "Test link: <a href=\"test/test.html\">link text</a>", "Test link: <a href=\"../Microsoft.DocAsCode.Build.Engine.Tests.dll\">link text 2</a>", "Test link style xref: <a class=\"xref\" href=\"test/test.html\" title=\"title\">link text 3</a>", "Test link style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\" title=\"title\">link text 4</a>", "Test encoded link style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\" title=\"title\">link text 5</a>", "Test invalid link style xref with anchor: <a href=\"xref:invalid#anchor\" title=\"title\">link text 6</a>", "Test autolink style xref: <a class=\"xref\" href=\"test/test.html\">Hello World</a>", "Test autolink style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\">Hello World</a>", "Test encoded autolink style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\">Hello World</a>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: <a class=\"xref\" href=\"test/test.html\">Hello World</a>", "Test xref with query string: <a class=\"xref\" href=\"test/test.html\">Foo<T></a>", "Test invalid xref with query string: <span class=\"xref\">Foo<T></span>", "Test xref with attribute: <a class=\"xref\" href=\"test/test.html\">Foo<T></a>", "Test xref with attribute: <a class=\"xref\" href=\"test/test.html\">Foo<T></a>", "Test invalid xref with attribute: <span class=\"xref\">Foo<T></span>", "Test invalid xref with attribute: <span class=\"xref\">Foo<T></span>", "<p>", "test</p>", ""), File.ReadAllText(conceptualOutputPath)); Assert.Equal("Conceptual", model["type"]); Assert.Equal("Hello world!", model["meta"]); Assert.Equal("b", model["a"]); } { // check mref. Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.Console.csyml", RawModelFileExtension)))); Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.ConsoleColor.csyml", RawModelFileExtension)))); } { // check resource. Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile))); Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension))); var meta = JsonUtility.Deserialize<Dictionary<string, object>>(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension)); Assert.Equal(7, meta.Count); Assert.True(meta.ContainsKey("meta")); Assert.Equal("Hello world!", meta["meta"]); Assert.True(meta.ContainsKey("abc")); Assert.Equal("xyz", meta["abc"]); Assert.True(meta.ContainsKey(Constants.PropertyName.Uid)); Assert.Equal("r1", meta[Constants.PropertyName.Uid]); } } finally { CleanUp(); File.Delete(resourceMetaFile); } }
public virtual object GetDashboardData(HttpContext context) { YZRequest request = new YZRequest(context); List <int> rootfolderids = JArray.Parse(request.GetString("rootfolders")).ToObject <List <int> >(); SpriteIdentity responsible = JObject.Parse(request.GetString("responsible")).ToObject <SpriteIdentity>(); BPMObjectNameCollection milestones = JArray.Parse(request.GetString("milestones")).ToObject <BPMObjectNameCollection>(); BPMObjectNameCollection moduletypes = JArray.Parse(request.GetString("moduletypes")).ToObject <BPMObjectNameCollection>(); BPMObjectNameCollection colors = JArray.Parse(request.GetString("colors")).ToObject <BPMObjectNameCollection>(); BPMObjectNameCollection executeStatus = JArray.Parse(request.GetString("executeStatus")).ToObject <BPMObjectNameCollection>(); string uid = YZAuthHelper.LoginUserAccount; FileCollection files = new FileCollection(); using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider) { using (IDbConnection cn = provider.OpenConnection()) { if (rootfolderids.Count == 0) { rootfolderids = this.GetAllReportRootFolders(provider, cn, uid); } FileSystem.FileCollection allfiles = new FileSystem.FileCollection(); foreach (int rootfolderid in rootfolderids) { FileSystem.FolderCollection allfolders = FileSystem.DirectoryManager.GetAllChildFolders(provider, cn, rootfolderid, null, null); FileSystem.FolderCollection rootFolders = allfolders.BuildTree(rootfolderid); allfolders = rootFolders.Expand(); FileSystem.FileCollection folderfiles = FileSystem.DirectoryManager.GetFiles(provider, cn, allfolders.IDs, null, null, -1); allfiles.AppendUnique(folderfiles); } foreach (FileSystem.File folderfile in allfiles) { File file = File.TryLoad(provider, cn, folderfile.FileID); if (file == null) { continue; } //responsible过滤 if (!String.IsNullOrEmpty(responsible.FileID)) { if (!file.Property.Owner.Contains(responsible)) { continue; } } //milestone过滤 if (milestones.Count != 0) { if (!milestones.Contains(file.Property.Milestone.ToString())) { continue; } } //moduletypes过滤 if (moduletypes.Count != 0) { if (!moduletypes.Contains(file.AttachmentInfo.Ext)) { continue; } } //color过滤 if (colors.Count != 0) { if (!colors.Contains(file.Property.Color.ToString())) { continue; } } //executeStatus过滤 if (executeStatus.Count != 0) { if (!executeStatus.Contains(file.Property.ExecuteStatus.ToString())) { continue; } } files.Add(file); } } } JObject rv = new JObject(); JObject item; //Milestone item = new JObject(); rv["Milestone"] = item; item["Total"] = files.Count; foreach (Milestone milestone in Enum.GetValues(typeof(Milestone))) { item[milestone.ToString()] = 0; } foreach (File file in files) { item[file.Property.Milestone.ToString()] = (int)item[file.Property.Milestone.ToString()] + 1; } //ExecuteStatus item = new JObject(); rv["ExecuteStatus"] = item; foreach (ExecuteStatus executeState in Enum.GetValues(typeof(ExecuteStatus))) { item[executeState.ToString()] = 0; } foreach (File file in files) { item[file.Property.ExecuteStatus.ToString()] = (int)item[file.Property.ExecuteStatus.ToString()] + 1; } //Color item = new JObject(); rv["Color"] = item; foreach (FileColor fileColor in Enum.GetValues(typeof(FileColor))) { item[fileColor.ToString()] = 0; } foreach (File file in files) { item[file.Property.Color.ToString()] = (int)item[file.Property.Color.ToString()] + 1; } //分类统计 item = new JObject(); rv["FileTypes"] = item; foreach (string ext in ".evc,.flow,.bpmn,.org,.data,.it,.product,.risk,.reg,.kpi".Split(',')) { JObject jTypeCounts = new JObject(); item[ext] = jTypeCounts; foreach (Milestone milestone in Enum.GetValues(typeof(Milestone))) { jTypeCounts[milestone.ToString()] = 0; } } foreach (File file in files) { string ext = file.AttachmentInfo.Ext; if (ext != null) { ext = ext.ToLower().Trim(); } JObject jTypeCounts = item[ext] as JObject; if (jTypeCounts != null) { jTypeCounts[file.Property.Milestone.ToString()] = (int)jTypeCounts[file.Property.Milestone.ToString()] + 1; } } //战略流程数量 item = new JObject(); rv["Strategic"] = item; item["StrategicProcess"] = 0; item["OperationProcess"] = 0; item["SupportProcess"] = 0; item["Other"] = 0; foreach (File file in files) { string filetype; if (file.isStrategicProces) { filetype = "StrategicProcess"; } else if (file.isOperationProcess) { filetype = "OperationProcess"; } else if (file.isSupportProces) { filetype = "SupportProcess"; } else { filetype = "Other"; } item[filetype] = (int)item[filetype] + 1; } return(rv); }
public void TestServerChanges() { // conceptual1--->conceptual2(phase 2) // conceptual2--->conceptual3(phase 1) // conceptual3 // conceptual4 #region Prepare test data var resourceFile = Path.GetFileName(typeof(IncrementalBuildTest).Assembly.Location); var inputFolder = GetRandomFolder(); var outputFolder = GetRandomFolder(); var templateFolder = GetRandomFolder(); var intermediateFolder = GetRandomFolder(); CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", templateFolder); CreateFile("ManagedReference.html.primary.tmpl", "managed content", templateFolder); CreateFile("toc.html.tmpl", "toc", templateFolder); var tocFile = CreateFile("toc.md", new[] { "# [test1](test.md)", "## [test2](test/test.md)", "# Api", "## [Console](@System.Console)", "## [ConsoleColor](xref:System.ConsoleColor)", }, inputFolder); var conceptualFile = CreateFile("test.md", new[] { "---", "uid: XRef1", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef1", "Test link: [link text](test/test.md)", "Test link: [link text 2](../" + resourceFile + ")", "Test link style xref: [link text 3](xref:XRef2 \"title\")", "<p>", "test", }, inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "---", "uid: XRef2", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef2", "Test link: [link text](../test.md)", "[!INCLUDE [API_version](test3.md)]", }, inputFolder); var conceptualFile3 = CreateFile("test/test3.md", new[] { "# Hello World", "test", }, inputFolder); var conceptualFile4 = CreateFile("test/test4.md", new[] { "# Hello World", "test", }, inputFolder); File.WriteAllText(MarkdownSytleConfig.MarkdownStyleFileName, @"{ rules : [ ""foo"", { name: ""bar"", disable: true} ], tagRules : [ { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: true } ] }"); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { tocFile, conceptualFile, conceptualFile2, conceptualFile3, conceptualFile4 }); files.Add(DocumentType.Article, new[] { "TestData/System.Console.csyml", "TestData/System.ConsoleColor.csyml" }, "TestData/", null); files.Add(DocumentType.Resource, new[] { resourceFile }); #endregion Init("IncrementalBuild.TestServerChanges"); var outputFolderFirst = Path.Combine(outputFolder, "IncrementalBuild.TestLocalChanges"); var outputFolderForIncremental = Path.Combine(outputFolder, "IncrementalBuild.TestLocalChanges.Second"); var outputFolderForCompare = Path.Combine(outputFolder, "IncrementalBuild.TestLocalChanges.Second.ForceBuild"); try { using (new LoggerPhaseScope("first-IncrementalBuild.TestServerChanges")) { BuildDocument( files, inputFolder, outputFolderFirst, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: templateFolder, intermediateFolder: intermediateFolder); } using (new LoggerPhaseScope("second-IncrementalBuild.TestServerChanges")) { BuildDocument( files, inputFolder, outputFolderForIncremental, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: templateFolder, intermediateFolder: intermediateFolder, changes: new Dictionary<string, ChangeKindWithDependency> { { ((RelativePath)conceptualFile3).GetPathFromWorkingFolder(), ChangeKindWithDependency.Updated }, { ((RelativePath)conceptualFile).GetPathFromWorkingFolder(), ChangeKindWithDependency.None }, { ((RelativePath)conceptualFile2).GetPathFromWorkingFolder(), ChangeKindWithDependency.None }, { ((RelativePath)conceptualFile4).GetPathFromWorkingFolder(), ChangeKindWithDependency.None }, { ((RelativePath)tocFile).GetPathFromWorkingFolder(), ChangeKindWithDependency.None }, { ((RelativePath)resourceFile).GetPathFromWorkingFolder(), ChangeKindWithDependency.None }, { "~/TestData/System.Console.csyml", ChangeKindWithDependency.None }, { "~/TestData/System.ConsoleColor.csyml", ChangeKindWithDependency.None }, }); } using (new LoggerPhaseScope("second-forcebuild-IncrementalBuild.TestServerChanges")) { BuildDocument( files, inputFolder, outputFolderForCompare, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: templateFolder); } { // check manifest var manifestOutputPath = Path.Combine(outputFolderForIncremental, "manifest.json"); Assert.True(File.Exists(manifestOutputPath)); var manifest = JsonUtility.Deserialize<Manifest>(manifestOutputPath); Assert.Equal(8, manifest.Files.Count); } { // check xrefmap var xrefMapOutputPath = Path.Combine(outputFolderForIncremental, "xrefmap.yml"); Assert.True(File.Exists(xrefMapOutputPath)); var xrefMap = YamlUtility.Deserialize<XRefMap>(xrefMapOutputPath); Assert.Equal(70, xrefMap.References.Count); } { // compare with force build Assert.True(CompareDir(outputFolderForIncremental, outputFolderForCompare)); } } finally { CleanUp(); Directory.Delete(outputFolder, true); Directory.Delete(templateFolder, true); Directory.Delete(inputFolder, true); Directory.Delete(intermediateFolder, true); } }
public void TestBuild() { #region Prepare test data var resourceFile = Path.GetFileName(typeof(DocumentBuilderTest).Assembly.Location); var resourceMetaFile = resourceFile + ".meta"; CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var tocFile = CreateFile("toc.md", new[] { "# [test1](test.md)", "## [test2](test/test.md)", "# Api", "## [Console](@System.Console)", "## [ConsoleColor](xref:System.ConsoleColor)", }, _inputFolder); var conceptualFile = CreateFile("test.md", new[] { "---", "uid: XRef1", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef1", "Test link: [link text](test/test.md)", "Test link: [link text 2](../" + resourceFile + ")", "Test link style xref: [link text 3](xref:XRef2 \"title\")", "Test link style xref with anchor: [link text 4](xref:XRef2#anchor \"title\")", "Test encoded link style xref with anchor: [link text 5](xref:%58%52%65%66%32#anchor \"title\")", "Test invalid link style xref with anchor: [link text 6](xref:invalid#anchor \"title\")", "Test autolink style xref: <xref:XRef2>", "Test autolink style xref with anchor: <xref:XRef2#anchor>", "Test encoded autolink style xref with anchor: <xref:%58%52%65%66%32#anchor>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: @XRef2", "Test xref with query string: <xref href=\"XRef2?text=Foo%3CT%3E\"/>", "Test invalid xref with query string: <xref href=\"invalid?alt=Foo%3CT%3E\"/>", "Test xref with attribute: <xref href=\"XRef2\" text=\"Foo<T>\"/>", "Test xref with attribute: <xref href=\"XRef2\" name=\"Foo<T>\"/>", "Test invalid xref with attribute: <xref href=\"invalid\" alt=\"Foo<T>\"/>", "Test invalid xref with attribute: <xref href=\"invalid\" fullname=\"Foo<T>\"/>", "<p>", "test", }, _inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "---", "uid: XRef2", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef2", "Test link: [link text](../test.md)", "<p>", "test", }, _inputFolder); File.WriteAllText(resourceMetaFile, @"{ abc: ""xyz"", uid: ""r1"" }"); File.WriteAllText(MarkdownSytleConfig.MarkdownStyleFileName, @"{ rules : [ ""foo"", { name: ""bar"", disable: true} ], tagRules : [ { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: true } ] }"); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { tocFile, conceptualFile, conceptualFile2 }); files.Add(DocumentType.Article, new[] { "TestData/System.Console.csyml", "TestData/System.ConsoleColor.csyml" }, "TestData/", null); files.Add(DocumentType.Resource, new[] { resourceFile }); #endregion Init(MarkdownValidatorBuilder.MarkdownValidatePhaseName); try { using (new LoggerPhaseScope(nameof(DocumentBuilderTest))) { BuildDocument( files, new Dictionary <string, object> { ["meta"] = "Hello world!", }, templateFolder: _templateFolder); } { // check log for markdown stylecop. Assert.Equal(2, Listener.Items.Count); Assert.Equal("Tag p is not valid.", Listener.Items[0].Message); Assert.Equal(LogLevel.Warning, Listener.Items[0].LogLevel); Assert.Equal("Tag p is not valid.", Listener.Items[1].Message); Assert.Equal(LogLevel.Warning, Listener.Items[1].LogLevel); } { // check toc. Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize <TocItemViewModel>(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))).Items; Assert.NotNull(model); Assert.Equal("test1", model[0].Name); Assert.Equal("test.html", model[0].Href); Assert.NotNull(model[0].Items); Assert.Equal("test2", model[0].Items[0].Name); Assert.Equal("test/test.html", model[0].Items[0].Href); Assert.Equal("Api", model[1].Name); Assert.Null(model[1].Href); Assert.NotNull(model[1].Items); Assert.Equal("Console", model[1].Items[0].Name); Assert.Equal("../System.Console.csyml", model[1].Items[0].Href); Assert.Equal("ConsoleColor", model[1].Items[1].Name); Assert.Equal("../System.ConsoleColor.csyml", model[1].Items[1].Href); } { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); Assert.True(File.Exists(conceptualOutputPath)); Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize <Dictionary <string, object> >(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); Assert.Equal( $"<h1 id=\"hello-world\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"7\" sourceendlinenumber=\"7\">Hello World</h1>", model["rawTitle"]); Assert.Equal( string.Join( "\n", "", $"<p sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"8\" sourceendlinenumber=\"25\">Test XRef: <xref href=\"XRef1\" data-throw-if-not-resolved=\"False\" data-raw=\"@XRef1\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"8\" sourceendlinenumber=\"8\"></xref>", $"Test link: <a href=\"~/{_inputFolder}/test/test.md\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"9\" sourceendlinenumber=\"9\">link text</a>", $"Test link: <a href=\"~/{resourceFile}\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"10\" sourceendlinenumber=\"10\">link text 2</a>", $"Test link style xref: <a href=\"xref:XRef2\" title=\"title\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"11\" sourceendlinenumber=\"11\">link text 3</a>", $"Test link style xref with anchor: <a href=\"xref:XRef2#anchor\" title=\"title\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"12\" sourceendlinenumber=\"12\">link text 4</a>", $"Test encoded link style xref with anchor: <a href=\"xref:%58%52%65%66%32#anchor\" title=\"title\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"13\" sourceendlinenumber=\"13\">link text 5</a>", $"Test invalid link style xref with anchor: <a href=\"xref:invalid#anchor\" title=\"title\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"14\" sourceendlinenumber=\"14\">link text 6</a>", $"Test autolink style xref: <xref href=\"XRef2\" data-throw-if-not-resolved=\"True\" data-raw=\"<xref:XRef2>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"15\" sourceendlinenumber=\"15\"></xref>", $"Test autolink style xref with anchor: <xref href=\"XRef2#anchor\" data-throw-if-not-resolved=\"True\" data-raw=\"<xref:XRef2#anchor>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"16\" sourceendlinenumber=\"16\"></xref>", $"Test encoded autolink style xref with anchor: <xref href=\"%58%52%65%66%32#anchor\" data-throw-if-not-resolved=\"True\" data-raw=\"<xref:%58%52%65%66%32#anchor>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"17\" sourceendlinenumber=\"17\"></xref>", $"Test invalid autolink style xref with anchor: <xref href=\"invalid#anchor\" data-throw-if-not-resolved=\"True\" data-raw=\"<xref:invalid#anchor>\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"18\" sourceendlinenumber=\"18\"></xref>", $"Test short xref: <xref href=\"XRef2\" data-throw-if-not-resolved=\"False\" data-raw=\"@XRef2\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"19\" sourceendlinenumber=\"19\"></xref>", "Test xref with query string: <xref href=\"XRef2?text=Foo%3CT%3E\"></xref>", "Test invalid xref with query string: <xref href=\"invalid?alt=Foo%3CT%3E\"></xref>", "Test xref with attribute: <xref href=\"XRef2\" text=\"Foo<T>\"></xref>", "Test xref with attribute: <xref href=\"XRef2\" name=\"Foo<T>\"></xref>", "Test invalid xref with attribute: <xref href=\"invalid\" alt=\"Foo<T>\"></xref>", "Test invalid xref with attribute: <xref href=\"invalid\" fullname=\"Foo<T>\"></xref></p>", $"<p sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"26\" sourceendlinenumber=\"27\"><p>", "test</p>", ""), model[Constants.PropertyName.Conceptual]); Assert.Equal( string.Join( "\n", "", "<p>Test XRef: <a class=\"xref\" href=\"test.html#XRef1\">Hello World</a>", "Test link: <a href=\"test/test.html\">link text</a>", "Test link: <a href=\"../Microsoft.DocAsCode.Build.Engine.Tests.dll\">link text 2</a>", "Test link style xref: <a class=\"xref\" href=\"test/test.html#XRef2\" title=\"title\">link text 3</a>", "Test link style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\" title=\"title\">link text 4</a>", "Test encoded link style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\" title=\"title\">link text 5</a>", "Test invalid link style xref with anchor: <a href=\"xref:invalid#anchor\" title=\"title\">link text 6</a>", "Test autolink style xref: <a class=\"xref\" href=\"test/test.html#XRef2\">Hello World</a>", "Test autolink style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\">Hello World</a>", "Test encoded autolink style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\">Hello World</a>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: <a class=\"xref\" href=\"test/test.html#XRef2\">Hello World</a>", "Test xref with query string: <a class=\"xref\" href=\"test/test.html#XRef2\">Foo<T></a>", "Test invalid xref with query string: <span class=\"xref\">Foo<T></span>", "Test xref with attribute: <a class=\"xref\" href=\"test/test.html#XRef2\">Foo<T></a>", "Test xref with attribute: <a class=\"xref\" href=\"test/test.html#XRef2\">Foo<T></a>", "Test invalid xref with attribute: <span class=\"xref\">Foo<T></span>", "Test invalid xref with attribute: <span class=\"xref\">Foo<T></span></p>", "<p><p>", "test</p>", ""), File.ReadAllText(conceptualOutputPath)); Assert.Equal("Conceptual", model["type"]); Assert.Equal("Hello world!", model["meta"]); Assert.Equal("b", model["a"]); } { // check mref. Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.Console.csyml", RawModelFileExtension)))); Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.ConsoleColor.csyml", RawModelFileExtension)))); } { // check resource. Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile))); Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension))); var meta = JsonUtility.Deserialize <Dictionary <string, object> >(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension)); Assert.Equal(7, meta.Count); Assert.True(meta.ContainsKey("meta")); Assert.Equal("Hello world!", meta["meta"]); Assert.True(meta.ContainsKey("abc")); Assert.Equal("xyz", meta["abc"]); Assert.True(meta.ContainsKey(Constants.PropertyName.Uid)); Assert.Equal("r1", meta[Constants.PropertyName.Uid]); } } finally { CleanUp(); File.Delete(resourceMetaFile); } }
public void TestMarkdownStyleInPlugins() { #region Prepare test data var resourceFile = Path.GetFileName(typeof(DocumentBuilderTest).Assembly.Location); var resourceMetaFile = resourceFile + ".meta"; CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var tocFile = CreateFile("toc.md", new[] { "# [test1](test.md)", "## [test2](test/test.md)", "# Api", "## [Console](@System.Console)", "## [ConsoleColor](xref:System.ConsoleColor)", }, _inputFolder); var conceptualFile = CreateFile("test.md", new[] { "---", "uid: XRef1", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef1", "Test link: [link text](test/test.md)", "Test link: [link text 2](../" + resourceFile + ")", "Test link style xref: [link text 3](xref:XRef2 \"title\")", "Test link style xref with anchor: [link text 4](xref:XRef2#anchor \"title\")", "Test encoded link style xref with anchor: [link text 5](xref:%58%52%65%66%32#anchor \"title\")", "Test invalid link style xref with anchor: [link text 6](xref:invalid#anchor \"title\")", "Test autolink style xref: <xref:XRef2>", "Test autolink style xref with anchor: <xref:XRef2#anchor>", "Test encoded autolink style xref with anchor: <xref:%58%52%65%66%32#anchor>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: @XRef2", "<p>", "test", }, _inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "---", "uid: XRef2", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef2", "Test link: [link text](../test.md)", "<p><div>", "test", }, _inputFolder); File.WriteAllText(resourceMetaFile, @"{ abc: ""xyz"", uid: ""r1"" }"); File.WriteAllText(MarkdownSytleConfig.MarkdownStyleFileName, @"{ settings : [ { category: ""div"", disable: true}, { category: ""p"", id: ""p-3"", disable: true} ], }"); CreateFile( MarkdownSytleDefinition.MarkdownStyleDefinitionFolderName + "/p" + MarkdownSytleDefinition.MarkdownStyleDefinitionFilePostfix, @"{ tagRules : { ""p-1"": { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: true }, ""p-2"": { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: false, disable: true }, ""p-3"": { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: false, } } } ", _templateFolder); CreateFile( MarkdownSytleDefinition.MarkdownStyleDefinitionFolderName + "/div" + MarkdownSytleDefinition.MarkdownStyleDefinitionFilePostfix, @"{ tagRules : { ""div-1"": { tagNames: [""div""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: true } } } ", _templateFolder); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { tocFile, conceptualFile, conceptualFile2 }); files.Add(DocumentType.Article, new[] { "TestData/System.Console.csyml", "TestData/System.ConsoleColor.csyml" }, "TestData/", null); files.Add(DocumentType.Resource, new[] { resourceFile }); #endregion Init(MarkdownValidatorBuilder.MarkdownValidatePhaseName); try { using (new LoggerPhaseScope(nameof(DocumentBuilderTest))) { BuildDocument( files, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: _templateFolder); } { // check log for markdown stylecop. Assert.Equal(2, Listener.Items.Count); Assert.Equal("Tag p is not valid.", Listener.Items[0].Message); Assert.Equal(LogLevel.Warning, Listener.Items[0].LogLevel); Assert.Equal("Tag p is not valid.", Listener.Items[1].Message); Assert.Equal(LogLevel.Warning, Listener.Items[1].LogLevel); } } finally { CleanUp(); File.Delete(resourceMetaFile); } }
public void TestBuildWithInvalidPath() { #region Prepare test data var resourceFile = Path.GetFileName(typeof(DocumentBuilderTest).Assembly.Location); var resourceMetaFile = resourceFile + ".meta"; CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var tocFile = CreateFile("toc.md", new[] { "# [test1](test.md)", "## [test2](test/test.md)", }, _inputFolder); var conceptualFile = CreateFile("test.md", new[] { "# Hello World", "Test link: [link 1](test/test.md)", "Test link: [link 2](http://www.microsoft.com)", "Test link: [link 3](a b c.md)", "Test link: [link 4](c:\\a.md)", "Test link: [link 5](\\a.md)", "Test link: [link 6](urn:a.md)", "Test link: [link 7](bad urn:a.md)", "Test link: [link 8](test/test.md#top)", "Test link: [link 9](a.md#top)", "Test link: [link 10](#top)", }, _inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "# Hello World", "Test link: [link 1](../test.md)", }, _inputFolder); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { tocFile, conceptualFile, conceptualFile2 }); #endregion try { using (new LoggerPhaseScope(nameof(DocumentBuilderTest))) { BuildDocument( files, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: _templateFolder); } { // check toc. Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize<TocItemViewModel>(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))).Items; Assert.NotNull(model); Assert.Equal("test1", model[0].Name); Assert.Equal("test.html", model[0].Href); Assert.NotNull(model[0].Items); Assert.Equal("test2", model[0].Items[0].Name); Assert.Equal("test/test.html", model[0].Items[0].Href); } { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); Assert.True(File.Exists(conceptualOutputPath)); Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize<Dictionary<string, object>>(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); Assert.Equal( $"<h1 id=\"hello-world\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">Hello World</h1>", model["rawTitle"]); Assert.Equal( string.Join( "\n", "", $"<p sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"2\" sourceendlinenumber=\"11\">Test link: <a href=\"~/{_inputFolder}/test/test.md\" data-raw-source=\"[link 1](test/test.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"2\" sourceendlinenumber=\"2\">link 1</a>", $"Test link: <a href=\"http://www.microsoft.com\" data-raw-source=\"[link 2](http://www.microsoft.com)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"3\" sourceendlinenumber=\"3\">link 2</a>", $"Test link: <a href=\"a b c.md\" data-raw-source=\"[link 3](a b c.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"4\" sourceendlinenumber=\"4\">link 3</a>", $"Test link: <a href=\"c:\\a.md\" data-raw-source=\"[link 4](c:\\a.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"5\" sourceendlinenumber=\"5\">link 4</a>", $"Test link: <a href=\"\\a.md\" data-raw-source=\"[link 5](\\a.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">link 5</a>", $"Test link: <a href=\"urn:a.md\" data-raw-source=\"[link 6](urn:a.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"7\" sourceendlinenumber=\"7\">link 6</a>", $"Test link: <a href=\"bad urn:a.md\" data-raw-source=\"[link 7](bad urn:a.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"8\" sourceendlinenumber=\"8\">link 7</a>", $"Test link: <a href=\"~/{_inputFolder}/test/test.md\" data-raw-source=\"[link 8](test/test.md#top)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"9\" sourceendlinenumber=\"9\" anchor=\"#top\">link 8</a>", $"Test link: <a href=\"a.md#top\" data-raw-source=\"[link 9](a.md#top)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"10\" sourceendlinenumber=\"10\">link 9</a>", $"Test link: <a href=\"#top\" data-raw-source=\"[link 10](#top)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"11\" sourceendlinenumber=\"11\">link 10</a></p>", ""), model[Constants.PropertyName.Conceptual]); Assert.Equal( string.Join( "\n", "", "<p>Test link: <a href=\"test/test.html\">link 1</a>", $"Test link: <a href=\"http://www.microsoft.com\">link 2</a>", $"Test link: <a href=\"a b c.md\">link 3</a>", $"Test link: <a href=\"c:\\a.md\">link 4</a>", $"Test link: <a href=\"\\a.md\">link 5</a>", $"Test link: <a href=\"urn:a.md\">link 6</a>", $"Test link: <a href=\"bad urn:a.md\">link 7</a>", $"Test link: <a href=\"test/test.html#top\">link 8</a>", $"Test link: <a href=\"a.md#top\">link 9</a>", $"Test link: <a href=\"#top\">link 10</a></p>", ""), File.ReadAllText(conceptualOutputPath)); Assert.Equal("Conceptual", model["type"]); Assert.Equal("Hello world!", model["meta"]); } } finally { } }
public void TestBasic() { #region Prepare test data var resourceFile = Path.GetFileName(typeof(IncrementalBuildTest).Assembly.Location); var inputFolder = GetRandomFolder(); var outputFolder = GetRandomFolder(); var templateFolder = GetRandomFolder(); var intermediateFolder = GetRandomFolder(); CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", templateFolder); CreateFile("ManagedReference.html.primary.tmpl", "managed content", templateFolder); CreateFile("toc.html.tmpl", "toc", templateFolder); var tocFile = CreateFile("toc.md", new[] { "# [test1](test.md)", "## [test2](test/test.md)", "# Api", "## [Console](@System.Console)", "## [ConsoleColor](xref:System.ConsoleColor)", }, inputFolder); var conceptualFile = CreateFile("test.md", new[] { "---", "uid: XRef1", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef1", "Test link: [link text](test/test.md)", "Test link: [link text 2](../" + resourceFile + ")", "Test link style xref: [link text 3](xref:XRef2 \"title\")", "Test link style xref with anchor: [link text 4](xref:XRef2#anchor \"title\")", "Test encoded link style xref with anchor: [link text 5](xref:%58%52%65%66%32#anchor \"title\")", "Test invalid link style xref with anchor: [link text 6](xref:invalid#anchor \"title\")", "Test autolink style xref: <xref:XRef2>", "Test autolink style xref with anchor: <xref:XRef2#anchor>", "Test encoded autolink style xref with anchor: <xref:%58%52%65%66%32#anchor>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: @XRef2", "Test xref with query string: <xref href=\"XRef2?text=Foo%3CT%3E\"/>", "Test invalid xref with query string: <xref href=\"invalid?alt=Foo%3CT%3E\"/>", "Test xref with attribute: <xref href=\"XRef2\" text=\"Foo<T>\"/>", "Test xref with attribute: <xref href=\"XRef2\" name=\"Foo<T>\"/>", "Test invalid xref with attribute: <xref href=\"invalid\" alt=\"Foo<T>\"/>", "Test invalid xref with attribute: <xref href=\"invalid\" fullname=\"Foo<T>\"/>", "<p>", "test", }, inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "---", "uid: XRef2", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: @XRef2", "Test link: [link text](../test.md)", "<p>", "test", }, inputFolder); File.WriteAllText(MarkdownSytleConfig.MarkdownStyleFileName, @"{ rules : [ ""foo"", { name: ""bar"", disable: true} ], tagRules : [ { tagNames: [""p""], behavior: ""Warning"", messageFormatter: ""Tag {0} is not valid."", openingTagOnly: true } ] }"); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { tocFile, conceptualFile, conceptualFile2 }); files.Add(DocumentType.Article, new[] { "TestData/System.Console.csyml", "TestData/System.ConsoleColor.csyml" }, "TestData/", null); files.Add(DocumentType.Resource, new[] { resourceFile }); #endregion Init("IncrementalBuild.TestBasic"); string outputFolderFirst = Path.Combine(outputFolder, "IncrementalBuild.TestBasic"); string outputFolderForIncremental = Path.Combine(outputFolder, "IncrementalBuild.TestBasic.Second"); try { using (new LoggerPhaseScope("first-IncrementalBuild.TestBasic")) { BuildDocument( files, inputFolder, outputFolderFirst, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: templateFolder, intermediateFolder: intermediateFolder); } // no changes using (new LoggerPhaseScope("second-IncrementalBuild.TestBasic")) { BuildDocument( files, inputFolder, outputFolderForIncremental, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: templateFolder, intermediateFolder: intermediateFolder); } { // check manifest var manifestOutputPath = Path.Combine(outputFolderForIncremental, "manifest.json"); Assert.True(File.Exists(manifestOutputPath)); var manifest = JsonUtility.Deserialize<Manifest>(manifestOutputPath); Assert.Equal(6, manifest.Files.Count); } { // check xrefmap var xrefMapOutputPath = Path.Combine(outputFolderForIncremental, "xrefmap.yml"); Assert.True(File.Exists(xrefMapOutputPath)); var xrefMap = YamlUtility.Deserialize<XRefMap>(xrefMapOutputPath); Assert.Equal(70, xrefMap.References.Count); } { // check conceptual. var conceptualOutputPath = Path.Combine(outputFolderForIncremental, Path.ChangeExtension(conceptualFile, ".html")); Assert.True(File.Exists(conceptualOutputPath)); Assert.Equal( string.Join( "\n", "", "<p>Test XRef: <a class=\"xref\" href=\"test.html\">Hello World</a>", "Test link: <a href=\"test/test.html\">link text</a>", "Test link: <a href=\"../Microsoft.DocAsCode.Build.Engine.Tests.dll\">link text 2</a>", "Test link style xref: <a class=\"xref\" href=\"test/test.html\" title=\"title\">link text 3</a>", "Test link style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\" title=\"title\">link text 4</a>", "Test encoded link style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\" title=\"title\">link text 5</a>", "Test invalid link style xref with anchor: <a href=\"xref:invalid#anchor\" title=\"title\">link text 6</a>", "Test autolink style xref: <a class=\"xref\" href=\"test/test.html\">Hello World</a>", "Test autolink style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\">Hello World</a>", "Test encoded autolink style xref with anchor: <a class=\"xref\" href=\"test/test.html#anchor\">Hello World</a>", "Test invalid autolink style xref with anchor: <xref:invalid#anchor>", "Test short xref: <a class=\"xref\" href=\"test/test.html\">Hello World</a>", "Test xref with query string: <a class=\"xref\" href=\"test/test.html\">Foo<T></a>", "Test invalid xref with query string: <span class=\"xref\">Foo<T></span>", "Test xref with attribute: <a class=\"xref\" href=\"test/test.html\">Foo<T></a>", "Test xref with attribute: <a class=\"xref\" href=\"test/test.html\">Foo<T></a>", "Test invalid xref with attribute: <span class=\"xref\">Foo<T></span>", "Test invalid xref with attribute: <span class=\"xref\">Foo<T></span>", "<p>", "test</p>", ""), File.ReadAllText(conceptualOutputPath)); } { // check toc. Assert.True(File.Exists(Path.Combine(outputFolderForIncremental, Path.ChangeExtension(tocFile, ".html")))); } { // check mref. Assert.True(File.Exists(Path.Combine(outputFolderForIncremental, Path.ChangeExtension("System.Console.csyml", ".html")))); Assert.True(File.Exists(Path.Combine(outputFolderForIncremental, Path.ChangeExtension("System.ConsoleColor.csyml", ".html")))); } { // check resource. Assert.True(File.Exists(Path.Combine(outputFolderForIncremental, resourceFile))); } } finally { CleanUp(); Directory.Delete(outputFolder, true); Directory.Delete(templateFolder, true); Directory.Delete(inputFolder, true); Directory.Delete(intermediateFolder, true); } }
public void TestContextObjectSDP() { using (var listener = new TestListenerScope("TestContextObjectSDP")) { var schemaFile = CreateFile("template/schemas/contextobject.schema.json", File.ReadAllText("TestData/schemas/contextobject.test.schema.json"), _templateFolder); var tocTemplate = CreateFile("template/toc.json.tmpl", "toc template", _templateFolder); // var coTemplate = CreateFile("template/contextobject.json.tmpl", "{{file_include2}}", _templateFolder); var inputFileName = "co/active.yml"; var includeFile = CreateFile("a b/inc.md", @"[root](../co/active.yml)", _inputFolder); var includeFile2 = CreateFile("c/d/inc.md", @"../../a b/toc.md", _inputFolder); var inputFile = CreateFile(inputFileName, @"### YamlMime:ContextObject breadcrumb_path: /absolute/toc.json toc_rel: ../a b/toc.md file_include: ../a b/inc.md file_include2: ../c/d/inc.md uhfHeaderId: MSDocsHeader-DotNet empty: searchScope: - .NET ", _inputFolder); FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { inputFile }, _inputFolder); BuildDocument(files); Assert.Equal(4, listener.Items.Count); Assert.Equal(2, listener.Items.Count(s => s.Message.StartsWith($"Invalid file link:(~/{_inputFolder}/a b/toc.md)."))); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): ContextObject"))); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("Invalid file link"))); listener.Items.Clear(); var rawModelFilePath = GetRawModelFilePath(inputFileName); Assert.True(File.Exists(rawModelFilePath)); var rawModel = JsonUtility.Deserialize <JObject>(rawModelFilePath); Assert.Equal("Hello world!", rawModel["meta"].Value <string>()); Assert.Equal("/absolute/toc.json", rawModel["breadcrumb_path"].Value <string>()); Assert.Equal("../a b/toc.md", rawModel["toc_rel"].Value <string>()); Assert.Equal($"<p sourcefile=\"{includeFile}\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"><a href=\"~/{inputFile}\" data-raw-source=\"[root](../co/active.yml)\" sourcefile=\"{includeFile}\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">root</a></p>\n", rawModel["file_include"].Value <string>()); Assert.Equal("../../a b/toc.md", rawModel["file_include2"].Value <string>()); Assert.Equal("MSDocsHeader-DotNet", rawModel["uhfHeaderId"].Value <string>()); Assert.Equal($".NET", rawModel["searchScope"][0].Value <string>()); files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { inputFile }, _inputFolder); var tocFile = CreateFile("a b/toc.md", "### hello", _inputFolder); files.Add(DocumentType.Article, new[] { tocFile }, _inputFolder); BuildDocument(files); Assert.Equal(2, listener.Items.Count); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): ContextObject"))); Assert.True(File.Exists(rawModelFilePath)); rawModel = JsonUtility.Deserialize <JObject>(rawModelFilePath); Assert.Equal("Hello world!", rawModel["meta"].Value <string>()); Assert.Equal("/absolute/toc.json", rawModel["breadcrumb_path"].Value <string>()); Assert.Equal("../a%20b/toc.json", rawModel["toc_rel"].Value <string>()); Assert.Equal("MSDocsHeader-DotNet", rawModel["uhfHeaderId"].Value <string>()); Assert.Equal($".NET", rawModel["searchScope"][0].Value <string>()); Assert.Equal("../a%20b/toc.json", rawModel["file_include2"].Value <string>()); } }
public void TestUidWithPatternedTag() { using var listener = new TestListenerScope("TestUidWithPatternedTag"); var schemaFile = CreateFile("template/schemas/patterned.uid.test.schema.json", @" { ""$schema"": ""http://dotnet.github.io/docfx/schemas/v1.0/schema.json#"", ""version"": ""1.0.0"", ""title"": ""PatternedUid"", ""description"": ""A simple test schema for sdp's patterned uid"", ""type"": ""object"", ""properties"": { ""uid"": { ""type"": ""string"", ""tags"": [ ""patterned:uid"" ] } } } ", _templateFolder); var inputFile = CreateFile("PatternedUid.yml", @"### YamlMime:PatternedUid uid: azure.hello1 ", _inputFolder); FileCollection files = new FileCollection(_defaultFiles); files.Add(DocumentType.Article, new[] { inputFile }, _inputFolder); BuildDocument(files, new DocumentBuildParameters { Files = files, OutputBaseDir = _outputFolder, ApplyTemplateSettings = _applyTemplateSettings, TemplateManager = _templateManager, TagParameters = new Dictionary <string, JArray> { ["patterned:uid"] = JArray.FromObject(new List <string> { "^azure\\..*" }) }, }); Assert.Equal(2, listener.Items.Count); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): PatternedUid"))); listener.Items.Clear(); inputFile = CreateFile("PatternedUid2.yml", @"### YamlMime:PatternedUid uid: invalid.hello1 ", _inputFolder); files.Add(DocumentType.Article, new[] { inputFile }, _inputFolder); inputFile = CreateFile("PatternedUid3.yml", @"### YamlMime:PatternedUid uid: invalid.azure.hello2 ", _inputFolder); files.Add(DocumentType.Article, new[] { inputFile }, _inputFolder); var exception = Assert.Throws <DocumentException>(() => BuildDocument(files, new DocumentBuildParameters { Files = files, OutputBaseDir = _outputFolder, ApplyTemplateSettings = _applyTemplateSettings, TemplateManager = _templateManager, TagParameters = new Dictionary <string, JArray> { ["patterned:uid"] = JArray.FromObject(new List <string> { "^azure\\..*" }) }, })); Assert.Equal("InvalidPropertyFormat", exception.Code); Assert.Equal(0, listener.Items.Count(s => s.Code == ErrorCodes.Build.InvalidPropertyFormat)); }
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.GetFullPath(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); }
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.GetFullPath(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 ProcessPythonModelShouldSucceed() { var moduleFileName = "cntk.core.yml"; var classFileName = "cntk.core.Value.yml"; var files = new FileCollection(Directory.GetCurrentDirectory()); files.Add( DocumentType.Article, new[] { $"{YmlDataDirectory}/{moduleFileName}", $"{YmlDataDirectory}/{classFileName}" }, TestDataDirectory); BuildDocument(files); var outputModuleRawModelPath = GetRawModelFilePath(moduleFileName); var outputClassRawModelPath = GetRawModelFilePath(classFileName); Assert.True(File.Exists(outputClassRawModelPath)); var moduleModel = JsonUtility.Deserialize <ApiBuildOutput>(outputModuleRawModelPath); Assert.NotNull(moduleModel); Assert.Equal("Test UniversalReferenceDocumentProcessor", moduleModel.Metadata["meta"]); Assert.Equal( "<p sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"2\">Bases: <xref href=\"cntk.cntk_py.Value\" data-throw-if-not-resolved=\"False\" data-raw-source=\"@cntk.cntk_py.Value\" sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"></xref>\nInternal representation of minibatch data.</p>\n", moduleModel.Children[0].Value[1].Summary); Assert.Equal("Class", moduleModel.Children[0].Value[1].Type); var classModel = JsonUtility.Deserialize <ApiBuildOutput>(outputClassRawModelPath); Assert.NotNull(classModel); Assert.Equal("Test UniversalReferenceDocumentProcessor", classModel.Metadata["meta"]); Assert.Single(classModel.SupportedLanguages); Assert.Equal("python", classModel.SupportedLanguages[0]); Assert.Equal("Class", classModel.Type); Assert.Equal("Value", classModel.Name[0].Value); Assert.Equal("cntk.core.Value", classModel.FullName[0].Value); Assert.Equal("https://github.com/Microsoft/CNTK", classModel.Source[0].Value.Remote.RemoteRepositoryUrl); Assert.Equal("cntk/core.py", classModel.Source[0].Value.Remote.RelativePath); Assert.Equal(182, classModel.Source[0].Value.StartLine); Assert.Equal(6, classModel.Syntax.Parameters.Count); Assert.Equal("shape", classModel.Syntax.Parameters[0].Name); Assert.Equal("tuple", classModel.Syntax.Parameters[0].Type[0].Uid); Assert.Equal("<p sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">shape of the value</p>\n", classModel.Syntax.Parameters[0].Description); Assert.Equal("cntk.cntk_py.Value", classModel.Inheritance[0].Value[0].Type.Uid); Assert.Equal("builtins.object", classModel.Inheritance[0].Value[0].Inheritance[0].Type.Uid); Assert.Single(classModel.Children); Assert.Equal("python", classModel.Children[0].Language); Assert.Equal(5, classModel.Children[0].Value.Count); var firstChildrenValue = classModel.Children[0].Value[0]; Assert.Equal("Method", firstChildrenValue.Type); Assert.Equal("cntk.core.Value.create", firstChildrenValue.Uid); Assert.Equal("create", firstChildrenValue.Name[0].Value); Assert.Equal("cntk.core.Value.create", firstChildrenValue.FullName[0].Value); Assert.Equal("<p sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">Creates a <xref href=\"cntk.core.Value\" data-throw-if-not-resolved=\"False\" data-raw-source=\"@cntk.core.Value\" sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"></xref> object.</p>\n", firstChildrenValue.Summary); Assert.Equal("<p sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"><xref href=\"cntk.core.Value\" data-throw-if-not-resolved=\"False\" data-raw-source=\"@cntk.core.Value\" sourcefile=\"TestData/yml/cntk.core.Value.yml\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"></xref> object.</p>\n", firstChildrenValue.Syntax.Return[0].Value.Description); Assert.Equal("type1", firstChildrenValue.Syntax.Return[0].Value.Type[0].Uid); Assert.Equal("type2", firstChildrenValue.Syntax.Return[0].Value.Type[1].Uid); Assert.Equal("type3", firstChildrenValue.Syntax.Return[0].Value.Type[2].Uid); }
public void TestBuildConceptualWithTemplateShouldSucceed() { CreateFile("conceptual.html.js", @" exports.transform = function (model){ return JSON.stringify(model, null, ' '); }; exports.xref = null; ", _templateFolder); CreateFile("toc.tmpl.js", @" exports.getOptions = function (){ return { isShared: true }; }; ", _templateFolder); CreateFile("conceptual.html.tmpl", "{{.}}", _templateFolder); var conceptualFile = CreateFile("test.md", new[] { "---", "uid: XRef1", "---", "# Hello World", "Test link: [link text](test/test.md)", "test", }, _inputFolder); var conceptualFile2 = CreateFile("test/test.md", new[] { "---", "uid: XRef2", "---", "test", }, _inputFolder); var tocFile = CreateFile("toc.md", new[] { "#[Test](test.md)" }, _inputFolder); var tocFile2 = CreateFile("test/toc.md", new[] { "#[Test](test.md)" }, _inputFolder); FileCollection files = new FileCollection(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { conceptualFile, conceptualFile2, tocFile, tocFile2 }); BuildDocument( files, new Dictionary<string, object> { ["meta"] = "Hello world!", }, templateFolder: _templateFolder); { // check toc. Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize<Dictionary<string, object>>(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))); var expected = new Dictionary<string, object> { ["_lang"] = "csharp", ["_tocPath"] = $"{_inputFolder}/toc", ["_rel"] = "../", ["_path"] = $"{_inputFolder}/toc", ["_tocRel"] = "toc", ["_tocKey"] = $"~/{_inputFolder}/toc.md", ["items"] = new object[] { new { name = "Test", href = "test.html", topicHref = "test.html" } }, ["__global"] = new { _shared = new Dictionary<string, object> { [$"~/{_inputFolder}/toc.md"] = new Dictionary<string, object> { ["_lang"] = "csharp", ["_tocPath"] = $"{_inputFolder}/toc", ["_rel"] = "../", ["_path"] = $"{_inputFolder}/toc", ["_tocRel"] = "toc", ["_tocKey"] = $"~/{_inputFolder}/toc.md", ["items"] = new object[] { new { name = "Test", href = "test.html", topicHref = "test.html" } }, }, [$"~/{_inputFolder}/test/toc.md"] = new Dictionary<string, object> { ["_lang"] = "csharp", ["_tocPath"] = $"{_inputFolder}/test/toc", ["_rel"] = "../../", ["_path"] = $"{_inputFolder}/test/toc", ["_tocRel"] = "toc", ["_tocKey"] = $"~/{_inputFolder}/test/toc.md", ["items"] = new object[] { new { name = "Test", href = "test.html", topicHref = "test.html" } }, } } } }; AssertMetadataEqual(expected, model); } { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); Assert.True(File.Exists(conceptualOutputPath)); Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize<Dictionary<string, object>>(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); var expected = new Dictionary<string, object> { ["_lang"] = "csharp", ["_tocPath"] = $"{_inputFolder}/toc", ["_rel"] = "../", ["_path"] = $"{_inputFolder}/test.html", ["_tocRel"] = "toc", ["_tocKey"] = $"~/{_inputFolder}/toc.md", ["conceptual"] = $"\n<p sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"5\" sourceendlinenumber=\"6\">Test link: <a href=\"~/{_inputFolder}/test/test.md\" data-raw-source=\"[link text](test/test.md)\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"5\" sourceendlinenumber=\"5\">link text</a>\ntest</p>\n", ["type"] = "Conceptual", ["source"] = model["source"], // reuse model's source, not testing this ["path"] = $"{_inputFolder}/test.md", ["meta"] = "Hello world!", ["title"] = "Hello World", ["rawTitle"] = $"<h1 id=\"hello-world\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"4\" sourceendlinenumber=\"4\">Hello World</h1>", ["uid"] = "XRef1", ["wordCount"] = 5, ["__global"] = new { _shared = new Dictionary<string, object> { [$"~/{_inputFolder}/toc.md"] = new Dictionary<string, object> { ["_lang"] = "csharp", ["_tocPath"] = $"{_inputFolder}/toc", ["_rel"] = "../", ["_path"] = $"{_inputFolder}/toc", ["_tocRel"] = "toc", ["_tocKey"] = $"~/{_inputFolder}/toc.md", ["items"] = new object[] { new { name = "Test", href = "test.html", topicHref = "test.html" } }, }, [$"~/{_inputFolder}/test/toc.md"] = new Dictionary<string, object> { ["_lang"] = "csharp", ["_tocPath"] = $"{_inputFolder}/test/toc", ["_rel"] = "../../", ["_path"] = $"{_inputFolder}/test/toc", ["_tocRel"] = "toc", ["_tocKey"] = $"~/{_inputFolder}/test/toc.md", ["items"] = new object[] { new { name = "Test", href = "test.html", topicHref = "test.html" } }, } } } }; AssertMetadataEqual(expected, model); } }