public void GetQualifications_Returns_All_Qualifications_From_Data_And_Adds_A_Default_To_Show_All()
    {
        var qualifications = new List <Qualification>
        {
            new() { Id = 1, Name = "Test Qualification 1" },
            new() { Id = 2, Name = "Test Qualification 2" }
        };

        _providerDataService.GetQualifications()
        .Returns(qualifications);

        var results = _service.GetQualifications().ToList();

        results.Count.Should().Be(3);
        results.SingleOrDefault(q => q.Id == 0 && q.Name == "All T Level courses").Should().NotBeNull();
    }
Esempio n. 2
0
    public Task Execute(ISearchContext context)
    {
        context.ViewModel.SelectedQualificationId ??= 0;

        var qualifications = _providerSearchService.GetQualifications();

        if (context.ViewModel.SelectedQualificationId != 0 &&
            // ReSharper disable once PossibleMultipleEnumeration
            qualifications.All(q => q.Id != context.ViewModel.SelectedQualificationId))
        {
            context.ViewModel.SelectedQualificationId = 0;
        }

        // ReSharper disable once PossibleMultipleEnumeration
        context.ViewModel.Qualifications = qualifications
                                           .Select(q =>
                                                   new SelectListItem
        {
            Text     = q.Name,
            Value    = q.Id.ToString(),
            Selected = q.Id == context.ViewModel.SelectedQualificationId.Value
        });

        return(Task.CompletedTask);
    }
        public void GetQualifications_Returns_All_Qualifications_OrderBy_Name()
        {
            var qualifications = new List <Qualification>
            {
                new Qualification {
                    Id = 1, Name = "Xyz"
                },
                new Qualification {
                    Id = 2, Name = "Mno"
                },
                new Qualification {
                    Id = 3, Name = "Abc"
                }
            };

            _providerDataService.GetQualifications().Returns(qualifications);

            var expected = qualifications.OrderBy(x => x.Name);

            var actual = _service.GetQualifications().ToList();

            Assert.True(actual.SequenceEqual(expected));
            Assert.False(actual.SequenceEqual(qualifications));
            _providerDataService.Received(1).GetQualifications();
        }
        public Task Execute(ISearchContext context)
        {
            context.ViewModel.SelectedQualificationId ??= 0;

            var qualifications = _providerSearchService.GetQualifications();

            context.ViewModel.Qualifications = qualifications
                                               .Select(q =>
                                                       new SelectListItem
            {
                Text     = q.Name,
                Value    = q.Id.ToString(),
                Selected = q.Id == context.ViewModel.SelectedQualificationId.Value
            });

            return(Task.CompletedTask);
        }
        public async Task Step_Returns_SelectListItems_For_All_Qualifications_With_A_Selected_Qualification()
        {
            // Arrange
            int?selectedQualificationId = 3;

            var viewModel = new FindViewModel
            {
                SelectedQualificationId = selectedQualificationId
            };

            var context = new SearchContext(viewModel);

            var qualifications = new List <Qualification>
            {
                new Qualification {
                    Id = 1, Name = "Qualification 1"
                },
                new Qualification {
                    Id = 2, Name = "Qualification 2"
                },
                new Qualification {
                    Id = 3, Name = "Qualification 3"
                },
                new Qualification {
                    Id = 4, Name = "Qualification 4"
                },
                new Qualification {
                    Id = 5, Name = "Qualification 5"
                }
            };

            _providerSearchService.GetQualifications().Returns(qualifications);

            // Act
            await _searchStep.Execute(context);

            // Assert
            _providerSearchService.Received(1).GetQualifications();
            context.ViewModel.Qualifications.Count().Should().Be(qualifications.Count);
            context.ViewModel.Qualifications
            .Any(q => q.Value == selectedQualificationId.ToString() && q.Selected)
            .Should().BeTrue();

            context.ViewModel.Qualifications
            .Count(q => q.Value == selectedQualificationId.ToString() && q.Selected)
            .Should()
            .Be(1);

            var qualificationsSelectList = context.ViewModel.Qualifications.OrderBy(q => q.Value).ToList();

            qualificationsSelectList[0].Value.Should().Be("1");
            qualificationsSelectList[0].Text.Should().Be("Qualification 1");
            qualificationsSelectList[0].Selected.Should().BeFalse();

            qualificationsSelectList[1].Value.Should().Be("2");
            qualificationsSelectList[1].Text.Should().Be("Qualification 2");
            qualificationsSelectList[1].Selected.Should().BeFalse();

            qualificationsSelectList[2].Value.Should().Be("3");
            qualificationsSelectList[2].Text.Should().Be("Qualification 3");
            qualificationsSelectList[2].Selected.Should().BeTrue();

            qualificationsSelectList[3].Value.Should().Be("4");
            qualificationsSelectList[3].Text.Should().Be("Qualification 4");
            qualificationsSelectList[3].Selected.Should().BeFalse();

            qualificationsSelectList[4].Value.Should().Be("5");
            qualificationsSelectList[4].Text.Should().Be("Qualification 5");
            qualificationsSelectList[4].Selected.Should().BeFalse();



            context.ViewModel.SelectedQualificationId.Should().Be(selectedQualificationId);
        }