public SitemapControllerTests() { defaultPathDataService = A.Fake <IPathDataService>(); defaultLogger = A.Fake <ILogger <SitemapController> >(); defaultBaseUrlService = A.Fake <IBaseUrlService>(); var pathModels = new List <PathModel> { new PathModel { SitemapURL = "http://SomeSitemapUrl.xyz", IsOnline = true, }, }; A.CallTo(() => defaultPathDataService.GetPaths()).Returns(pathModels); var user = A.Fake <ClaimsPrincipal>(); A.CallTo(() => user.Identity.IsAuthenticated).Returns(true); defaultHttpContext = A.Fake <HttpContext>(); defaultHttpContext.Request.Scheme = DummyScheme; defaultHttpContext.Request.Host = new HostString(DummyHost); var fakeIdentity = new GenericIdentity("User"); var principal = new GenericPrincipal(fakeIdentity, null); A.CallTo(() => defaultHttpContext.User).Returns(principal); defaultUrlHelper = A.Fake <IUrlHelper>(); A.CallTo(() => defaultUrlHelper.Action(A <UrlActionContext> .Ignored)).Returns(DummyHomeIndex); defaultTokenRetriever = A.Fake <IBearerTokenRetriever>(); A.CallTo(() => defaultTokenRetriever.GetToken(A <HttpContext> .Ignored)).Returns("SomeToken"); A.CallTo(() => defaultBaseUrlService.GetBaseUrl(A <HttpRequest> .Ignored, A <IUrlHelper> .Ignored)) .Returns("http://SomeBaseUrl"); defaultSitemapService = A.Fake <IApplicationSitemapService>(); A.CallTo(() => defaultSitemapService.GetAsync(A <ApplicationSitemapModel> .Ignored)) .Returns(Task.FromResult <IEnumerable <SitemapLocation> >(new List <SitemapLocation>() { new SitemapLocation { Url = "http://Sitemap.xml", Priority = 1, }, })); defaultController = new SitemapController(defaultPathDataService, defaultLogger, defaultTokenRetriever, defaultBaseUrlService, defaultSitemapService) { ControllerContext = new ControllerContext { HttpContext = defaultHttpContext, }, Url = defaultUrlHelper, }; }
private async Task <List <ApplicationSitemapModel> > CreateApplicationSitemapModelTasksAsync(IList <Models.PathModel> paths) { var bearerToken = User.Identity.IsAuthenticated ? await bearerTokenRetriever.GetToken(HttpContext).ConfigureAwait(false) : null; var applicationSitemapModels = new List <ApplicationSitemapModel>(); foreach (var path in paths) { logger.LogInformation($"{nameof(Action)}: Getting child Sitemap for: {path.Path}"); var applicationSitemapModel = new ApplicationSitemapModel { Path = path.Path, BearerToken = bearerToken, SitemapUrl = path.SitemapURL, }; applicationSitemapModel.RetrievalTask = sitemapService.GetAsync(applicationSitemapModel); applicationSitemapModels.Add(applicationSitemapModel); } return(applicationSitemapModels); }