public async Task Then_Returns_Employer_Apprenticeships(
            ApprenticeshipSearchParameters searchParameters,
            List <Apprenticeship> apprenticeships,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            ApprenticeshipSearchService service)
        {
            searchParameters.PageNumber    = 1;
            searchParameters.PageItemCount = 10;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();
            searchParameters.ProviderId    = null;

            apprenticeships[0].Cohort.EmployerAccountId = searchParameters.EmployerAccountId.Value;
            apprenticeships[1].Cohort.EmployerAccountId = searchParameters.EmployerAccountId.Value;

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

            var expectedApprenticeships =
                apprenticeships.Where(app => app.Cohort.EmployerAccountId == searchParameters.EmployerAccountId);

            var result = await service.Find(searchParameters);

            result.Apprenticeships.Count()
            .Should().Be(apprenticeships
                         .Count(apprenticeship => apprenticeship.Cohort.EmployerAccountId == searchParameters.EmployerAccountId));

            result.Apprenticeships.Should().BeEquivalentTo(expectedApprenticeships);
        }
        public async Task Then_Will_Return_Page_Number_If_All_Apprenticeships_Are_With_Alerts(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.ReverseSort   = false;
            searchParameters.PageNumber    = 2;
            searchParameters.PageItemCount = 2;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            searchParameters.ProviderId = null;

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual(searchParameters.PageNumber, actual.PageNumber);
            Assert.IsNotEmpty(actual.Apprenticeships);
        }
        public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Employer_When_Getting_All_Results(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 0;
            searchParameters.PageItemCount = 2;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            apprenticeships[0].Cohort.EmployerAccountId = 0;
            apprenticeships[0].EmployerRef = null;
            searchParameters.ProviderId    = null;

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual(5, actual.TotalAvailableApprenticeships);
        }
        public async Task Then_Apprentices_Are_Return_Per_Page(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 2;
            searchParameters.PageItemCount = 2;
            searchParameters.ReverseSort   = false;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual(2, actual.Apprenticeships.Count());
            Assert.AreEqual("C", actual.Apprenticeships.ElementAt(0).FirstName);
            Assert.AreEqual("D", actual.Apprenticeships.ElementAt(1).FirstName);
        }
