public async Task GetFileTextReturnsEmptyStringWhenFileDoesntExist()
        {
            var fileInfoHelper = A.Fake <IFileInfoHelper>();
            var service        = new ShellRobotFileService(fileInfoHelper, null);

            var result = await service.GetStaticFileText("SomeRobotsPath");

            Assert.True(string.IsNullOrWhiteSpace(result));
        }
        public async Task GetFileTextIdentifiesCorrectResponseForDev()
        {
            const string fakeRobotFileText = "StaticRobotsFileText";
            var          fileInfoHelper    = A.Fake <IFileInfoHelper>();

            A.CallTo(() => fileInfoHelper.FileExists(A <string> .Ignored)).Returns(true);
            A.CallTo(() => fileInfoHelper.ReadAllTextAsync("SomeRobotsPath\\StaticRobots.txt")).Returns(fakeRobotFileText);

            var service = new ShellRobotFileService(fileInfoHelper, null);

            var result = await service.GetStaticFileText("SomeRobotsPath");

            Assert.Equal(fakeRobotFileText, result);
        }
        public async Task GetFileTextReturnsFilesTextWhenFileDoesntExist()
        {
            const string fakeRobotFileText = "FakeRobotFileText";
            var          fileInfoHelper    = A.Fake <IFileInfoHelper>();

            A.CallTo(() => fileInfoHelper.FileExists(A <string> .Ignored)).Returns(true);
            A.CallTo(() => fileInfoHelper.ReadAllTextAsync(A <string> .Ignored)).Returns(fakeRobotFileText);

            var service = new ShellRobotFileService(fileInfoHelper, null);

            var result = await service.GetStaticFileText("SomeRobotsPath");

            Assert.Equal(fakeRobotFileText, result);
        }
        public async Task GetFileTextIdentifiesCorrectResponseForProd()
        {
            const string fakeRobotFileText = "StaticRobotsFileText";
            var          fileInfoHelper    = A.Fake <IFileInfoHelper>();

            A.CallTo(() => fileInfoHelper.FileExists(A <string> .Ignored)).Returns(true);
            A.CallTo(() => fileInfoHelper.ReadAllTextAsync("SomeRobotsPath\\ProductionStaticRobots.txt")).Returns(fakeRobotFileText);

            var httpContextAccessor = A.Fake <IHttpContextAccessor>();

            A.CallTo(() => httpContextAccessor.HttpContext.Request.Host).Returns(new HostString("nationalcareers.service.gov.uk"));

            var service = new ShellRobotFileService(fileInfoHelper, httpContextAccessor);

            var result = await service.GetStaticFileText("SomeRobotsPath");

            Assert.Equal(fakeRobotFileText, result);
        }
        public async Task GetFileTextIdentifiesCorrectResponseForDraftDevIntegration()
        {
            const string expectedFileText =
                @"User-agent: *
Disallow: /";

            var fileInfoHelper = new FileInfoHelper();

            var httpContextAccessor = A.Fake <IHttpContextAccessor>();

            A.CallTo(() => httpContextAccessor.HttpContext.Request.Host).Returns(new HostString("dev-draft.nationalcareersservice.org.uk"));

            var service = new ShellRobotFileService(fileInfoHelper, httpContextAccessor);

            var result = await service.GetStaticFileText($"{AppDomain.CurrentDomain.BaseDirectory}wwwroot");

            Assert.Equal(expectedFileText, result);
        }
        public async Task GetFileTextIdentifiesCorrectResponseForPreProdIntegration()
        {
            const string expectedFileText =
                @"User-agent: SemrushBot-SA
Disallow: /alerts/
Disallow: /ab/
Disallow: /webchat/
{Insertion}

User-agent: *
Disallow: /";

            var fileInfoHelper = new FileInfoHelper();

            var httpContextAccessor = A.Fake <IHttpContextAccessor>();

            A.CallTo(() => httpContextAccessor.HttpContext.Request.Host).Returns(new HostString("staging.nationalcareers.service.gov.uk"));

            var service = new ShellRobotFileService(fileInfoHelper, httpContextAccessor);

            var result = await service.GetStaticFileText($"{AppDomain.CurrentDomain.BaseDirectory}wwwroot");

            Assert.Equal(expectedFileText, result);
        }