testing markdown storage and retrieval

This commit is contained in:
2023-12-04 12:27:06 -07:00
parent 69f0b322b2
commit c6ce528ba1
23 changed files with 467 additions and 340 deletions

View File

@@ -12,6 +12,7 @@
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="nsubstitute" Version="5.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />

View File

@@ -0,0 +1,261 @@
using LocalModels;
using Management.Services;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute;
using NUnit.Framework.Internal;
public class FileStorageTests
{
private FileStorageManager fileManager { get; set; }
private string setupTempDirectory()
{
var tempDirectory = Path.GetTempPath();
var storageDirectory = tempDirectory + "fileStorageTests";
Console.WriteLine(storageDirectory);
if (!Directory.Exists(storageDirectory))
Directory.CreateDirectory(storageDirectory);
else
{
var di = new DirectoryInfo(storageDirectory);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
}
return storageDirectory;
}
[SetUp]
public void SetUp()
{
var storageDirectory = setupTempDirectory();
var fileManagerLogger = new MyLogger<FileStorageManager>(NullLogger<FileStorageManager>.Instance);
var markdownLoaderLogger = new MyLogger<CourseMarkdownLoader>(NullLogger<CourseMarkdownLoader>.Instance);
Environment.SetEnvironmentVariable("storageDirectory", storageDirectory);
var markdownLoader = new CourseMarkdownLoader(markdownLoaderLogger);
fileManager = new FileStorageManager(fileManagerLogger, markdownLoader);
}
[Test]
public async Task EmptyCourse_CanBeSavedAndLoaded()
{
LocalCourse testCourse = new LocalCourse
{
Settings = new()
{
Name = "test empty course",
},
Modules = []
};
await fileManager.SaveCourseAsync(testCourse);
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
loadedCourse.Should().BeEquivalentTo(testCourse);
}
[Test]
public async Task CourseSettings_CanBeSavedAndLoaded()
{
LocalCourse testCourse = new()
{
Settings = new()
{
AssignmentGroups = [],
Name = "Test Course with settings",
DaysOfWeek = [DayOfWeek.Monday, DayOfWeek.Wednesday],
StartDate = new DateTime(),
EndDate = new DateTime(),
DefaultDueTime = new() { Hour = 1, Minute = 59 },
},
Modules = []
};
await fileManager.SaveCourseAsync(testCourse);
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
loadedCourse.Settings.Should().BeEquivalentTo(testCourse.Settings);
}
[Test]
public async Task EmptyCourseModules_CanBeSavedAndLoaded()
{
LocalCourse testCourse = new()
{
Settings = new()
{
Name = "Test Course with modules",
},
Modules = [
new() {
Name="test module 1",
Assignments= [],
Quizzes=[]
}
]
};
await fileManager.SaveCourseAsync(testCourse);
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
loadedCourse.Modules.Should().BeEquivalentTo(testCourse.Modules);
}
[Test]
public async Task CourseModules_WithAssignments_CanBeSavedAndLoaded()
{
LocalCourse testCourse = new()
{
Settings = new()
{
Name = "Test Course with modules and assignments",
},
Modules = [
new() {
Name="test module 1 with assignments",
Assignments=[
new () {
Name="test assignment",
Description ="here is the description",
DueAt = new DateTime(),
LockAt = new DateTime(),
SubmissionTypes = [AssignmentSubmissionType.ONLINE_UPLOAD],
LocalAssignmentGroupName = "Final Project",
Rubric = [
new() {Points = 4, Label="do task 1"},
new() {Points = 2, Label="do task 2"},
]
}
],
Quizzes=[]
}
]
};
await fileManager.SaveCourseAsync(testCourse);
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
loadedCourse.Modules.First().Assignments.Should().BeEquivalentTo(testCourse.Modules.First().Assignments);
}
[Test]
public async Task CourseModules_WithQuizzes_CanBeSavedAndLoaded()
{
LocalCourse testCourse = new()
{
Settings = new() { Name = "Test Course with modules and quiz" },
Modules = [
new() {
Name="test module 1 with quiz",
Assignments=[],
Quizzes=[
new() {
Name = "Test Quiz",
Description = "quiz description",
LockAt = new DateTime(2022, 10, 3, 12, 5, 0),
DueAt = new DateTime(2022, 10, 3, 12, 5, 0),
ShuffleAnswers = true,
OneQuestionAtATime = true,
LocalAssignmentGroupName = "Assignments",
Questions=[
new () {
Text = "test essay",
QuestionType = QuestionType.ESSAY,
Points = 1
}
]
}
]
}
]
};
await fileManager.SaveCourseAsync(testCourse);
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
loadedCourse.Modules.First().Quizzes.Should().BeEquivalentTo(testCourse.Modules.First().Quizzes);
}
[Test]
public async Task MarkdownStorage_FullyPopulated_DoesNotLoseData()
{
LocalCourse testCourse = new (){
Settings = new () {
AssignmentGroups = [],
Name = "Test Course with lots of data",
DaysOfWeek = [DayOfWeek.Monday, DayOfWeek.Wednesday],
StartDate = new DateTime(),
EndDate = new DateTime(),
DefaultDueTime = new() { Hour = 1, Minute = 59 },
},
Modules = [
new() {
Name= "new test module",
Assignments = [
new() {
Name="test assignment",
Description ="here is the description",
DueAt = new DateTime(),
LockAt = new DateTime(),
SubmissionTypes = [AssignmentSubmissionType.ONLINE_UPLOAD],
LocalAssignmentGroupName = "Final Project",
Rubric = [
new() { Points = 4, Label="do task 1" },
new() { Points = 2, Label="do task 2" },
]
}
],
Quizzes = [
new() {
Name = "Test Quiz",
Description = "quiz description",
LockAt = new DateTime(),
DueAt = new DateTime(),
ShuffleAnswers = true,
OneQuestionAtATime = false,
LocalAssignmentGroupName = "someId",
AllowedAttempts = -1,
Questions = [
new() {
Text = "test short answer",
QuestionType = QuestionType.SHORT_ANSWER,
Points = 1
}
]
}
]
}
]
};
await fileManager.SaveCourseAsync(testCourse);
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
loadedCourse.Should().BeEquivalentTo(testCourse);
}
}

