Skip to content

Commit

Permalink
tests: test cookbook using new generator
Browse files Browse the repository at this point in the history
  • Loading branch information
swharden committed Sep 28, 2021
1 parent 170d2a7 commit 533b65f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/cookbook/output
nuget.exe

## Ignore Visual Studio temporary files, build results, and
Expand Down
94 changes: 10 additions & 84 deletions src/tests/Cookbook/Generate.cs
Original file line number Diff line number Diff line change
@@ -1,106 +1,32 @@
using NUnit.Framework;
using ScottPlot.Cookbook;
using ScottPlot.Cookbook.Website;
using ScottPlot.Cookbook.Website.Pages;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ScottPlotTests.Cookbook
{
class Generate
{
/// <summary>
/// Source folder containing the original .cs files that will be parsed to get recipe source code
/// </summary>
const string SourceFolder = "../../../../cookbook/ScottPlot.Cookbook";

/// <summary>
/// The folder that will store isolated code example text files
/// </summary>
const string RecipeFolder = "./cookbook/source";

/// <summary>
/// The folder to put the website into
/// </summary>
const string WebsitePath = "./website";
const string COOKBOOK_PROJECT_FOLDER = "../../../../cookbook/ScottPlot.Cookbook";
const string COOKBOOK_OUTPUT_FOLDER = "../../../../cookbook/output";

[OneTimeSetUp]
public void Setup()
{
CreateFolder(RecipeFolder);
CreateFolder(WebsitePath);
}

private static void CreateFolder(string path)
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}

[Test]
public void Test_Cookbook_ImagesAndCode()
{
Chef.CreateCookbookImages(Path.Join(WebsitePath, "images"));
Chef.CreateCookbookSource(SourceFolder, RecipeFolder);
}

[Test]
public void Test_Webpage_CookbookCategoryPages()
{
string cookbookFolder = Path.Combine(WebsitePath, "category");
CreateFolder(cookbookFolder);
foreach (var categoryName in Locate.GetCategories())
{
var page = new CookbookCategoryPage(categoryName);

string categoryFolder = Path.Combine(cookbookFolder, Page.Sanitize(categoryName));
CreateFolder(categoryFolder);
string mdFilePath = Path.Combine(categoryFolder, "index.md");
page.SaveMarkdown(mdFilePath);
Console.WriteLine(Path.GetFullPath(mdFilePath));
}
}

[Test]
public void Test_Webpage_CookIndexPage()
public void OneTimeSetup()
{
var page = new CookbookHomePage();
string mdPath = Path.Combine(WebsitePath, "index.md");
page.SaveMarkdown(mdPath);
Console.WriteLine(Path.GetFullPath(mdPath));
if (Directory.Exists(COOKBOOK_OUTPUT_FOLDER))
Directory.Delete(COOKBOOK_OUTPUT_FOLDER, recursive: true);
Directory.CreateDirectory(COOKBOOK_OUTPUT_FOLDER);
}

[Test]
public void Test_Webpage_PlotApi()
public void Test_Generate_RecipeImages()
{
var page = new PlotApiPage();
string mdFilePath = Path.Combine(WebsitePath, "api/plot/index.md");
CreateFolder(Path.GetDirectoryName(mdFilePath));
page.SaveMarkdown(mdFilePath);
Console.WriteLine();
Console.WriteLine(Path.GetFullPath(mdFilePath));
Chef.CreateCookbookImages(Path.Join(COOKBOOK_OUTPUT_FOLDER, "images"));
}

[Test]
public void Test_Webpage_ForEveryPlottable()
public void Test_Generate_RecipeSourceJson()
{
string plottableFolder = WebsitePath + "/api/plottable";
CreateFolder(plottableFolder);
foreach (var plottableType in Locate.GetPlottableTypes())
{
var page = new PlottableApiPage(plottableType);
string thisPlottableFolder = plottableFolder + "/" + Page.Sanitize(plottableType.Name);
CreateFolder(thisPlottableFolder);
string mdPath = thisPlottableFolder + "/index.md";
//CreateFolder(thisPlottableFolder);
page.SaveMarkdown(mdPath);
Console.WriteLine(Path.GetFullPath(mdPath));
}
Chef.CreateRecipesJson(COOKBOOK_PROJECT_FOLDER, Path.Join(COOKBOOK_OUTPUT_FOLDER, "recipes.json"));
}
}
}

0 comments on commit 533b65f

Please sign in to comment.