Exemplo n.º 1
0
        public async Task Then_Sorted_Apprentices_Are_Return_Per_Page(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.FieldName         = nameof(Apprenticeship.FirstName);
            searchParameters.PageNumber        = 2;
            searchParameters.PageItemCount     = 2;
            searchParameters.ReverseSort       = false;
            searchParameters.Filters           = new ApprenticeshipSearchFilters();
            searchParameters.CancellationToken = CancellationToken.None;

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);
            var service = new OrderedApprenticeshipSearchService(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);
        }
        public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_Normal_Sort(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.FieldName         = nameof(Apprenticeship.FirstName);
            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 OrderedApprenticeshipSearchService(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]));
        }
Exemplo n.º 3
0
        public async Task Then_Will_Return_Total_Apprenticeships_For_Employer(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.FieldName     = nameof(Apprenticeship.FirstName);
            searchParameters.PageNumber    = 2;
            searchParameters.PageItemCount = 2;
            searchParameters.ReverseSort   = false;
            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 OrderedApprenticeshipSearchService(mockContext.Object);

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

            //Assert
            Assert.AreEqual(5, actual.TotalAvailableApprenticeships);
        }
Exemplo n.º 4
0
        public async Task Then_Will_Return_Page_Number_Of_One_If_Only_Page(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.FieldName     = nameof(Apprenticeship.FirstName);
            searchParameters.PageNumber    = 20;
            searchParameters.PageItemCount = 5;
            searchParameters.ReverseSort   = false;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            searchParameters.ProviderId = null;

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

            var service = new OrderedApprenticeshipSearchService(mockContext.Object);

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

            //Assert
            Assert.AreEqual(2, actual.PageNumber);
            Assert.IsNotEmpty(actual.Apprenticeships);
        }
Exemplo n.º 5
0
        public async Task Then_Sorted_Apprentices_For_Employer_Are_Return(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.FieldName         = nameof(Apprenticeship.FirstName);
            searchParameters.PageNumber        = 0;
            searchParameters.PageItemCount     = 0;
            searchParameters.ReverseSort       = false;
            searchParameters.Filters           = new ApprenticeshipSearchFilters();
            searchParameters.CancellationToken = CancellationToken.None;
            searchParameters.ProviderId        = null;


            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParameters);

            apprenticeships[1].EmployerRef = null;
            apprenticeships[1].Cohort.EmployerAccountId = 0;

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

            var service = new OrderedApprenticeshipSearchService(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]));
        }
Exemplo n.º 6
0
        public async Task Then_Sorted_With_Alerts_Total_Found_Are_Return_With_Page_Data(
            OrderedApprenticeshipSearchParameters searchParams,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParams.FieldName     = nameof(Apprenticeship.FirstName);
            searchParams.PageNumber    = 2;
            searchParams.PageItemCount = 2;
            searchParams.ReverseSort   = false;
            searchParams.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = GetTestApprenticeshipsWithAlerts(searchParams);

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

            var service = new OrderedApprenticeshipSearchService(mockContext.Object);

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

            //Assert
            Assert.AreEqual(3, actual.TotalApprenticeshipsWithAlertsFound);
        }
Exemplo n.º 7
0
        public async Task Then_Apprentices_Are_First_Sorted_By_Alerts(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 0;
            searchParameters.PageItemCount = 0;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "Should_Be_Second",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(1),
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Employer")
                    },
                    DataLockStatus          = new List <DataLockStatus>(),
                    PendingUpdateOriginator = Originator.Provider
                },
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "Should_Be_Third",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(2),
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Employer")
                    },
                    DataLockStatus          = new List <DataLockStatus>(),
                    PendingUpdateOriginator = Originator.Provider
                },
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "Should_Be_First",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow,
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Employer")
                    },
                    DataLockStatus          = new List <DataLockStatus>(),
                    PendingUpdateOriginator = null
                }
            };

            apprenticeships[0].Cohort.ProviderId = searchParameters.ProviderId ?? 0;
            apprenticeships[1].Cohort.ProviderId = searchParameters.ProviderId ?? 0;
            apprenticeships[2].Cohort.ProviderId = searchParameters.ProviderId ?? 0;

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

            var service = new OrderedApprenticeshipSearchService(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);
        }