View File

@@ -5,9 +5,11 @@ public class MonthDetailTests
[Test]
public void TestCanGetMonthName()
{
var detail = new MonthDetail();
var calendarMonth = new CalendarMonth(2022, 2);
detail.Month = calendarMonth;
var detail = new MonthDetail()
{
Month = calendarMonth
};
detail.MonthName.Should().Be("February");
}

View File

@@ -3,7 +3,6 @@
@using CanvasModel.EnrollmentTerms
@using Management.Web.Shared.Components.AssignmentForm
@using Management.Web.Shared.Course
@using Management.Web.Shared.Module.Assignment.Templates
@using Management.Web.Shared.Semester
@using CanvasModel.Courses
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage

View File

@@ -1,7 +1,6 @@
@page "/course/{CourseName}"
@using CanvasModel.EnrollmentTerms
@using Management.Web.Shared.Course
@using Management.Web.Shared.Module.Assignment.Templates
@using Management.Web.Shared.Semester
@using CanvasModel.Courses
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage

View File

@@ -1,7 +1,6 @@
@page "/"
@using CanvasModel.EnrollmentTerms
@using Management.Web.Shared.Course
@using Management.Web.Shared.Module.Assignment.Templates
@using Management.Web.Shared.Semester
@using CanvasModel.Courses
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage

View File

@@ -4,7 +4,6 @@
@using CanvasModel.Quizzes
@using Management.Web.Shared.Components.AssignmentForm
@using Management.Web.Shared.Course
@using Management.Web.Shared.Module.Assignment.Templates
@using Management.Web.Shared.Semester
@using CanvasModel.Courses
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage

View File

