public void UpdateLearningLogItemLastAccessedDate_should_set_date_correctly() { // Given var addedDate = new DateTime(2021, 11, 1); var updatedDate = new DateTime(2021, 11, 1); using (new TransactionScope()) { var itemId = InsertLearningLogItem( GenericDelegateId, addedDate, GenericLearningResourceReferenceId ); // When service.UpdateLearningLogItemLastAccessedDate(itemId, updatedDate); var result = service.GetLearningLogItem(itemId); // Then using (new AssertionScope()) { result.Should().NotBeNull(); result !.LastAccessedDate.Should().Be(updatedDate); } } }
public async Task <string?> GetLearningResourceLinkAndUpdateLastAccessedDate( int learningLogItemId, int delegateId ) { var actionPlanResource = learningLogItemsDataService.GetLearningLogItem(learningLogItemId) !; learningLogItemsDataService.UpdateLearningLogItemLastAccessedDate(learningLogItemId, clockService.UtcNow); var resource = await learningHubApiClient.GetResourceByReferenceId( actionPlanResource.LearningHubResourceReferenceId !.Value ); return(resource.Link); }
public async Task GetLearningResourceLinkAndUpdateLastAccessedDate_updates_last_accessed_returns_resource_link() { // Given var testDate = new DateTime(2021, 12, 2); A.CallTo(() => clockService.UtcNow).Returns(testDate); const int learningLogItemId = 1; const int delegateId = 2; const int resourceReferenceId = 3; const string resourceLink = "www.test.com"; var learningLogItems = Builder <LearningLogItem> .CreateNew() .With(i => i.CompletedDate = null) .And(i => i.ArchivedDate = null) .And(i => i.LearningHubResourceReferenceId = resourceReferenceId) .And(i => i.LearningLogItemId = learningLogItemId) .Build(); A.CallTo(() => learningLogItemsDataService.GetLearningLogItem(learningLogItemId)) .Returns(learningLogItems); var matchedResource = Builder <ResourceReferenceWithResourceDetails> .CreateNew() .With(r => r.RefId = resourceReferenceId) .And(r => r.Title = "Title") .And(r => r.Catalogue = genericCatalogue) .And(r => r.Link = resourceLink).Build(); A.CallTo(() => learningHubApiClient.GetResourceByReferenceId(resourceReferenceId)) .Returns(matchedResource); // When var result = await actionPlanService.GetLearningResourceLinkAndUpdateLastAccessedDate(learningLogItemId, delegateId); // Then result.Should().Be(resourceLink); A.CallTo(() => learningLogItemsDataService.GetLearningLogItem(learningLogItemId)) .MustHaveHappenedOnceExactly(); A.CallTo( () => learningLogItemsDataService.UpdateLearningLogItemLastAccessedDate(learningLogItemId, testDate) ) .MustHaveHappenedOnceExactly(); A.CallTo(() => learningHubApiClient.GetResourceByReferenceId(resourceReferenceId)) .MustHaveHappenedOnceExactly(); }
UpdateActionPlanResourcesLastAccessedDateIfPresent_updates_last_accessed_date_of_appropriate_records() { // Given var testDate = new DateTime(2021, 12, 2); A.CallTo(() => clockService.UtcNow).Returns(testDate); const int delegateId = 2; const int resourceReferenceId = 3; var expectedLearningLogItemIdsToUpdate = new[] { 1, 4 }; var learningLogItems = Builder <LearningLogItem> .CreateListOfSize(4).All() .With(i => i.CompletedDate = null) .And(i => i.ArchivedDate = null) .And(i => i.LearningHubResourceReferenceId = resourceReferenceId) .And((i, index) => i.LearningLogItemId = index + 1) .TheFirst(1).With(i => i.CompletedDate = DateTime.UtcNow) .TheNext(1).With(i => i.ArchivedDate = DateTime.UtcNow) .TheNext(1).With(i => i.LearningHubResourceReferenceId = resourceReferenceId + 100) .Build(); A.CallTo(() => learningLogItemsDataService.GetLearningLogItems(delegateId)) .Returns(learningLogItems); // When actionPlanService.UpdateActionPlanResourcesLastAccessedDateIfPresent(resourceReferenceId, delegateId); // Then A.CallTo(() => learningLogItemsDataService.GetLearningLogItems(delegateId)) .MustHaveHappenedOnceExactly(); foreach (var id in expectedLearningLogItemIdsToUpdate) { A.CallTo( () => learningLogItemsDataService.UpdateLearningLogItemLastAccessedDate(id, testDate) ) .MustHaveHappenedOnceExactly(); } }