Exemplo n.º 8
0
        public async Task Then_Apprentices_Are_Sorted_By_Provider_Name(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 0;
            searchParameters.PageItemCount = 0;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var provider1 = new Provider(searchParameters.ProviderId.Value, "Should_Be_First", DateTime.UtcNow, DateTime.UtcNow);
            var provider2 = new Provider(searchParameters.ProviderId.Value, "Should_Be_Second", DateTime.UtcNow, DateTime.UtcNow);
            var provider3 = new Provider(searchParameters.ProviderId.Value, "Should_Be_Third", DateTime.UtcNow, DateTime.UtcNow);

            var apprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "LastName",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(2),
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        Provider = provider2, ProviderId = provider2.UkPrn
                    },
                    DataLockStatus = new List <DataLockStatus>(),
                    PaymentStatus  = PaymentStatus.Paused
                },
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "LastName",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(3),
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        Provider = provider3, ProviderId = provider3.UkPrn
                    },
                    DataLockStatus = new List <DataLockStatus>(),
                    PaymentStatus  = PaymentStatus.Completed
                },
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "LastName",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(-1),
                    ProviderRef = searchParameters.ProviderId.ToString(),
                    Cohort      = new Cohort {
                        Provider = provider1, ProviderId = provider1.UkPrn
                    },
                    DataLockStatus = new List <DataLockStatus>(),
                    PaymentStatus  = PaymentStatus.Active
                }
            };

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

            var service = new OrderedApprenticeshipSearchService(mockContext.Object);

            searchParameters.FieldName   = nameof(Apprenticeship.ApprenticeshipStatus);
            searchParameters.ReverseSort = false;

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

            //Assert
            Assert.AreEqual("Should_Be_First", actual.Apprenticeships.ElementAt(0).Cohort.Provider.Name);
            Assert.AreEqual("Should_Be_Second", actual.Apprenticeships.ElementAt(1).Cohort.Provider.Name);
            Assert.AreEqual("Should_Be_Third", actual.Apprenticeships.ElementAt(2).Cohort.Provider.Name);
        }
Exemplo n.º 9
0
        public async Task Then_Apprentices_Are_Sorted_By_Apprenticeship_Status(
            OrderedApprenticeshipSearchParameters searchParameters,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext)
        {
            //Arrange
            searchParameters.PageNumber    = 0;
            searchParameters.PageItemCount = 0;
            searchParameters.Filters       = new ApprenticeshipSearchFilters();

            var apprenticeships = new List <Apprenticeship>
            {
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "Should_Be_Second",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(2),
                    ProviderRef = "Provider ref",
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Employer")
                    },
                    DataLockStatus = new List <DataLockStatus>(),
                    PaymentStatus  = PaymentStatus.Paused
                },
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "Should_Be_Third",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(3),
                    ProviderRef = "Provider ref",
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Employer")
                    },
                    DataLockStatus = new List <DataLockStatus>(),
                    PaymentStatus  = PaymentStatus.Completed
                },
                new Apprenticeship
                {
                    FirstName   = "FirstName",
                    LastName    = "Should_Be_First",
                    Uln         = "Uln",
                    CourseName  = "Course",
                    StartDate   = DateTime.UtcNow.AddMonths(-1),
                    ProviderRef = "Provider ref",
                    Cohort      = new Cohort {
                        AccountLegalEntity = CreateAccountLegalEntity("Employer")
                    },
                    DataLockStatus = new List <DataLockStatus>(),
                    PaymentStatus  = PaymentStatus.Active
                }
            };

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

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

            var service = new OrderedApprenticeshipSearchService(mockContext.Object);

            searchParameters.FieldName   = nameof(Apprenticeship.ApprenticeshipStatus);
            searchParameters.ReverseSort = false;

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

            //Assert
            Assert.AreEqual("Should_Be_First", actual.Apprenticeships.ElementAt(0).LastName);
            Assert.AreEqual("Should_Be_Second", actual.Apprenticeships.ElementAt(1).LastName);
            Assert.AreEqual("Should_Be_Third", actual.Apprenticeships.ElementAt(2).LastName);
        }