Beispiel #1
0
        public async Task And_Cookie_Exists_Then_Reads_Cookie_And_Builds_ViewModel_From_Mediator_Result(
            ShortlistCookieItem shortlistCookie,
            GetShortlistForUserResult resultFromMediator,
            [Frozen] Mock <ICookieStorageService <ShortlistCookieItem> > mockCookieService,
            [Frozen] Mock <IMediator> mockMediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Frozen] Mock <IOptions <FindApprenticeshipTrainingWeb> > config,
            [Greedy] ShortlistController controller)
        {
            //Arrange
            config.Object.Value.EmployerDemandFeatureToggle = false;
            mockCookieService
            .Setup(service => service.Get(Constants.ShortlistCookieName))
            .Returns(shortlistCookie);
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetShortlistForUserQuery>(c => c.ShortlistUserId.Equals(shortlistCookie.ShortlistUserId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(resultFromMediator);

            //Act
            var actual = await controller.Index("") as ViewResult;

            //Assert
            actual.Should().NotBeNull();
            var model = actual.Model as ShortlistViewModel;

            model.Should().NotBeNull();
            model.Shortlist.Should()
            .BeEquivalentTo(
                resultFromMediator.Shortlist.Select(item => (ShortlistItemViewModel)item));
            model.Removed.Should().BeEmpty();
            model.HelpBaseUrl.Should().BeEmpty();
        }
Beispiel #2
0
        public async Task And_Cookie_No_Exists_Then_Returns_Empty_ViewModel(
            ShortlistCookieItem shortlistCookie,
            GetShortlistForUserResult resultFromMediator,
            [Frozen] Mock <ICookieStorageService <ShortlistCookieItem> > mockCookieService,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ShortlistController controller)
        {
            //Arrange
            mockCookieService
            .Setup(service => service.Get(Constants.ShortlistCookieName))
            .Returns(default(ShortlistCookieItem));
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetShortlistForUserQuery>(c => c.ShortlistUserId.Equals(shortlistCookie.ShortlistUserId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(resultFromMediator);

            //Act
            var actual = await controller.Index(null) as ViewResult;

            //Assert
            actual.Should().NotBeNull();
            var model = actual.Model as ShortlistViewModel;

            model.Should().NotBeNull();
            model.Shortlist.Should().BeEmpty();
            mockMediator.Verify(mediator => mediator.Send(
                                    It.IsAny <GetShortlistForUserQuery>(),
                                    It.IsAny <CancellationToken>()),
                                Times.Never);
        }
Beispiel #3
0
        public async Task Then_If_The_Encoded_Removed_Param_Is_Invalid_Then_It_Is_Set_To_Empty(
            string removed,
            ShortlistCookieItem shortlistCookie,
            GetShortlistForUserResult resultFromMediator,
            [Frozen] Mock <ICookieStorageService <ShortlistCookieItem> > mockCookieService,
            [Frozen] Mock <IMediator> mockMediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Greedy] ShortlistController controller)
        {
            var encodedData = Encoding.UTF8.GetBytes($"{removed}");

            mockCookieService
            .Setup(service => service.Get(Constants.ShortlistCookieName))
            .Returns(shortlistCookie);
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetShortlistForUserQuery>(c => c.ShortlistUserId.Equals(shortlistCookie.ShortlistUserId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(resultFromMediator);

            //Act
            var actual = await controller.Index(encodedData.ToString()) as ViewResult;

            //Assert
            actual.Should().NotBeNull();
            var model = actual.Model as ShortlistViewModel;

            model.Should().NotBeNull();
            model.Shortlist.Should()
            .BeEquivalentTo(
                resultFromMediator.Shortlist.Select(item => (ShortlistItemViewModel)item));
            model.Removed.Should().BeEmpty();
        }
Beispiel #4
0
        public async Task Then_Gets_Shortlist_For_User_From_Mediator(
            Guid shortlistUserId,
            GetShortlistForUserResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ShortlistController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetShortlistForUserQuery>(query => query.ShortlistUserId == shortlistUserId),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetAllForUser(shortlistUserId) as ObjectResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetShortlistForUserResponse;

            model !.Shortlist.Should().BeEquivalentTo(mediatorResult.Shortlist.Select(item => (GetShortlistItem)item));
        }
Beispiel #5
0
        public async Task Then_The_Help_Link_Is_Shown_If_The_Feature_Is_Toggled_On(ShortlistCookieItem shortlistCookie,
                                                                                   GetShortlistForUserResult resultFromMediator,
                                                                                   [Frozen] Mock <ICookieStorageService <ShortlistCookieItem> > mockCookieService,
                                                                                   [Frozen] Mock <IMediator> mockMediator,
                                                                                   [Frozen] Mock <IDataProtector> protector,
                                                                                   [Frozen] Mock <IDataProtectionProvider> provider,
                                                                                   [Frozen] Mock <IOptions <FindApprenticeshipTrainingWeb> > config,
                                                                                   [Greedy] ShortlistController controller)
        {
            //Arrange
            config.Object.Value.EmployerDemandFeatureToggle = true;
            mockCookieService
            .Setup(service => service.Get(Constants.ShortlistCookieName))
            .Returns(shortlistCookie);
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetShortlistForUserQuery>(c => c.ShortlistUserId.Equals(shortlistCookie.ShortlistUserId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(resultFromMediator);

            //Act
            var actual = await controller.Index("") as ViewResult;

            //Assert
            actual.Should().NotBeNull();
            var model = actual.Model as ShortlistViewModel;

            model.Should().NotBeNull();
            model.Shortlist.Should()
            .BeEquivalentTo(
                resultFromMediator.Shortlist.Select(item => (ShortlistItemViewModel)item));
            model.Removed.Should().BeEmpty();
            model.HelpBaseUrl.Should().Be(config.Object.Value.EmployerDemandUrl);
            foreach (var itemViewModel in model.Shortlist)
            {
                itemViewModel.HelpFindingCourseUrl.Should().Be($"/registerdemand/course/{itemViewModel.Course.Id}/share-interest?entrypoint=0");
            }
        }
Beispiel #6
0
        public async Task Then_If_The_Removed_Query_Param_Is_Set_It_Is_Decoded(
            string removed,
            ShortlistCookieItem shortlistCookie,
            GetShortlistForUserResult resultFromMediator,
            [Frozen] Mock <ICookieStorageService <ShortlistCookieItem> > mockCookieService,
            [Frozen] Mock <IMediator> mockMediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Greedy] ShortlistController controller)
        {
            //Arrange
            var encodedData = Encoding.UTF8.GetBytes($"{removed}");

            protector.Setup(sut => sut.Unprotect(It.IsAny <byte[]>())).Returns(encodedData);
            provider.Setup(x => x.CreateProtector(Constants.ShortlistProtectorName)).Returns(protector.Object);
            mockCookieService
            .Setup(service => service.Get(Constants.ShortlistCookieName))
            .Returns(shortlistCookie);
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetShortlistForUserQuery>(c => c.ShortlistUserId.Equals(shortlistCookie.ShortlistUserId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(resultFromMediator);

            //Act
            var actual = await controller.Index(WebEncoders.Base64UrlEncode(encodedData)) as ViewResult;

            //Assert
            actual.Should().NotBeNull();
            var model = actual.Model as ShortlistViewModel;

            model.Should().NotBeNull();
            model.Shortlist.Should()
            .BeEquivalentTo(
                resultFromMediator.Shortlist.Select(item => (ShortlistItemViewModel)item));
            model.Removed.Should().Be(removed);
        }