public RobotControllerTests()
        {
            defaultAppRegistryDataService = A.Fake <IAppRegistryDataService>();
            defaultLogger             = A.Fake <ILogger <RobotController> >();
            defaultWebHostEnvironment = A.Fake <IWebHostEnvironment>();
            defaultBaseUrlService     = A.Fake <IBaseUrlService>();

            var appRegistrationModels = new List <AppRegistrationModel>
            {
                new AppRegistrationModel
                {
                    RobotsURL = new Uri("http://SomeRobotUrl.xyz", UriKind.Absolute),
                    IsOnline  = true,
                },
            };

            A.CallTo(() => defaultAppRegistryDataService.GetAppRegistrationModels()).Returns(appRegistrationModels);

            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>();
            A.CallTo(() => defaultShellRobotFileService.GetStaticFileText(A <string> .Ignored)).Returns("{Insertion}");

            defaultController = new RobotController(defaultAppRegistryDataService, defaultLogger, defaultWebHostEnvironment, defaultTokenRetriever, defaultApplicationRobotService, defaultShellRobotFileService, defaultBaseUrlService)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = defaultHttpContext,
                },
                Url = defaultUrlHelper,
            };
        }
Esempio n. 2
0
        private async Task <List <ApplicationRobotModel> > CreateApplicationRobotModelTasksAsync(IEnumerable <AppRegistrationModel> appRegistrationModel)
        {
            var bearerToken = User.Identity.IsAuthenticated ? await bearerTokenRetriever.GetToken(HttpContext).ConfigureAwait(false) : null;

            var applicationRobotModels = new List <ApplicationRobotModel>();

            foreach (var path in appRegistrationModel)
            {
                logger.LogInformation($"{nameof(Action)}: Getting child robots.txt for: {path.Path}");

                var applicationRobotModel = new ApplicationRobotModel
                {
                    Path        = path.Path,
                    RobotsURL   = path.RobotsURL.ToString(),
                    BearerToken = bearerToken,
                };

                applicationRobotModel.RetrievalTask = applicationRobotService.GetAsync(applicationRobotModel);

                applicationRobotModels.Add(applicationRobotModel);
            }

            return(applicationRobotModels);
        }