From 530613fca32df9e2aabc11d4c85a35c4830b01da Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Mon, 9 Jan 2023 20:02:22 -0700 Subject: [PATCH] can create config from semester --- .../Features/ConfigurationTests.cs | 24 +++++++++++++++++++ .../Features/Calendar/SemesterPlanner.cs | 2 -- .../Configuration/ConfigrationManagement.cs | 19 +++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Management.Test/Features/ConfigurationTests.cs create mode 100644 Management/Features/Configuration/ConfigrationManagement.cs diff --git a/Management.Test/Features/ConfigurationTests.cs b/Management.Test/Features/ConfigurationTests.cs new file mode 100644 index 0000000..4783429 --- /dev/null +++ b/Management.Test/Features/ConfigurationTests.cs @@ -0,0 +1,24 @@ +using CanvasModel.EnrollmentTerms; + +public class ConfigurationTests +{ + [Test] + public void TestCanCreateConfigFromTermAndDays() + { + + DateTime startAt = new DateTime(2022, 1, 1); + DateTime endAt = new DateTime(2022, 1, 2); + var canvasTerm = new EnrollmentTermModel( + Id: 1, + Name: "one", + StartAt: startAt, + EndAt: endAt + ); + var daysOfWeek = new DayOfWeek[] { DayOfWeek.Monday }; + + var config = ConfigurationManagement.CreateFromTerm(canvasTerm, daysOfWeek); + config.StartDate.Should().Be(startAt); + config.EndDate.Should().Be(endAt); + config.Days.Should().BeEquivalentTo(daysOfWeek); + } +} \ No newline at end of file diff --git a/Management/Features/Calendar/SemesterPlanner.cs b/Management/Features/Calendar/SemesterPlanner.cs index b390094..75d014f 100644 --- a/Management/Features/Calendar/SemesterPlanner.cs +++ b/Management/Features/Calendar/SemesterPlanner.cs @@ -5,8 +5,6 @@ public class SemesterPlanner public IEnumerable Months { get; } public SemesterPlanner(SemesterConfiguration configuration) { - // var start = configuration.StartAt ?? throw new Exception($"Canvas Term must have a start date. Term: {configuration.Id}"); - // var end = configuration.EndAt ?? throw new Exception($"Canvas Term must have a end date. Term: {configuration.Id}"); var start = configuration.StartDate; var end = configuration.EndDate; diff --git a/Management/Features/Configuration/ConfigrationManagement.cs b/Management/Features/Configuration/ConfigrationManagement.cs new file mode 100644 index 0000000..6fd1d3a --- /dev/null +++ b/Management/Features/Configuration/ConfigrationManagement.cs @@ -0,0 +1,19 @@ +using CanvasModel.EnrollmentTerms; + +public class ConfigurationManagement +{ + public static SemesterConfiguration CreateFromTerm( + EnrollmentTermModel canvasTerm, + DayOfWeek[] daysOfWeek + ) + { + var start = canvasTerm.StartAt ?? throw new Exception($"Canvas Term must have a start date. Term: {canvasTerm.Name}"); + var end = canvasTerm.EndAt ?? throw new Exception($"Canvas Term must have a end date. Term: {canvasTerm.Name}"); + + return new SemesterConfiguration( + StartDate: start, + EndDate: end, + Days: daysOfWeek + ); + } +} \ No newline at end of file