@@ -32,15 +32,6 @@
public string? TemplateId { get; set; }
public Dictionary<string, string> VariableValues { get; set; } = new Dictionary<string, string>();
private AssignmentTemplate? selectedTemplate =>
planner
.LocalCourse?
.Settings
.AssignmentTemplates
.FirstOrDefault(t => t.Id == TemplateId);
private void handleChange(string newRawAssignment)
{
rawText = newRawAssignment;

View File

@@ -1,125 +0,0 @@
@using Management.Web.Shared.Components
@inject CoursePlanner planner
@code
{
private Modal modal { get; set; } = default!;
private string newTemplateName { get; set; } = "";
protected override void OnInitialized()
{
planner.StateHasChanged += reload;
}
private void reload()
{
this.InvokeAsync(this.StateHasChanged);
}
public void Dispose()
{
planner.StateHasChanged -= reload;
}
private string? _selectedTemplateId;
private string? selectedTemplateId
{
get { return _selectedTemplateId; }
set { _selectedTemplateId = value; }
}
private AssignmentTemplate? selectedTemplate =>
planner
.LocalCourse?
.Settings
.AssignmentTemplates
.FirstOrDefault(t => t.Id == selectedTemplateId);
private void newTemplate()
{
if (planner.LocalCourse != null)
{
var newOne = new AssignmentTemplate()
{
Id=Guid.NewGuid().ToString(),
Name=newTemplateName
};
planner.LocalCourse = planner.LocalCourse with
{
Settings = planner.LocalCourse.Settings with
{
AssignmentTemplates = planner.LocalCourse.Settings.AssignmentTemplates.Append(newOne)
}
};
newTemplateName = "";
}
}
}
<button
class="btn btn-outline-secondary"
@onclick="@(() => modal.Show())"
>
Manage Assignment Templates
</button>
@if(planner.LocalCourse != null)
{
<Modal @ref="modal">
<Title>
<h1>Assignment Templates</h1>
</Title>
<Body>
<div class="row justify-content-center">
<div class="col-auto">
<form @onsubmit:preventDefault="true">
<label for="termselect">Templates</label>
<select id="termselect" class="form-select" @bind="selectedTemplateId">
<option></option>
@foreach (var template in planner.LocalCourse.Settings.AssignmentTemplates)
{
<option value="@template.Id">@template.Name</option>
}
</select>
</form>
</div>
<div class="col-auto my-auto">
<form
@onsubmit:preventDefault="true"
@onsubmit="newTemplate"
>
<label
class="form-label"
for="newTemplateName"
>
New Template Name
</label>
<input
class="form-control"
type="text"
@bind="newTemplateName"
@bind:event="oninput"
/>
<button
class="btn btn-outline-primary"
>
New Template
</button>
</form>
</div>
</div>
@if(selectedTemplate != null)
{
<TemplateEditor Template="selectedTemplate" />
}
</Body>
<Footer>
<button
class="btn btn-outline-secondary"
@onclick="@(() => modal.Hide())"
>
Close
</button>
</Footer>
</Modal>
}

View File

@@ -1,96 +0,0 @@
@using Markdig
@inject CoursePlanner planner
@code
{
[Parameter, EditorRequired]
public AssignmentTemplate Template { get; set; } = default!;
protected override void OnInitialized()
{
base.OnInitialized();
}
public string Preview => Markdown.ToHtml(Template.Markdown);
private void SetName(string newName)
{
if(planner.LocalCourse != null)
{
var newTemplates = planner.LocalCourse.Settings.AssignmentTemplates.Select(t =>
t.Id == Template.Id
? t with { Name=newName }
: t
);
planner.LocalCourse = planner.LocalCourse with
{
Settings = planner.LocalCourse.Settings with
{
AssignmentTemplates=newTemplates
}
};
}
}
private void SetMarkdown(string newMarkdown)
{
if(planner.LocalCourse != null)
{
var newTemplates = planner.LocalCourse.Settings.AssignmentTemplates.Select(t =>
t.Id == Template.Id
? t with { Markdown=newMarkdown }
: t
);
planner.LocalCourse = planner.LocalCourse with
{
Settings = planner.LocalCourse.Settings with
{
AssignmentTemplates=newTemplates
}
};
}
}
}
<div class="row justify-content-center m-3">
<div class="col-6">
<input
class="form-control"
type="text"
value="@Template.Name"
@oninput="@((e) => {
var newValue = (string) (e.Value ?? "");
SetName(newValue);
})"
>
</div>
</div>
<div class="row">
<div class="col-6">
<textarea
rows="30"
class="form-control"
value="@Template.Markdown"
@oninput="@((e) => {
var newValue = (string) (e.Value ?? "");
SetMarkdown(newValue);
})"
/>
</div>
<div class="col-6">
@((MarkupString) Preview)
</div>
</div>
<br>
<h5 class="text-center">Detected Template Variables</h5>
<div class="row justify-content-center">
<div class="col-auto">
<ul>
@foreach (var variable in AssignmentTemplate.GetVariables(Template.Markdown))
{
<li>@variable</li>
}
</ul>
</div>
</div>

