Example #1
0
        public async Task Then_Returns_All_Distinct_Course_Names_For_Provider(
            GetApprenticeshipsFilterValuesQuery query,
            List <CommitmentsV2.Models.Apprenticeship> apprenticeships,
            [Frozen] Mock <ICacheStorageService> cacheStorageService,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            GetApprenticeshipsFilterValuesQueryHandler handler)
        {
            query.EmployerAccountId = null;

            SetupEmptyCache(query, cacheStorageService);
            SetProviderIdOnApprenticeship(apprenticeships, query.ProviderId);

            apprenticeships[2].CourseName = apprenticeships[1].CourseName;

            var expectedCourseNames = new[]
            { apprenticeships[0].CourseName, apprenticeships[1].CourseName };

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);

            var result = await handler.Handle(query, CancellationToken.None);

            result.CourseNames.Should().BeEquivalentTo(expectedCourseNames);
        }
Example #2
0
        public async Task Then_Returns_Ordered_LegalEntityNames(
            GetApprenticeshipsFilterValuesQuery query,
            List <Apprenticeship> apprenticeships,
            [Frozen] Mock <ICacheStorageService> cacheStorageService,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            GetApprenticeshipsFilterValuesQueryHandler handler)
        {
            query.EmployerAccountId = null;
            SetupEmptyCache(query, cacheStorageService);
            SetProviderIdOnApprenticeship(apprenticeships, query.ProviderId ?? 0);

            apprenticeships[0].Cohort.AccountLegalEntity = CreateAccountLegalEntity("B");
            apprenticeships[1].Cohort.AccountLegalEntity = CreateAccountLegalEntity("C");
            apprenticeships[2].Cohort.AccountLegalEntity = CreateAccountLegalEntity("A");

            var expectedEmployerNames = new[]
            {
                "A",
                "B",
                "C"
            };

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);

            var result = await handler.Handle(query, CancellationToken.None);

            result.EmployerNames.Should().BeEquivalentTo(expectedEmployerNames);
        }
Example #3
0
        public async Task Then_Checks_The_Caches_For_That_Employers_Filter_Values_And_Returns_If_Exists(
            GetApprenticeshipsFilterValuesQuery query,
            List <CommitmentsV2.Models.Apprenticeship> apprenticeships,
            GetApprenticeshipsFilterValuesQueryResult queryResult,
            [Frozen] Mock <ICacheStorageService> cacheStorageService,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            GetApprenticeshipsFilterValuesQueryHandler handler)
        {
            query.ProviderId = null;

            //Arrange
            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);
            cacheStorageService
            .Setup(x => x.RetrieveFromCache <GetApprenticeshipsFilterValuesQueryResult>(
                       $"{nameof(GetApprenticeshipsFilterValuesQueryResult)}-{query.EmployerAccountId}"))
            .ReturnsAsync(queryResult);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            mockContext.Verify(x => x.Apprenticeships, Times.Never);
            actual.Should().BeEquivalentTo(queryResult);
        }
Example #4
0
        public async Task Then_Returns_Ordered_PlannedEndDates(
            GetApprenticeshipsFilterValuesQuery query,
            List <CommitmentsV2.Models.Apprenticeship> apprenticeships,
            [Frozen] Mock <ICacheStorageService> cacheStorageService,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            GetApprenticeshipsFilterValuesQueryHandler handler)
        {
            SetupEmptyCache(query, cacheStorageService);
            SetProviderIdOnApprenticeship(apprenticeships, query.ProviderId ?? 0);

            var now = DateTime.UtcNow;

            apprenticeships[0].EndDate = now.AddMonths(-1);
            apprenticeships[1].EndDate = now.AddMonths(-2);
            apprenticeships[2].EndDate = now;

            var expectedEndDates = new[]
            {
                apprenticeships[2].EndDate,
                apprenticeships[0].EndDate,
                apprenticeships[1].EndDate
            };

            mockContext.Setup(context => context.Apprenticeships).ReturnsDbSet(apprenticeships);

            var result = await handler.Handle(query, CancellationToken.None);

            result.EndDates.Should().BeEquivalentTo(expectedEndDates);
        }
Example #5
0
        public async Task Then_Adds_Result_To_Cache_For_One_Minute_For_Employer(
            GetApprenticeshipsFilterValuesQuery query,
            List <CommitmentsV2.Models.Apprenticeship> apprenticeships,
            [Frozen] Mock <ICacheStorageService> cacheStorageService,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            GetApprenticeshipsFilterValuesQueryHandler handler)
        {
            query.ProviderId = null;

            //Arrange
            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);
            SetupEmptyCache(query, cacheStorageService);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            cacheStorageService.Verify(x => x.SaveToCache($"{nameof(GetApprenticeshipsFilterValuesQueryResult)}-{query.EmployerAccountId}", actual, 1), Times.Once);
        }