Exemplo n.º 1
0
        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();
        }