示例#1
0
        public async Task Then_The_Api_Is_Called_With_The_Valid_Request_Parameters_And_The_Hub_Is_Returned(
            GetHubQuery query,
            GetMenuQueryResult menuResult,
            MenuPageModel.MenuPageContent menuContent,
            CmsContent apiResponse,
            HubPageModel response,
            GetBannerQueryResult bannerResult,
            BannerPageModel bannerContent,
            [Frozen] Mock <IContentService> contentService,
            [Frozen] Mock <IReliableCacheStorageService> service,
            [Frozen] Mock <IMediator> mediator,
            GetHubQueryHandler handler)
        {
            contentService.Setup(x => x.HasContent(It.IsAny <ApiResponse <CmsContent> >())).Returns(true);
            service.Setup(o =>
                          o.GetData <CmsContent>(
                              It.Is <GetHubEntriesRequest>(c =>
                                                           c.GetUrl.Contains($"fields.hubType={query.Hub.ToTitleCase()}")),
                              $"{query.Hub.ToTitleCase()}_hub", contentService.Object.HasContent))
            .ReturnsAsync(apiResponse);

            mediator.SetupMenu(menuResult, menuContent);
            mediator.SetupBanners(bannerResult, bannerContent);

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

            actual.PageModel.Should().BeEquivalentTo(response.Build(apiResponse, menuContent, bannerContent));
            service.Verify(x => x.GetData <CmsContent>(It.IsAny <GetHubEntriesRequest>(), It.IsAny <string>(), contentService.Object.HasContent), Times.Once);
        }
        public async Task And_The_Api_Is_Called_With_Invalid_Request_Parameters_Then_No_Hub_Is_Returned(
            GetHubQuery query, [Frozen] Mock <IApiClient> client, [Frozen] Mock <IOptions <CampaignConfiguration> > config, GetHubQueryHandler handler)
        {
            SetupMockConfig(config);
            client.Setup(o => o.Get <Page <Hub> >(It.Is <GetHubPreviewRequest>(r => r.GetUrl == $"hub/preview/{query.Hub}"))).ReturnsAsync((Page <Hub>)null);
            client.Setup(o => o.Get <Page <Hub> >(It.Is <GetHubRequest>(r => r.GetUrl == $"hub/{query.Hub}"))).ReturnsAsync((Page <Hub>)null);

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

            actual.Should().NotBeNull();
            actual.Page.Should().BeNull();
        }
        public async Task Then_The_Api_Is_Called_With_The_Valid_Request_Parameters_And_The_Hub_Is_Returned_From_The_Preview_Api_if_Config_And_Param_Set(
            GetHubQuery query, Page <Hub> response, [Frozen] Mock <IOptions <CampaignConfiguration> > config, [Frozen] Mock <IApiClient> client, GetHubQueryHandler handler)
        {
            SetupMockConfig(config);
            query.Preview = true;
            client.Setup(o => o.Get <Page <Hub> >(It.Is <GetHubPreviewRequest>(r => r.GetUrl == $"hub/preview/{query.Hub}"))).ReturnsAsync(response);

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

            client.Verify(o => o.Get <Page <Hub> >(It.Is <GetHubPreviewRequest>(r => r.GetUrl == $"hub/preview/{query.Hub}")), Times.Once);
            actual.Should().NotBeNull();
            actual.Page.Should().NotBeNull();
        }
        public async Task Then_The_Api_Is_Called_With_The_Valid_Request_Parameters_Then_The_Hub_Is_Returned_From_The_Api_With_The_Menu(
            bool preview, GetHubQuery query, Page <Hub> response, [Frozen] Mock <IApiClient> client, [Frozen] Mock <IOptions <CampaignConfiguration> > config, GetHubQueryHandler handler)
        {
            query.Preview = preview;
            SetupMockConfig(config, false);

            client.Setup(o => o.Get <Page <Hub> >(It.Is <GetHubRequest>(r => r.GetUrl == $"hub/{query.Hub}"))).ReturnsAsync(response);

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

            client.Verify(
                o => o.Get <Page <Hub> >(It.Is <GetHubRequest>(r => r.GetUrl == $"hub/{query.Hub}")), Times.Once);
            client.Verify(o => o.Get <Page <Hub> >(It.IsAny <GetHubPreviewRequest>()), Times.Never);

            actual.Should().NotBeNull();
            actual.Page.Should().NotBeNull();
            actual.Page.Content.Should().NotBeNull();
            actual.Page.Menu.Should().NotBeNull();
            actual.Page.Menu.Apprentices.Should().NotBeNullOrEmpty();
            actual.Page.Menu.Influencers.Should().NotBeNullOrEmpty();
            actual.Page.Menu.TopLevel.Should().NotBeNullOrEmpty();
            actual.Page.Menu.Employers.Should().NotBeNullOrEmpty();
        }