This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/69-homepage
- Loading branch information
Showing
17 changed files
with
421 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
Epsilon.Canvas.Tests/CanvasModuleCollectionFetcherTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using Epsilon.Abstractions.Model; | ||
using Epsilon.Canvas.Abstractions.Model; | ||
using Epsilon.Canvas.Abstractions.Service; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using System.Text.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Epsilon.Canvas.Abstractions; | ||
|
||
namespace Epsilon.Canvas.Tests | ||
{ | ||
public class CanvasModuleCollectionFetcherTests | ||
{ | ||
[Fact] | ||
public async Task GivenAllowedModulesAndCourseId_WhenModuleAndOutcomeServiceAreMocked_ThenReturnsExpectedModuleOutcomeResultCollection() | ||
{ | ||
// Arrange | ||
var courseId = 123; | ||
var allowedModules = new[] { "Module 1", "Module 3" }; | ||
var outcomeServiceMock = new Mock<IOutcomeHttpService>(); | ||
var moduleServiceMock = new Mock<IModuleHttpService>(); | ||
|
||
var expectedResults = new List<ModuleOutcomeResultCollection> | ||
{ | ||
new ModuleOutcomeResultCollection( | ||
new Module(1, "Module 1", 3, new List<ModuleItem> | ||
{ | ||
new ModuleItem(1, "Module 1 Item 1", ModuleItemType.Page, 1), | ||
new ModuleItem(2, "Module 1 Item 2", ModuleItemType.Assignment, 2), | ||
new ModuleItem(3, "Module 1 Item 3", ModuleItemType.Quiz, 3) | ||
}), | ||
new OutcomeResultCollection( | ||
new List<OutcomeResult> { }, | ||
new OutcomeResultCollectionLink( | ||
new List<Outcome> | ||
{ | ||
new Outcome(1, "Outcome 1", "Outcome 1 EN Short Description NL Long Description"), | ||
new Outcome(2, "Outcome 2", "Outcome 2 EN Short Description NL Long Description") | ||
}, | ||
new List<Alignment> { } | ||
) | ||
) | ||
), | ||
new ModuleOutcomeResultCollection( | ||
new Module(3, "Module 3", 2, new List<ModuleItem> | ||
{ | ||
new ModuleItem(4, "Module 3 Item 1", ModuleItemType.Assignment, 4), | ||
new ModuleItem(5, "Module 3 Item 2", ModuleItemType.Assignment, 5) | ||
}), | ||
new OutcomeResultCollection( | ||
new List<OutcomeResult> { }, | ||
new OutcomeResultCollectionLink( | ||
new List<Outcome> | ||
{ | ||
new Outcome(1, "Outcome 1", "Outcome 1 EN Short Description NL Long Description"), | ||
new Outcome(2, "Outcome 2", "Outcome 2 EN Short Description NL Long Description") | ||
}, | ||
new List<Alignment> { } | ||
) | ||
) | ||
) | ||
}; | ||
|
||
outcomeServiceMock | ||
.Setup(s => s.GetResults(It.IsAny<int>(), It.IsAny<string[]>())) | ||
.ReturnsAsync(new OutcomeResultCollection( | ||
new List<OutcomeResult> | ||
{ | ||
new OutcomeResult(false, 3, new OutcomeResultLink("user1", "1", "1", "2")), | ||
new OutcomeResult(true, 4.5, new OutcomeResultLink("user2", "2", "2", "3")), | ||
new OutcomeResult(false, null, new OutcomeResultLink("user1", "1", "1", "3")), | ||
}, | ||
new OutcomeResultCollectionLink( | ||
new List<Outcome> | ||
{ | ||
new Outcome(1, "Outcome 1", "Outcome 1 EN Short Description NL Long Description"), | ||
new Outcome(2, "Outcome 2", "Outcome 2 EN Short Description NL Long Description"), | ||
}, | ||
new List<Alignment> | ||
{ | ||
new Alignment("1", "Alignment 1", new Uri("https://alignment1.com")), | ||
new Alignment("2", "Alignment 2", new Uri("https://alignment2.com")), | ||
new Alignment("3", "Alignment 3", new Uri("https://alignment3.com")), | ||
} | ||
) | ||
)); | ||
|
||
moduleServiceMock | ||
.Setup(s => s.GetAll(It.IsAny<int>(), It.IsAny<string[]>())) | ||
.ReturnsAsync(new List<Module> | ||
{ | ||
new Module(1, "Module 1", 3, new List<ModuleItem> | ||
{ | ||
new ModuleItem(1, "Module 1 Item 1", ModuleItemType.Page, 1), | ||
new ModuleItem(2, "Module 1 Item 2", ModuleItemType.Assignment, 2), | ||
new ModuleItem(3, "Module 1 Item 3", ModuleItemType.Quiz, 3) | ||
}), | ||
new Module(2, "Module 2", 0, new List<ModuleItem>()), | ||
new Module(3, "Module 3", 2, new List<ModuleItem> | ||
{ | ||
new ModuleItem(4, "Module 3 Item 1", ModuleItemType.Assignment, 4), | ||
new ModuleItem(5, "Module 3 Item 2", ModuleItemType.Assignment, 5) | ||
}), | ||
}); | ||
|
||
var canvasModuleCollectionFetcher = new CanvasModuleCollectionFetcher( | ||
Mock.Of<ILogger<CanvasModuleCollectionFetcher>>(), moduleServiceMock.Object, outcomeServiceMock.Object | ||
); | ||
|
||
// Act | ||
var result = new List<ModuleOutcomeResultCollection>(); | ||
await foreach (var item in canvasModuleCollectionFetcher.GetAll(courseId, allowedModules)) | ||
{ | ||
result.Add(item); | ||
} | ||
|
||
// Assert | ||
Assert.Equal(JsonSerializer.Serialize(expectedResults), JsonSerializer.Serialize(result)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Epsilon.Canvas.Tests/Services/AssignmentHttpServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Epsilon.Abstractions.Http; | ||
using Epsilon.Canvas.Abstractions.Model; | ||
using Epsilon.Canvas.Abstractions.Service; | ||
using Moq; | ||
using Moq.Protected; | ||
using Xunit; | ||
|
||
namespace Epsilon.Canvas.Service.Tests | ||
{ | ||
public class AssignmentHttpServiceTests | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly Mock<IPaginatorHttpService> _paginatorHttpServiceMock; | ||
private readonly AssignmentHttpService _assignmentHttpService; | ||
|
||
public AssignmentHttpServiceTests() | ||
{ | ||
_httpClient = new HttpClient(); | ||
_paginatorHttpServiceMock = new Mock<IPaginatorHttpService>(); | ||
_assignmentHttpService = new AssignmentHttpService(_httpClient, _paginatorHttpServiceMock.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenCourseIdAndIncludeSubmissionAndRubricAssessment_WhenCanvasAssignmentsAreRetrieved_ThenAssignmentsAreReturned() | ||
{ | ||
// Arrange | ||
var courseId = 123; | ||
var include = new[] { "submission", "rubric_assessment" }; | ||
var assignments = new[] | ||
{ | ||
new Assignment(1, "Assignment 1", new("https://example.com/1"), null), | ||
new Assignment(2, "Assignment 2", new("https://example.com/2"), new Submission(null, null, null, null)), | ||
new Assignment(3, "Assignment 3", new("https://example.com/3"), new Submission(null, null, new RubricAssessment(8.5, 1, Enumerable.Empty<RubricRating>()), null)), | ||
}; | ||
_paginatorHttpServiceMock.Setup(x => x.GetAllPages<IEnumerable<Assignment>>(HttpMethod.Get, $"v1/courses/{courseId}/assignments?include[]=submission&include[]=rubric_assessment")) | ||
.ReturnsAsync(new[] { assignments }); | ||
|
||
// Act | ||
var result = await _assignmentHttpService.GetAll(courseId, include); | ||
|
||
// Assert | ||
Assert.Equal(assignments, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="Moq" Version="4.18.4" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Epsilon.Abstractions\Epsilon.Abstractions.csproj" /> | ||
<ProjectReference Include="..\Epsilon\Epsilon.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Epsilon.Abstractions.Model; | ||
using Epsilon.Canvas.Abstractions.Model; | ||
using Epsilon.Export; | ||
using Moq; | ||
using System.Text.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Epsilon.Tests | ||
{ | ||
public class ExportDataPackagerTests | ||
{ | ||
[Fact] | ||
public async Task GivenListOfModuleOutcomeResultCollection_WhenRequiringOpenLearningOutcomeStructure_ThenOutcomeStructureShouldBeTransformed() | ||
{ | ||
// Arrange | ||
var module = new Module(1, "Module 1", 3, new List<ModuleItem> | ||
{ | ||
new ModuleItem(1, "Module 1 Item 1", ModuleItemType.Page, 1), | ||
new ModuleItem(2, "Module 1 Item 2", ModuleItemType.Assignment, 2), | ||
new ModuleItem(3, "Module 1 Item 3", ModuleItemType.Quiz, 3) | ||
}); | ||
|
||
var outcomes = new List<Outcome> | ||
{ | ||
new Outcome(1, "Outcome 1", "Outcome 1 EN Short Description NL Long Description"), | ||
new Outcome(2, "Outcome 2", "Outcome 2 EN Short Description NL Long Description"), | ||
}; | ||
|
||
var alignments = new List<Alignment> | ||
{ | ||
new Alignment("1", "Alignment 1", new Uri("https://alignment1.com")), | ||
new Alignment("2", "Alignment 2", new Uri("https://alignment2.com")), | ||
}; | ||
|
||
var outcomeResults = new List<OutcomeResult> | ||
{ | ||
new OutcomeResult(false, 3, new OutcomeResultLink("user1", "1", "1", "2")), | ||
new OutcomeResult(true, 4.5, new OutcomeResultLink("user2", "2", "2", "3")), | ||
new OutcomeResult(false, null, new OutcomeResultLink("user1", "1", "1", "3")), | ||
}; | ||
|
||
var links = new OutcomeResultCollectionLink(outcomes, alignments); | ||
|
||
var collection = new OutcomeResultCollection(outcomeResults, links); | ||
|
||
var moduleOutcomeResultCollection = new ModuleOutcomeResultCollection(module, collection); | ||
|
||
var data = new List<ModuleOutcomeResultCollection> | ||
{ | ||
moduleOutcomeResultCollection | ||
}.ToAsyncEnumerable(); | ||
|
||
var expectedData = new ExportData | ||
{ | ||
CourseModules = new List<CourseModule> | ||
{ | ||
new CourseModule | ||
{ | ||
Name = "Module 1", | ||
Outcomes = new List<CourseOutcome> | ||
{ | ||
new CourseOutcome | ||
{ | ||
Name = "Outcome 1", | ||
Description = "Short Description", | ||
Assignments = new List<CourseAssignment> | ||
{ | ||
new CourseAssignment | ||
{ | ||
Name = "Alignment 2", | ||
Url = "https://alignment2.com/", | ||
Score = "Satisfactory" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var exportDataPackager = new ExportDataPackager(); | ||
|
||
// Act | ||
var result = await exportDataPackager.GetExportData(data); | ||
|
||
// Assert | ||
Assert.Equal(JsonSerializer.Serialize(expectedData), JsonSerializer.Serialize(result)); | ||
} | ||
} | ||
} |
Oops, something went wrong.