コード例 #5
0
        public async Task Then_Will_Not_Search_For_Apprenticeships_That_Will_Be_Skipped(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IMapper <Apprenticeship, GetApprenticeshipsQueryResult.ApprenticeshipDetails> > mockMapper,
            ApprenticeshipSearchService service)
        {
            searchParameters.PageNumber    = 2;
            searchParameters.PageItemCount = 3;
            searchParameters.ReverseSort   = false;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            AssignProviderToApprenticeships(searchParameters.ProviderId ?? 0, apprenticeships);

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

            await service.Find(searchParameters);

            mockContext.Verify(context => context.Apprenticeships, Times.Exactly(4));

            mockMapper.Verify(x => x.Map(It.Is <Apprenticeship>(app => app.DataLockStatus.Any())), Times.Never);
        }
        public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_for_Default_Search(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber        = 0;
            searchParameters.ReverseSort       = false;
            searchParameters.Filters           = new ApprenticeshipSearchFilters();
            searchParameters.CancellationToken = CancellationToken.None;
            searchParameters.EmployerAccountId = null;


            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            apprenticeships[1].ProviderRef = null;
            apprenticeships[1].EndDate     = DateTime.UtcNow.AddMonths(-13);;

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual(apprenticeships.Count - 1, actual.Apprenticeships.Count());
            Assert.IsFalse(actual.Apprenticeships.Contains(apprenticeships[1]));
        }
        public async Task Then_Returns_Apprenticeships_Total_Found(
            ApprenticeshipSearchParameters searchParameters,
            List <Apprenticeship> apprenticeships,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            ApprenticeshipSearchService service)
        {
            searchParameters.PageNumber    = 1;
            searchParameters.PageItemCount = 10;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            apprenticeships[0].Cohort.ProviderId = searchParameters.ProviderId ?? 0;
            apprenticeships[1].Cohort.ProviderId = searchParameters.ProviderId ?? 0;
            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);

            var result = await service.Find(searchParameters);

            result.TotalApprenticeshipsFound
            .Should().Be(apprenticeships
                         .Count(apprenticeship => apprenticeship.Cohort.ProviderId == searchParameters.ProviderId));
        }
        public async Task Then_Apprentices_With_Alerts_Total_Found_Are_Return_With_Page_Data(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 2;
            searchParameters.PageItemCount = 2;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual(3, actual.TotalApprenticeshipsWithAlertsFound);
        }
        public async Task And_No_Sort_Term_And_Is_And_There_Are_ApprenticeshipUpdates_These_Appear_First(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 0;
            searchParameters.PageItemCount = 0;
            searchParameters.ReverseSort   = false;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();


            var apprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship
                {
                    FirstName            = "XX",
                    LastName             = "Should_Be_Second",
                    Uln                  = "XX",
                    CourseName           = "XX",
                    StartDate            = DateTime.UtcNow,
                    ProviderRef          = "ABC",
                    Cohort               = new Cohort(),
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>
                    {
                        new ApprenticeshipUpdate
                        {
                            Status     = (byte)ApprenticeshipUpdateStatus.Pending,
                            Originator = (byte)Originator.Employer
                        }
                    }
                },
                new Apprenticeship
                {
                    FirstName            = "XX",
                    LastName             = "Should_Be_First",
                    Uln                  = "XX",
                    CourseName           = "XX",
                    StartDate            = DateTime.UtcNow,
                    ProviderRef          = "ABC",
                    Cohort               = new Cohort(),
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                },
                new Apprenticeship
                {
                    FirstName            = "XX",
                    LastName             = "Should_Be_Third",
                    Uln                  = "XX",
                    CourseName           = "XX",
                    StartDate            = DateTime.UtcNow,
                    ProviderRef          = "ABC",
                    Cohort               = new Cohort(),
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>
                    {
                        new ApprenticeshipUpdate
                        {
                            Status     = (byte)ApprenticeshipUpdateStatus.Pending,
                            Originator = Originator.Provider
                        }
                    }
                },
            };

            AssignProviderToApprenticeships(searchParameters.ProviderId ?? 0, apprenticeships);

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual("Should_Be_Second", actual.Apprenticeships.ElementAt(0).LastName);
            Assert.AreEqual("Should_Be_Third", actual.Apprenticeships.ElementAt(1).LastName);
            Assert.AreEqual("Should_Be_First", actual.Apprenticeships.ElementAt(2).LastName);
        }
        public async Task And_No_Sort_Term_Then_Apprentices_Are_Default_Sorted(
            ApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange

            searchParameters.ReverseSort       = false;
            searchParameters.PageNumber        = 1;
            searchParameters.PageItemCount     = 10;
            searchParameters.EmployerAccountId = null;

            searchParameters.Filters = new ApprenticeshipSearchFilters();

            var apprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship
                {
                    FirstName   = "XX",
                    LastName    = "XX",
                    Uln         = "Should_Be_Third",
                    CourseName  = "XX",
                    StartDate   = DateTime.UtcNow,
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("XX")
                    },
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                },
                new Apprenticeship
                {
                    FirstName   = "XX",
                    LastName    = "XX",
                    Uln         = "XX",
                    CourseName  = "XX",
                    StartDate   = DateTime.UtcNow.AddMonths(2),
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("XX")
                    },
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                },
                new Apprenticeship
                {
                    FirstName   = "XX",
                    LastName    = "XX",
                    Uln         = "XX",
                    CourseName  = "XX",
                    StartDate   = DateTime.UtcNow,
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Should_Be_Fourth")
                    },
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                },
                new Apprenticeship
                {
                    FirstName   = "XX",
                    LastName    = "XX",
                    Uln         = "XX",
                    CourseName  = "Should_Be_Fifth",
                    StartDate   = DateTime.UtcNow,
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("XX")
                    },
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                },
                new Apprenticeship
                {
                    FirstName   = "Should_Be_First",
                    LastName    = "XX",
                    Uln         = "XX",
                    CourseName  = "XX",
                    StartDate   = DateTime.UtcNow,
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("XX")
                    },
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                },
                new Apprenticeship
                {
                    FirstName   = "XX",
                    LastName    = "Should_Be_Second",
                    Uln         = "XX",
                    CourseName  = "XX",
                    StartDate   = DateTime.UtcNow,
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("XX")
                    },
                    DataLockStatus       = new List <DataLockStatus>(),
                    ApprenticeshipUpdate = new List <ApprenticeshipUpdate>()
                }
            };

            AssignProviderToApprenticeships(searchParameters.ProviderId ?? 0, apprenticeships);

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

            var service = new ApprenticeshipSearchService(mockContext.Object);

            //Act
            var actual = await service.Find(searchParameters);

            //Assert
            Assert.AreEqual("Should_Be_First", actual.Apprenticeships.ElementAt(0).FirstName);
            Assert.AreEqual("Should_Be_Second", actual.Apprenticeships.ElementAt(1).LastName);
            Assert.AreEqual("Should_Be_Third", actual.Apprenticeships.ElementAt(2).Uln);
            Assert.AreEqual("Should_Be_Fourth", actual.Apprenticeships.ElementAt(3).Cohort.AccountLegalEntity.Name);
            Assert.AreEqual("Should_Be_Fifth", actual.Apprenticeships.ElementAt(4).CourseName);
            Assert.AreEqual(DateTime.UtcNow.AddMonths(2).ToString("d"), actual.Apprenticeships.ElementAt(5).StartDate.Value.ToString("d"));
        }