Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b42730c
HEEDLS-441 Add new action/views
AlexJacksonDS Sep 16, 2021
f175e66
HEEDLS-441 Make form able to post to complex model
AlexJacksonDS Sep 20, 2021
4ae0cdd
HEEDLS-441 Save tutorial statuses to database
AlexJacksonDS Sep 20, 2021
5df5e24
HEEDLS-441 Fix styling on checkboxes and layout issues
AlexJacksonDS Sep 20, 2021
bf0e531
HEEDLS-441 No javascript Select/Deselect buttons
AlexJacksonDS Sep 20, 2021
2587c9a
HEEDLS-441 Add javascript select all
AlexJacksonDS Sep 22, 2021
4e93f83
HEEDLS-441 Refactor screen to be only single section
AlexJacksonDS Sep 23, 2021
6967820
HEEDLS-441 Make the sets of checkboxes into columns for desktop
AlexJacksonDS Sep 23, 2021
f94aaa8
HEEDLS-441 Refactor form data classes and fix javascript
AlexJacksonDS Sep 24, 2021
8335017
HEEDLS-441 Lint fix unexpected Unicode BOM
AlexJacksonDS Sep 24, 2021
92f7bdf
HEEDLS-441 Add unit tests for new services and controller actions
AlexJacksonDS Sep 24, 2021
a0d7a9d
Merge branch 'master' into HEEDLS-441-edit-course-content
AlexJacksonDS Sep 24, 2021
bbf9e53
HEEDLS-441 Add final unit tests post merge
AlexJacksonDS Sep 24, 2021
54d75f3
HEEDLS-441 Change customisation used in tests
AlexJacksonDS Sep 24, 2021
d706c6a
HEEDLS-441 Break down a few long lines
AlexJacksonDS Sep 24, 2021
bbbcb56
HEEDLS-441 Review markups
AlexJacksonDS Sep 28, 2021
7dab11c
HEEDLS-441 Add new service to Startup
AlexJacksonDS Sep 28, 2021
54fea49
Merge branch 'master' into HEEDLS-441-edit-course-content
AlexJacksonDS Sep 28, 2021
2932f6a
Merge branch 'master' into HEEDLS-441-edit-course-content
AlexJacksonDS Oct 12, 2021
b5a73ac
HEEDLS-441 Review markups
AlexJacksonDS Oct 12, 2021
88b246e
HEEDLS-441 Further review markups
AlexJacksonDS Oct 12, 2021
0187d12
Merge branch 'master' into HEEDLS-441-edit-course-content
AlexJacksonDS Oct 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,66 @@ public void CreateNewAspProgressRecord_adds_new_record()
transaction.Dispose();
}
}

[Test]
public void InsertNewAspProgressRecordsForTutorialIfNoneExist_inserts_new_records()
{
// Given
const int tutorialId = 12732;
const int customisationId = 14019;

using var transaction = new TransactionScope();
try
{
// When
var initialProgressIdsOnAspProgressRecords = tutorialContentTestHelper
.GetDistinctProgressIdsOnAspProgressRecordsFromTutorialId(tutorialId).ToList();
progressDataService.InsertNewAspProgressRecordsForTutorialIfNoneExist(tutorialId, customisationId);
var resultProgressIdsOnAspProgressRecords = tutorialContentTestHelper
.GetDistinctProgressIdsOnAspProgressRecordsFromTutorialId(tutorialId).ToList();

// Then
using (new AssertionScope())
{
initialProgressIdsOnAspProgressRecords.Count.Should().Be(3);
resultProgressIdsOnAspProgressRecords.Count.Should().Be(6);
}
}
finally
{
transaction.Dispose();
}
}

[Test]
public void
InsertNewAspProgressRecordsForTutorialIfNoneExist_does_not_insert_new_records_when_they_already_exist()
{
// Given
const int tutorialId = 12925;
const int customisationId = 27816;

using var transaction = new TransactionScope();
try
{
// When
var initialAspProgressIds = tutorialContentTestHelper
.GetAspProgressFromTutorialId(tutorialId).ToList();
progressDataService.InsertNewAspProgressRecordsForTutorialIfNoneExist(tutorialId, customisationId);
var resultAspProgressIds = tutorialContentTestHelper
.GetAspProgressFromTutorialId(tutorialId).ToList();

// Then
using (new AssertionScope())
{
initialAspProgressIds.Count.Should()
.Be(resultAspProgressIds.Count);
}
}
finally
{
transaction.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1359,5 +1359,20 @@ public void GetSectionsByApplication_should_have_correct_results()
result.First().Tutorials.Should().BeEmpty();
}
}