View File

@@ -0,0 +1,28 @@
namespace LocalModels;
public static class AssignmentSubmissionType
{
public static readonly string ONLINE_TEXT_ENTRY = "online_text_entry";
public static readonly string ONLINE_UPLOAD = "online_upload";
public static readonly string ONLINE_QUIZ = "online_quiz";
// public static readonly string ON_PAPER = "on_paper";
public static readonly string DISCUSSION_TOPIC = "discussion_topic";
// public static readonly string EXTERNAL_TOOL = "external_tool";
public static readonly string ONLINE_URL = "online_url";
// public static readonly string MEDIA_RECORDING = "media_recording";
// public static readonly string STUDENT_ANNOTATION = "student_annotation";
public static readonly string NONE = "none";
public static readonly IEnumerable<string> AllTypes = new string[]
{
ONLINE_TEXT_ENTRY,
ONLINE_UPLOAD,
ONLINE_QUIZ,
// ON_PAPER,
DISCUSSION_TOPIC,
// EXTERNAL_TOOL,
ONLINE_URL,
// MEDIA_RECORDING,
// STUDENT_ANNOTATION,
NONE,
};
}

View File

@@ -6,41 +6,6 @@ using YamlDotNet.Serialization;
namespace LocalModels;
public record RubricItem
{
public static readonly string extraCredit = "(Extra Credit) ";
public required string Label { get; set; }
public required int Points { get; set; }
public bool IsExtraCredit => Label.Contains(extraCredit.ToLower(), StringComparison.CurrentCultureIgnoreCase);
}
public static class AssignmentSubmissionType
{
public static readonly string ONLINE_TEXT_ENTRY = "online_text_entry";
public static readonly string ONLINE_UPLOAD = "online_upload";
public static readonly string ONLINE_QUIZ = "online_quiz";
// public static readonly string ON_PAPER = "on_paper";
public static readonly string DISCUSSION_TOPIC = "discussion_topic";
// public static readonly string EXTERNAL_TOOL = "external_tool";
public static readonly string ONLINE_URL = "online_url";
// public static readonly string MEDIA_RECORDING = "media_recording";
// public static readonly string STUDENT_ANNOTATION = "student_annotation";
public static readonly string NONE = "none";
public static readonly IEnumerable<string> AllTypes = new string[]
{
ONLINE_TEXT_ENTRY,
ONLINE_UPLOAD,
ONLINE_QUIZ,
// ON_PAPER,
DISCUSSION_TOPIC,
// EXTERNAL_TOOL,
ONLINE_URL,
// MEDIA_RECORDING,
// STUDENT_ANNOTATION,
NONE,
};
}
public record LocalAssignment
{
// public ulong? CanvasId { get; init; } = null;

View File

@@ -0,0 +1,9 @@
namespace LocalModels;
public record RubricItem
{
public static readonly string extraCredit = "(Extra Credit) ";
public required string Label { get; set; }
public required int Points { get; set; }
public bool IsExtraCredit => Label.Contains(extraCredit.ToLower(), StringComparison.CurrentCultureIgnoreCase);
}

View File

@@ -18,8 +18,6 @@ public record LocalCourseSettings
public DateTime StartDate { get; init; }
public DateTime EndDate { get; init; }
public SimpleTimeOnly DefaultDueTime { get; init; } = new SimpleTimeOnly();
public IEnumerable<AssignmentTemplate> AssignmentTemplates { get; init; } =
Enumerable.Empty<AssignmentTemplate>();
public string ToYaml()
{

View File

@@ -0,0 +1,17 @@
using Management.Services;
public class FileConfiguration
{
public static string GetBasePath()
{
string? storageDirectory = Environment.GetEnvironmentVariable("storageDirectory");
var basePath = storageDirectory ?? Path.GetFullPath("../storage");
if (!Directory.Exists(basePath))
throw new Exception("storage folder not found");
return basePath;
}
}

View File

@@ -5,14 +5,22 @@ using YamlDotNet.Serialization;
public class FileStorageManager
{
private readonly MyLogger<FileStorageManager> logger;
private static readonly string _basePath = "../storage";
private readonly CourseMarkdownLoader _courseMarkdownLoader;
private readonly string _basePath;
public FileStorageManager(MyLogger<FileStorageManager> logger)
public FileStorageManager(
MyLogger<FileStorageManager> logger,
CourseMarkdownLoader courseMarkdownLoader
)
{
if (!Directory.Exists(_basePath))
throw new Exception("storage folder not found");
this.logger = logger;
_courseMarkdownLoader = courseMarkdownLoader;
_basePath = FileConfiguration.GetBasePath();
logger.Log("Using storage directory: " + _basePath);
}
public string CourseToYaml(LocalCourse course)
{
var serializer = new SerializerBuilder().DisableAliases().Build();
@@ -131,6 +139,7 @@ public class FileStorageManager
}
removeOldAssignments(assignmentsDirectory, module);
}
private void removeOldAssignments(string path, LocalModule module)
{
var existingFiles = Directory.EnumerateFiles(path);
@@ -166,68 +175,9 @@ public class FileStorageManager
return courses;
}
// public async Task<LocalCourse> LoadCourseByName(string courseName)
// {
// var courseDirectory = $"{_basePath}/{courseName}";
// if (!Directory.Exists(courseDirectory))
// {
// var errorMessage = $"error loading course by name, could not find folder {courseDirectory}";
// logger.Log(errorMessage);
// throw new LoadCourseFromFileException(errorMessage);
// }
// var settingsPath = $"{courseDirectory}/settings.yml";
// if (!Directory.Exists(settingsPath))
// {
// var errorMessage = $"error loading course by name, settings file {settingsPath}";
// logger.Log(errorMessage);
// throw new LoadCourseFromFileException(errorMessage);
// }
// var settingsString = await File.ReadAllTextAsync(settingsPath);
// var settings = LocalCourseSettings.ParseYaml(settingsString);
// var modulePaths = Directory.GetDirectories(courseDirectory);
// var modules = modulePaths
// .Select(LoadModuleFromPath)
// .ToArray();
// }
// public async Task<LocalModule> LoadModuleFromPath(string modulePath)
// {
// var assignmentsPath = $"{modulePath}/assignments";
// if (!Directory.Exists(assignmentsPath))
// {
// var errorMessage = $"error loading course by name, assignments folder does not exist in {modulePath}";
// logger.Log(errorMessage);
// throw new LoadCourseFromFileException(errorMessage);
// }
// var quizzesPath = $"{modulePath}/quizzes";
// if (!Directory.Exists(quizzesPath))
// {
// var errorMessage = $"error loading course by name, quizzes folder does not exist in {modulePath}";
// logger.Log(errorMessage);
// throw new LoadCourseFromFileException(errorMessage);
// }
// var assignments = LoadAssignmentsFromPath(assignmentsPath);
// var quizzes = LoadQuizzesFromPath(quizzesPath);
// }
// public async Task<IEnumerable<LocalAssignment>> LoadAssignmentsFromPath(string assignmentsFolder)
// {
// }
// public async Task<IEnumerable<LocalAssignment>> LoadQuizzesFromPath(string quizzesFolder)
// {
// }
}
public class LoadCourseFromFileException(string message) : Exception(message)
public async Task<IEnumerable<LocalCourse>> LoadSavedMarkdownCourses()
{
return await _courseMarkdownLoader.LoadSavedMarkdownCourses();
}
}

