public void ContentContainsMultipleHeaders() { // Arrange var expectedToc = new Toc { ToCValueForPasting = @"# Table of Content * One * Two * Three" }; const string content = @"There contains multiple headers # One But nothing more # Two # Three"; // Act var response = controller.CreateToc(content); // Assert var printer = GetTestPrinter(); Toc actualToc = null; PAssert.IsTrue(() => response.TryGetContentValue(out actualToc)); Assert.AreEqual(printer.PrintObject(expectedToc), printer.PrintObject(actualToc)); }
// [Test] public void ContentContainsSingleHeader() { // Arrange var expectedToc = new Toc { ToCValueForPasting = "# Table of Content" + Environment.NewLine + "* Right Here" }; var content = "There is a single header" + Environment.NewLine + "# Right Here" + Environment.NewLine + "But nothing more"; var reader = new Mock <UrlReader>(MockBehavior.Strict); reader.Setup(x => x.ReadUrl(It.IsAny <Uri>())).Returns(content); // Act var response = controller.Get(anyUrl); // Assert var printer = Create.Printer(); Toc actualToc = null; PAssert.IsTrue(() => response.TryGetContentValue(out actualToc)); var expected = @"new Toc() { ToCValueForPasting = ""Support custom ordering of collections::Open, projection should enable adding computed field::Open, integration with coverty::Open, Add tabular as an output form::Open, Stateprinter.printobject should not use optional paramters::Open"" }"; printer.Assert.PrintIsSame(expected, actualToc); }
public void ContentContainsSingleHeader() { // Arrange var content = "There is a single header" + Environment.NewLine + "Table of content" + Environment.NewLine + "# Right Here" + Environment.NewLine + "But nothing more"; var reader = new Mock <UrlReader>(MockBehavior.Strict); reader.Setup(x => x.ReadUrl(It.IsAny <Uri>())).Returns(content); controller.reader = reader.Object; // Act var response = controller.Get(anyUrl); // Assert var printer = Create.Printer(); Toc actualToc = null; PAssert.IsTrue(() => response.TryGetContentValue(out actualToc)); var expected = @"new Toc() { ToCValueForPasting = ""Table of Content * [Right Here](#right-here) "" }"; printer.Assert.PrintIsSame(expected, actualToc); }
public static void ClearTocCache(string culture, string productCategory, string docSetCategory) { string key = culture + "_" + productCategory + "_" + docSetCategory; Toc result = null; tocDic.TryRemove(key, out result); }
public static void DownloadSchedule(string filePath, Toc toc = Toc.All, ScheduleType schedule = ScheduleType.Full, DayOfWeek? day = null) { Uri requestUri = new Uri(string.Format("{0}?type={1}&day={2}", (object)ConfigurationManager.AppSettings["ScheduleUri"], (object)string.Format("CIF_{0}_{1}_DAILY", (object)TocHelper.TocToString(toc), (object)TocHelper.ScheduleTypeToString(schedule)), (object)TocHelper.ScheduleTypeToDay(schedule, day))); Trace.TraceInformation("Downloading file: {0} to {1}", requestUri, filePath); byte[] buffer = new byte[4096]; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Timeout = (int)TimeSpan.FromMinutes((double)int.Parse(ConfigurationManager.AppSettings["ScheduleTimeoutMins"])).TotalMilliseconds; string str = Convert.ToBase64String(Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["Username"] + ":" + ConfigurationManager.AppSettings["Password"])); webRequest.Headers[HttpRequestHeader.Authorization] = "Basic " + str; using (WebResponse response = webRequest.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (MemoryStream memoryStream = new MemoryStream()) { int count; int counter = 0; do { Console.WriteLine("Downloading bytes {0}", counter * 4096); count = responseStream.Read(buffer, 0, buffer.Length); memoryStream.Write(buffer, 0, count); counter++; } while (count != 0); byte[] bytes = memoryStream.ToArray(); System.IO.File.WriteAllBytes(filePath, bytes); } } } }
public ArcImsLegend(Toc toc) { _toc = toc; foreach (TocGroup tocGroup in toc) { Groups.Add(new ArcImsLegendGroup(tocGroup)); } }
public void AddOrReplaceAddsNewTocWhenNotExist() { var avanti = new Toc("VT", "Avanti"); var lookup = new TocLookup(Substitute.For <ILogger>(), new Dictionary <string, Toc>()); lookup.AddOrReplace("VT", avanti); var toc = lookup["VT"].Single(); Assert.Same(avanti, toc); }
/* ## Constructing TOC Manager ## ## There are two ways to create a TocManager. When a TOC file already exist, it ## is loaded and initialized automatically. */ public TocManager(Toc toc, string filename) { if (toc == null) { throw new ArgumentNullException(nameof(toc)); } _toc = toc; _filename = filename; _addedSections = new List <Section> (); }
public void ReturnsExistingToc() { var vt = new Toc("VT"); var lookup = new TocLookup(Substitute.For <ILogger>(), new Dictionary <string, Toc>() { { "VT", vt } }); var toc = lookup.FindOrAdd("VT"); Assert.Same(vt, toc); }
private static int MergeToc(string mkdocsPath, string newTocPath) { var mkdocs = new YamlStream(); using (var reader = new StreamReader(mkdocsPath)) { mkdocs.Load(reader); } Toc toc = null; using (var reader = new StreamReader(newTocPath)) { // Examine the new toc var deserializer = new YamlDotNet.Serialization.DeserializerBuilder().Build(); toc = deserializer.Deserialize <Toc>(reader); } // the mkdocs format is not ammenable to object serialization unfortunately... var root = (YamlMappingNode)mkdocs.Documents[0].RootNode; // Examine the stream var items = (YamlSequenceNode)root.Children[new YamlScalarNode("nav")]; var apitoc = items.Where(it => it is YamlMappingNode ym && ym.Children.Count > 0 && ym.Children[0].Key is YamlScalarNode s && s.Value == "API documentation").FirstOrDefault() as YamlMappingNode; if (apitoc == null) { apitoc = new YamlMappingNode(); items.Add(apitoc); } apitoc.Children.Clear(); var s = new YamlSequenceNode(); apitoc.Add(new YamlScalarNode("API documentation"), s); int count = AddLinks(s, toc.toc); // save the updated mkdocs using (var writer = new StreamWriter(mkdocsPath)) { mkdocs.Save(writer, false); } Console.WriteLine("Added {0} api documentation links to the nav: section in {1}", count, mkdocsPath); return(0); }
public void IgnoresAddingExistingToc() { var avanti = new Toc("VT", "Avanti"); var lookup = new TocLookup(Substitute.For <ILogger>(), new Dictionary <string, Toc>() { { "VT", avanti } }); var virgin = new Toc("VT", "Virgin"); lookup.AddIfNotExist("VT", virgin); var toc = lookup["VT"].Single(); Assert.Same(avanti, toc); }
public void AddOrReplaceReplacesExistingToc() { var avanti = new Toc("VT", "Avanti"); var lookup = new TocLookup(Substitute.For <ILogger>(), new Dictionary <string, Toc>() { { "VT", avanti } }); var virgin = new Toc("VT", "Virgin"); lookup.AddOrReplace("VT", virgin); var toc = lookup["VT"].Single(); Assert.Same(virgin, toc); }
public void ContentDoesNotContainAnyHeaders() { // Arrange var expectedToc = new Toc { ToCValueForPasting = "# Table of Content" }; const string content = "There is something here, but no headers"; // Act var response = controller.CreateToc(content); // Assert var printer = GetTestPrinter(); Toc actualToc = null; PAssert.IsTrue(() => response.TryGetContentValue(out actualToc)); Assert.AreEqual(printer.PrintObject(expectedToc), printer.PrintObject(actualToc)); }
/* ## Constructor ## ## Options and TOC are passed as parameters to the constructor. The rest of ## the fields are initialized inside it. Theme is loaded from the disk, ## Markdown pipeline is created and configured, and a PageParams object is ## created. */ public HtmlGenerator(Options options, Toc toc) { _options = options; _theme = LoadTheme(); _pipeline = new MarkdownPipelineBuilder() .UseCustomContainers() .UseGenericAttributes() .UseAutoIdentifiers() .UseYamlFrontMatter() .UseMathematics() .UseDiagrams() .UsePipeTables() .UseEmphasisExtras() .Build(); _params = new PageParams(); _params.Toc = toc; ConvertTocMarkdown(); }
public static Toc GetToc(string culture, string docPath) { Toc result = null; int firstSlashIndex = docPath.IndexOf("/"); if (firstSlashIndex < 0) { return(null); } string productCategory = docPath.Substring(0, firstSlashIndex); string docPathTrimProduct = docPath.Substring(firstSlashIndex + 1); firstSlashIndex = docPathTrimProduct.IndexOf("/"); if (firstSlashIndex < 0) { return(null); } string docSetCategory = docPathTrimProduct.Substring(0, firstSlashIndex); result = GetCachedToc(culture, productCategory, docSetCategory); if (result == null) { string tocFilePath = productCategory + "/" + docSetCategory + "/toc.xml"; string tocContent = BlobManager.ReadContent(blobConnectString, docBlobContainer, culture, tocFilePath); if (tocContent != null) { result = XmlReader.GetOject <Toc>(tocContent); if (result != null) { result.RootPath = docSetCategory; result.UrlPrefix = "/" + culture + result.UrlPrefix + productCategory + "/" + docSetCategory + "/"; CacheToc(culture, productCategory, docSetCategory, result); BuildTheTocChildMap(result); } } } return(result); }
public void ContentDoesNotContainAnyHeaders() { // Arrange var expectedToc = new Toc { ToCValueForPasting = "# Table of Content" }; const string content = "There is something here, but no headers"; var reader = new Mock <UrlReader>(MockBehavior.Strict); reader.Setup(x => x.ReadUrl(It.IsAny <Uri>())).Returns(content); controller.reader = reader.Object; // Act var response = controller.Get(anyUrl); // Assert var printer = Create.Printer(); Toc actualToc = null; PAssert.IsTrue(() => response.TryGetContentValue(out actualToc)); // Assert.AreEqual(printer.PrintObject(expectedToc), printer.PrintObject(actualToc)); }
public void ContentContainsMultipleHeaders() { // Arrange var expectedToc = new Toc { ToCValueForPasting = "# Table of Content" + Environment.NewLine + "* One" + Environment.NewLine + "* Two" + Environment.NewLine + "* Three" }; var content = "There contains multiple headers" + Environment.NewLine + "# One" + Environment.NewLine + "But nothing more" + Environment.NewLine + "# Two" + Environment.NewLine + "# Three"; var reader = new Mock <UrlReader>(MockBehavior.Strict); reader.Setup(x => x.ReadUrl(It.IsAny <Uri>())).Returns(content); controller.reader = reader.Object; // Act var response = controller.Get(anyUrl); // Assert var printer = Create.Printer(); Toc actualToc = null; PAssert.IsTrue(() => response.TryGetContentValue(out actualToc)); //Assert.AreEqual(printer.PrintObject(expectedToc), printer.PrintObject(actualToc)); }
private void LoadTypes(Toc entry, string namespacePrefix, List <(string link, string fullName)> links)
private static void BuildTheTocChildMap(Toc toc) { BuildTheTocChildMap(toc.TocItem, new List <TocItem>()); }
private static void CacheToc(string culture, string productCategory, string docSetCategory, Toc toc) { string key = culture + "_" + productCategory + "_" + docSetCategory; if (!tocDic.ContainsKey(key)) { tocDic.TryAdd(key, toc); } }
public void IsValid(string[] tocs, Toc testToc, bool expected) { var filter = new TocFilter(tocs); Assert.Equal(expected, filter.IsValid(testToc)); }
/* * If there is no file available, a parameterless constructor can be called to * create an empty TOC. In this case the TOC does not need to be updated, so * the `_addedSections` field can be left uninitialized. */ public TocManager() { _toc = new Toc(); _toc.Contents = new List <Section> (); }