[Test]
public void GetSectionById_returns_expected_section()
{
// Given
const int sectionId = 1;
const string expectedName = "Mouse skills";

// When
var result = sectionContentDataService.GetSectionById(sectionId);

// Then
result?.SectionId.Should().Be(sectionId);
result?.SectionName.Should().Be(expectedName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;

internal partial class TutorialContentDataServiceTests
{
private const int CustomisationId = 1379;
private const int SectionId = 74;

[Test]
public void GetTutorialsBySectionId_returns_tutorials_correctly()
{
// Given
const int customisationId = 1379;
const int sectionId = 74;

// When
var result = tutorialContentDataService.GetTutorialsBySectionId(sectionId, customisationId).ToList();
var result = tutorialContentDataService.GetTutorialsBySectionId(SectionId, CustomisationId).ToList();

// Then
using (new AssertionScope())
Expand All @@ -42,5 +42,76 @@ public void GetTutorialIdsByCourse_returns_correct_tutorials()
// Then
result.Should().BeEquivalentTo(expectedTutorials);
}

[Test]
public void
UpdateOrInsertCustomisationTutorialStatuses_updates_both_statuses_on_existing_CustomisationTutorial()
{
// When
using var transaction = new TransactionScope();
try
{
tutorialContentDataService.UpdateOrInsertCustomisationTutorialStatuses(
49,
CustomisationId,
false,
false
);
var result = tutorialContentDataService.GetTutorialsBySectionId(SectionId, CustomisationId).ToList();

using (new AssertionScope())
{
result.First().TutorialId.Should().Be(49);
result.First().TutorialName.Should().Be("View documents");
result.First().Status.Should().BeFalse();
result.First().DiagStatus.Should().BeFalse();
}
}
finally
{
transaction.Dispose();
}
}

[Test]
public void UpdateOrInsertCustomisationTutorialStatuses_inserts_new_CustomisationTutorial_when_one_does_not_exist()
{
// Given
const int tutorialId = 12732;
const int customisationId = 14019;

// When
using var transaction = new TransactionScope();
try
{
var initialResult =
tutorialContentTestHelper.GetCustomisationTutorialByTutorialIdAndCustomisationId(
tutorialId,
customisationId
);
tutorialContentDataService.UpdateOrInsertCustomisationTutorialStatuses(
tutorialId,
customisationId,
true,
true
);
var result = tutorialContentTestHelper.GetCustomisationTutorialByTutorialIdAndCustomisationId(
tutorialId,
customisationId
);

using (new AssertionScope())
{
initialResult.Should().BeNull();
result.Should().NotBeNull();
result?.Status.Should().BeTrue();
result?.DiagStatus.Should().BeTrue();
}
}
finally
{
transaction.Dispose();
}
}
}
}
106 changes: 106 additions & 0 deletions DigitalLearningSolutions.Data.Tests/Services/SectionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace DigitalLearningSolutions.Data.Tests.Services
{
using System.Collections.Generic;
using System.Linq;
using DigitalLearningSolutions.Data.DataServices;
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Services;
using FakeItEasy;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;

public class SectionServiceTests
{
private ISectionContentDataService sectionContentDataService = null!;
private ISectionService sectionService = null!;
private ITutorialContentDataService tutorialContentDataService = null!;

[SetUp]
public void Setup()
{
sectionContentDataService = A.Fake<ISectionContentDataService>();
tutorialContentDataService = A.Fake<ITutorialContentDataService>();

sectionService = new SectionService(
sectionContentDataService,
tutorialContentDataService
);
}

[Test]
public void GetSectionsAndTutorialsForCustomisation_returns_fully_populated_list()
{
// Given
var tutorialOne = new Tutorial(1, "Test", true, true);
var tutorialTwo = new Tutorial(2, "Case", false, false);
var tutorials = new List<Tutorial> { tutorialOne, tutorialTwo };
var sectionOne = new Section(1, "Section");
var sectionTwo = new Section(2, "Second Section");
A.CallTo(() => sectionContentDataService.GetSectionsByApplicationId(1))
.Returns(new List<Section> { sectionOne, sectionTwo });
A.CallTo(() => tutorialContentDataService.GetTutorialsBySectionId(A<int>._, 1))
.Returns(tutorials);

// When
var result = sectionService.GetSectionsAndTutorialsForCustomisation(1, 1).ToList();

// Then
using (new AssertionScope())
{
A.CallTo(() => tutorialContentDataService.GetTutorialsBySectionId(A<int>._, 1))
.MustHaveHappenedTwiceExactly();
result.Count.Should().Be(2);
result.First().SectionId.Should().Be(1);
result.First().SectionName.Should().Be("Section");
result.First().Tutorials.Should().BeEquivalentTo(tutorials);
}
}

[Test]
public void GetSectionAndTutorialsBySectionIdForCustomisation_returns_fully_populated_Section()
{
// Given
var tutorialOne = new Tutorial(1, "Test", true, true);
var tutorialTwo = new Tutorial(2, "Case", false, false);
var tutorials = new List<Tutorial> { tutorialOne, tutorialTwo };
var section = new Section(1, "Section");
A.CallTo(() => sectionContentDataService.GetSectionById(1))
.Returns(section);
A.CallTo(() => tutorialContentDataService.GetTutorialsBySectionId(A<int>._, 1))
.Returns(tutorials);

// When
var result = sectionService.GetSectionAndTutorialsBySectionIdForCustomisation(1, 1);

// Then
using (new AssertionScope())
{
A.CallTo(() => tutorialContentDataService.GetTutorialsBySectionId(A<int>._, 1))
.MustHaveHappenedOnceExactly();
result?.SectionId.Should().Be(1);
result?.SectionName.Should().Be("Section");
result?.Tutorials.Should().BeEquivalentTo(tutorials);
}
}

[Test]
public void GetSectionAndTutorialsBySectionIdForCustomisation_returns_null_if_section_not_found()
{
// Given
A.CallTo(() => sectionContentDataService.GetSectionById(1))
.Returns(null);

// When
var result = sectionService.GetSectionAndTutorialsBySectionIdForCustomisation(1, 1);

// Then
using (new AssertionScope())
{
result.Should().BeNull();
A.CallTo(() => tutorialContentDataService.GetTutorialsBySectionId(A<int>._, 1))
.MustNotHaveHappened();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace DigitalLearningSolutions.Data.Tests.Services
{
using System.Collections.Generic;
using DigitalLearningSolutions.Data.DataServices;
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Services;
using FakeItEasy;
using FluentAssertions.Execution;
using NUnit.Framework;

public class TutorialServiceTests
{
private IProgressDataService progressDataService = null!;
private ITutorialContentDataService tutorialContentDataService = null!;
private ITutorialService tutorialService = null!;

[SetUp]
public void Setup()
{
progressDataService = A.Fake<IProgressDataService>();
tutorialContentDataService = A.Fake<ITutorialContentDataService>();

tutorialService = new TutorialService(
tutorialContentDataService,
progressDataService
);
}

[Test]
public void UpdateTutorialsStatuses_calls_data_services_correct_number_of_times()
{
// Given
var tutorialOne = new Tutorial(1, "Test", true, true);
var tutorialTwo = new Tutorial(2, "Case", false, false);
var tutorials = new List<Tutorial> { tutorialOne, tutorialTwo };
A.CallTo(
() => tutorialContentDataService.UpdateOrInsertCustomisationTutorialStatuses(
A<int>._,
A<int>._,
A<bool>._,
A<bool>._
)
)
.DoesNothing();
A.CallTo(() => progressDataService.InsertNewAspProgressRecordsForTutorialIfNoneExist(A<int>._, A<int>._))
.DoesNothing();

// When
tutorialService.UpdateTutorialsStatuses(tutorials, 1);

// Then
using (new AssertionScope())
{
A.CallTo(
() => tutorialContentDataService.UpdateOrInsertCustomisationTutorialStatuses(
A<int>._,
A<int>._,
A<bool>._,
A<bool>._
)
)
.MustHaveHappened(2, Times.Exactly);
A.CallTo(() => progressDataService.InsertNewAspProgressRecordsForTutorialIfNoneExist(A<int>._, A<int>._))
.MustHaveHappened(2, Times.Exactly);
}
}
}
}
Loading