View File

@@ -0,0 +1,3 @@
public class LoadCourseFromFileException(string message) : Exception(message)
{
}

View File

@@ -0,0 +1,127 @@
using System.Reflection.Metadata.Ecma335;
using LocalModels;
using Management.Services;
using YamlDotNet.Serialization;
public class CourseMarkdownLoader
{
private readonly MyLogger<CourseMarkdownLoader> logger;
private readonly string _basePath;
public CourseMarkdownLoader(MyLogger<CourseMarkdownLoader> logger)
{
this.logger = logger;
_basePath = FileConfiguration.GetBasePath();
}
public async Task<IEnumerable<LocalCourse>> LoadSavedMarkdownCourses()
{
var courseDirectories = Directory.GetDirectories(_basePath);
var courses = await Task.WhenAll(
courseDirectories.Select(async n => await LoadCourseByPath(n))
);
return courses;
}
public async Task<LocalCourse> LoadCourseByPath(string courseDirectory)
{
if (!Directory.Exists(courseDirectory))
{
var errorMessage = $"error loading course by name, could not find folder {courseDirectory}";
logger.Log(errorMessage);
throw new LoadCourseFromFileException(errorMessage);
}
LocalCourseSettings settings = await loadCourseSettings(courseDirectory);
var modules = await loadCourseModules(courseDirectory);
return new()
{
Settings = settings,
Modules = modules
};
}
private async Task<LocalCourseSettings> loadCourseSettings(string courseDirectory)
{
var settingsPath = $"{courseDirectory}/settings.yml";
if (!File.Exists(settingsPath))
{
var errorMessage = $"error loading course by name, settings file {settingsPath}";
logger.Log(errorMessage);
throw new LoadCourseFromFileException(errorMessage);
}
var settingsString = await File.ReadAllTextAsync(settingsPath);
var settings = LocalCourseSettings.ParseYaml(settingsString);
return settings;
}
private async Task<IEnumerable<LocalModule>> loadCourseModules(string courseDirectory)
{
var modulePaths = Directory.GetDirectories(courseDirectory);
var modules = await Task.WhenAll(
modulePaths
.Select(loadModuleFromPath)
);
return modules;
}
private async Task<LocalModule> loadModuleFromPath(string modulePath)
{
var moduleName = Path.GetFileName(modulePath);
var assignments = await loadAssignmentsFromPath(modulePath);
var quizzes = await loadQuizzesFromPath(modulePath);
return new LocalModule()
{
Name = moduleName,
Assignments = assignments,
Quizzes = quizzes,
};
}
private async Task<IEnumerable<LocalAssignment>> loadAssignmentsFromPath(string modulePath)
{
var assignmentsPath = $"{modulePath}/assignments";
if (!Directory.Exists(assignmentsPath))
{
var errorMessage = $"error loading course by name, assignments folder does not exist in {modulePath}";
logger.Log(errorMessage);
throw new LoadCourseFromFileException(errorMessage);
}
var assignmentFiles = Directory.GetFiles(assignmentsPath);
var assignmentPromises = assignmentFiles
.Select(async filePath =>
{
var rawFile = await File.ReadAllTextAsync(filePath);
return LocalAssignment.ParseMarkdown(rawFile);
})
.ToArray();
return await Task.WhenAll(assignmentPromises);
}
private async Task<IEnumerable<LocalQuiz>> loadQuizzesFromPath(string modulePath)
{
var quizzesPath = $"{modulePath}/quizzes";
if (!Directory.Exists(quizzesPath))
{
var errorMessage = $"error loading course by name, quizzes folder does not exist in {modulePath}";
logger.Log(errorMessage);
throw new LoadCourseFromFileException(errorMessage);
}
var quizFiles = Directory.GetFiles(quizzesPath);
var quizPromises = quizFiles
.Select(async path =>
{
var rawQuiz = await File.ReadAllTextAsync(path);
return LocalQuiz.ParseMarkdown(rawQuiz);
});
return await Task.WhenAll(quizPromises);
}
}