public async Task<IActionResult> Health() { string resourceName = typeof(Program).Namespace; string message; logger.LogInformation($"{nameof(Health)} has been called"); message = "Composite Shell is available"; logger.LogInformation($"{nameof(Health)} responded with: {resourceName} - {message}"); var viewModel = CreateHealthViewModel(resourceName, message); // loop through the registered applications and create some tasks - one per application for their health var paths = await pathDataService.GetPaths().ConfigureAwait(false); var onlinePaths = paths.Where(w => w.IsOnline && string.IsNullOrWhiteSpace(w.ExternalURL)).ToList(); var offlinePaths = paths.Where(w => !w.IsOnline && string.IsNullOrWhiteSpace(w.ExternalURL)).ToList(); if (onlinePaths?.Count > 0) { var applicationOnlineHealthModels = await GetApplicationOnlineHealthAsync(onlinePaths).ConfigureAwait(false); AppendApplicationsHealths(viewModel.HealthItems, applicationOnlineHealthModels); } if (offlinePaths?.Count > 0) { var applicationOfflineHealthItemModels = CreateOfflineApplicationHealthModels(offlinePaths.ToList()); viewModel.HealthItems.AddRange(applicationOfflineHealthItemModels); } return this.NegotiateContentResult(viewModel); }
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, }; }
public async Task <IViewComponentResult> InvokeAsync() { var vm = new ListPathsViewModel(); var paths = await pathDataService.GetPaths().ConfigureAwait(false); vm.Paths = paths.Where(w => !string.IsNullOrWhiteSpace(w.TopNavigationText)); return(View(vm)); }
public RobotControllerTests() { defaultPathDataService = A.Fake <IPathDataService>(); defaultLogger = A.Fake <ILogger <RobotController> >(); defaultWebHostEnvironment = A.Fake <IWebHostEnvironment>(); defaultBaseUrlService = A.Fake <IBaseUrlService>(); var pathModels = new List <PathModel> { new PathModel { RobotsURL = "http://SomeRobotUrl.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.Content(A <string> .Ignored)).Returns("DummyUrl"); A.CallTo(() => defaultUrlHelper.RouteUrl(A <UrlRouteContext> .Ignored)).Returns(DummySitemapUrl); defaultTokenRetriever = A.Fake <IBearerTokenRetriever>(); A.CallTo(() => defaultTokenRetriever.GetToken(A <HttpContext> .Ignored)).Returns("SomeToken"); defaultApplicationRobotService = A.Fake <IApplicationRobotService>(); A.CallTo(() => defaultApplicationRobotService.GetAsync(A <ApplicationRobotModel> .Ignored)).Returns("RetrievedValue: SomeValue"); defaultShellRobotFileService = A.Fake <IShellRobotFileService>(); defaultController = new RobotController(defaultPathDataService, defaultLogger, defaultWebHostEnvironment, defaultTokenRetriever, defaultApplicationRobotService, defaultShellRobotFileService, defaultBaseUrlService) { ControllerContext = new ControllerContext { HttpContext = defaultHttpContext, }, Url = defaultUrlHelper, }; }
private async Task <IEnumerable <ApplicationRobotModel> > GetApplicationRobotsAsync() { var paths = await pathDataService.GetPaths().ConfigureAwait(false); var onlinePaths = paths.Where(w => w.IsOnline && !string.IsNullOrWhiteSpace(w.RobotsURL)).ToList(); var applicationRobotModels = await CreateApplicationRobotModelTasksAsync(onlinePaths).ConfigureAwait(false); var allRobotRetrievalTasks = (from a in applicationRobotModels select a.RetrievalTask).ToArray(); await Task.WhenAll(allRobotRetrievalTasks).ConfigureAwait(false); return(applicationRobotModels); }
private async Task <IEnumerable <ApplicationSitemapModel> > GetApplicationSitemapsAsync() { // loop through the registered applications and create some tasks - one per application that has a sitemap url var paths = await pathDataService.GetPaths().ConfigureAwait(false); var onlinePaths = paths.Where(w => w.IsOnline && !string.IsNullOrWhiteSpace(w.SitemapURL)).ToList(); var applicationSitemapModels = await CreateApplicationSitemapModelTasksAsync(onlinePaths).ConfigureAwait(false); // await all application sitemap service tasks to complete var allTasks = (from a in applicationSitemapModels select a.RetrievalTask).ToArray(); await Task.WhenAll(allTasks).ConfigureAwait(false); return(applicationSitemapModels); }
public async Task HealthReturnsSuccess(string mediaTypeName) { //Arrange var claims = new List <Claim>(); var user = new ClaimsPrincipal(new ClaimsIdentity(claims)); healthController.ControllerContext = new ControllerContext(); healthController.ControllerContext.HttpContext = new DefaultHttpContext() { User = user }; healthController.ControllerContext.HttpContext.Request.Headers.Add(HeaderNames.Accept, mediaTypeName); var path1 = "path1"; var path2 = "path2"; var pathModels = new List <PathModel> { new PathModel { Path = path1, IsOnline = true, }, new PathModel { Path = path2, IsOnline = false, }, }; var regions = new List <RegionModel>() { new RegionModel() { Path = path1, RegionEndpoint = $"http://localhost/{path1}/region1", PageRegion = PageRegion.Body, }, new RegionModel() { Path = path2, RegionEndpoint = $"http://localhost/{path2}/region2", PageRegion = PageRegion.Body, }, }; var path1HealthItemModels = new List <HealthItemModel>(); path1HealthItemModels.Add(new HealthItemModel() { Message = "Message1", Service = "Service1" }); path1HealthItemModels.Add(new HealthItemModel() { Message = "Message2", Service = "Service2" }); A.CallTo(() => pathDataService.GetPaths()).Returns(pathModels); A.CallTo(() => regionService.GetRegions(A <string> .Ignored)).Returns(regions); A.CallTo(() => applicationHealthService.GetAsync(A <ApplicationHealthModel> .Ignored)).Returns(path1HealthItemModels); //Act var result = await healthController.Health().ConfigureAwait(false); var model = GetModel <HealthViewModel>(result); //Assert Assert.Equal(4, model.HealthItems.Count); Assert.Contains(model.HealthItems, x => x.Message.Contains("Composite Shell is available", StringComparison.OrdinalIgnoreCase)); Assert.Contains(model.HealthItems, x => x.Message.Contains("Message1", StringComparison.OrdinalIgnoreCase)); Assert.Contains(model.HealthItems, x => x.Message.Contains("Message2", StringComparison.OrdinalIgnoreCase)); Assert.Contains(model.HealthItems, x => x.Message.Contains("Skipped health check for: path2, because it is offline", StringComparison.OrdinalIgnoreCase)); }