/// <summary>
 /// Initializes a new instance of the <see cref="XRobotsTagAttribute"/> class
 /// </summary>
 public XRobotsTagAttribute()
 {
     _config = new XRobotsTagConfiguration {
         Enabled = true
     };
     _headerConfigurationOverrideHelper = new HeaderConfigurationOverrideHelper();
     _headerOverrideHelper = new HeaderOverrideHelper(new CspReportHelper());
 }
Exemple #2
0
        public void Validate_HeaderDisabled_NoException()
        {
            var xRobotsConfig = new XRobotsTagConfiguration {
                Enabled = false
            };

            _validator.Validate(xRobotsConfig);
        }
        public void CreateXRobotsTagResult_Disabled_ReturnsNull()
        {
            var xRobotsTag = new XRobotsTagConfiguration { Enabled = false, NoIndex = true };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.IsNull(result);
        }
Exemple #4
0
        public void Validate_HeaderDisabled_NoException()
        {
            var xRobotsConfig = new XRobotsTagConfiguration {
                Enabled = false
            };

            Assert.DoesNotThrow(() => _validator.Validate(xRobotsConfig));
        }
Exemple #5
0
        public void Validate_HeaderEnabledWithNoDirectives_ThrowsException()
        {
            var xRobotsConfig = new XRobotsTagConfiguration {
                Enabled = true
            };

            Assert.Throws <Exception>(() => _validator.Validate(xRobotsConfig));
        }
Exemple #6
0
        public void Validate_HeaderEnabledWithDirectives_NoException()
        {
            var xRobotsConfig = new XRobotsTagConfiguration {
                Enabled = true, NoIndex = true
            };

            Assert.DoesNotThrow(() => _validator.Validate(xRobotsConfig));
        }
        public void GetXRobotsTagConfiguration_NoOwinContext_ReturnsSystemWebConfig()
        {
            var config = new XRobotsTagConfiguration();
            _systemWebContext.XRobotsTag = config;

            var result = _contextHelper.GetXRobotsTagConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
Exemple #8
0
        public void GetXRobotsTagWithOverride_ConfigOverriden_ReturnsOverrideElement()
        {
            var configOverride = new XRobotsTagConfiguration {
                Enabled = true, NoIndex = true
            };

            _headerConfigurationOverrideHelper.SetXRobotsTagHeaderOverride(_mockContext, configOverride);

            Assert.AreSame(configOverride, _headerConfigurationOverrideHelper.GetXRobotsTagWithOverride(_mockContext));
        }
Exemple #9
0
        public void GetXRobotsTagConfiguration_ReturnsContextConfig()
        {
            var config = new XRobotsTagConfiguration();

            _nwContext.XRobotsTag = config;

            var result = _contextHelper.GetXRobotsTagConfiguration(_mockContext);

            Assert.Same(config, result);
        }
        public void CreateXRobotsTagResult_Disabled_ReturnsNull()
        {
            var xRobotsTag = new XRobotsTagConfiguration {
                Enabled = false, NoIndex = true
            };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.IsNull(result);
        }
Exemple #11
0
        public void GetXRobotsTagConfiguration_NoOwinContext_ReturnsSystemWebConfig()
        {
            var config = new XRobotsTagConfiguration();

            _systemWebContext.XRobotsTag = config;

            var result = _contextHelper.GetXRobotsTagConfiguration(_mockContext);

            Assert.Same(config, result);
        }
        public void GetXRobotsTagConfiguration_HasOwinConfig_ReturnsOwinConfig()
        {
            SetupOwinContext();
            var config = new XRobotsTagConfiguration();
            _owinContext.XRobotsTag = config;

            var result = _contextHelper.GetXRobotsTagConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
        public void CreateXRobotsTagResult_EnabledWithNoOdp_ReturnsSetXRobotsTagNoOdpResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration { Enabled = true, NoOdp = true };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
            Assert.AreEqual("noodp", result.Value);
        }
Exemple #14
0
        public void GetXRobotsTagConfiguration_HasOwinConfig_ReturnsOwinConfig()
        {
            SetupOwinContext();
            var config = new XRobotsTagConfiguration();

            _owinContext.XRobotsTag = config;

            var result = _contextHelper.GetXRobotsTagConfiguration(_mockContext);

            Assert.Same(config, result);
        }
        public void SetXRobotsTagHeader_NoOverride_DoesNothing()
        {
            var contextConfig = new XRobotsTagConfiguration();
            _contextHelper.Setup(h => h.GetXRobotsTagConfiguration(It.IsAny<HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXRobotsTagWithOverride(It.IsAny<HttpContextBase>())).Returns((XRobotsTagConfiguration)null);

            _overrideHelper.SetXRobotsTagHeader(_mockContext);

            _headerGenerator.Verify(g => g.CreateXRobotsTagResult(It.IsAny<XRobotsTagConfiguration>(), It.IsAny<XRobotsTagConfiguration>()), Times.Never);
            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), It.IsAny<HeaderResult>()), Times.Never);
        }
Exemple #16
0
        public void GetXRobotsTagConfiguration_OwinContextWithoutConfig_ReturnsSystemWebConfig()
        {
            SetupOwinContext();
            var config = new XRobotsTagConfiguration();

            _systemWebContext.XRobotsTag = config;

            var result = _contextHelper.GetXRobotsTagConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
        public void SetXRobotsTagHeader_Override_CreatesAndHandlesHeaderResult()
        {
            var contextConfig = new XRobotsTagConfiguration();
            var overrideConfig = new XRobotsTagConfiguration();
            _contextHelper.Setup(h => h.GetXRobotsTagConfiguration(It.IsAny<HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXRobotsTagWithOverride(It.IsAny<HttpContextBase>())).Returns(overrideConfig);
            _headerGenerator.Setup(g => g.CreateXRobotsTagResult(overrideConfig, contextConfig)).Returns(_expectedHeaderResult);

            _overrideHelper.SetXRobotsTagHeader(_mockContext);

            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), _expectedHeaderResult), Times.Once);
        }
        public void SetXRobotsTagHeader_NoOverride_DoesNothing()
        {
            var contextConfig = new XRobotsTagConfiguration();

            _contextHelper.Setup(h => h.GetXRobotsTagConfiguration(It.IsAny <HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXRobotsTagWithOverride(It.IsAny <HttpContextBase>())).Returns((XRobotsTagConfiguration)null);

            _overrideHelper.SetXRobotsTagHeader(_mockContext);

            _headerGenerator.Verify(g => g.CreateXRobotsTagResult(It.IsAny <XRobotsTagConfiguration>(), It.IsAny <XRobotsTagConfiguration>()), Times.Never);
            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny <HttpResponseBase>(), It.IsAny <HeaderResult>()), Times.Never);
        }
        public void SetXRobotsTagHeader_Override_CreatesAndHandlesHeaderResult()
        {
            var contextConfig  = new XRobotsTagConfiguration();
            var overrideConfig = new XRobotsTagConfiguration();

            _contextHelper.Setup(h => h.GetXRobotsTagConfiguration(It.IsAny <HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXRobotsTagWithOverride(It.IsAny <HttpContextBase>())).Returns(overrideConfig);
            _headerGenerator.Setup(g => g.CreateXRobotsTagResult(overrideConfig, contextConfig)).Returns(_expectedHeaderResult);

            _overrideHelper.SetXRobotsTagHeader(_mockContext);

            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny <HttpResponseBase>(), _expectedHeaderResult), Times.Once);
        }
        public void CreateXRobotsTagResult_EnabledWithMultipleDirectives_ReturnsSetXRobotsTagWithDirectivesResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration {
                Enabled = true, NoIndex = true, NoFollow = true
            };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
            Assert.AreEqual("noindex, nofollow", result.Value);
        }
Exemple #21
0
        public void CreateXRobotsTagResult_EnabledWithNoIndexNoOdp_ReturnsSetXRobotsTagNoIndexOnlyResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration {
                Enabled = true, NoIndex = true, NoOdp = true
            };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.NotNull(result);
            Assert.Equal(HeaderResult.ResponseAction.Set, result.Action);
            Assert.Equal("X-Robots-Tag", result.Name);
            Assert.Equal("noindex", result.Value);
        }
        public void CreateXRobotsTagResult_EnabledWithNoTranslate_ReturnsSetXRobotsTagNoTranslateResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration {
                Enabled = true, NoTranslate = true
            };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
            Assert.AreEqual("notranslate", result.Value);
        }
        public void CreateXRobotsTagResult_DisabledWithNoIndexInOldConfig_ReturnsRemoveXRobotsTagResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration {
                Enabled = false, NoIndex = true
            };
            var oldXRobotsTag = new XRobotsTagConfiguration {
                Enabled = true, NoIndex = true
            };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag, oldXRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Remove, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
        }
        public void CreateXRobotsTagResult_EnabledWithNoArchiveAndEnabledWithNoIndexInOldConfig_ReturnsSetXRobotsTagNoArchiveResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration {
                Enabled = true, NoArchive = true
            };
            var oldXRobotsTag = new XRobotsTagConfiguration {
                Enabled = true, NoIndex = true
            };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag, oldXRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
            Assert.AreEqual("noarchive", result.Value);
        }
        public void CreateXRobotsTagResult_EnabledWithNoArchiveAndEnabledWithNoIndexInOldConfig_ReturnsSetXRobotsTagNoArchiveResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration { Enabled = true, NoArchive = true };
            var oldXRobotsTag = new XRobotsTagConfiguration { Enabled = true, NoIndex = true };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag, oldXRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
            Assert.AreEqual("noarchive", result.Value);
        }
Exemple #26
0
 public XRobotsTagOptions()
 {
     Config = new XRobotsTagConfiguration();
 }
 public void Validate_HeaderDisabled_NoException()
 {
     var xRobotsConfig = new XRobotsTagConfiguration { Enabled = false };
     Assert.DoesNotThrow(() => _validator.Validate(xRobotsConfig));
 }
 public void Validate_HeaderEnabledWithNoDirectives_ThrowsException()
 {
     var xRobotsConfig = new XRobotsTagConfiguration { Enabled = true };
     Assert.Throws<Exception>(() => _validator.Validate(xRobotsConfig));
 }
 public void Validate_HeaderEnabledWithDirectives_NoException()
 {
     var xRobotsConfig = new XRobotsTagConfiguration { Enabled = true, NoIndex = true };
     Assert.DoesNotThrow(() => _validator.Validate(xRobotsConfig));
 }
        public void GetXRobotsTagWithOverride_ConfigOverriden_ReturnsOverrideElement()
        {
            var configOverride = new XRobotsTagConfiguration { Enabled = true, NoIndex = true };

            _headerConfigurationOverrideHelper.SetXRobotsTagHeaderOverride(_mockContext, configOverride);

            Assert.AreSame(configOverride, _headerConfigurationOverrideHelper.GetXRobotsTagWithOverride(_mockContext));
        }
        public void CreateXRobotsTagResult_DisabledWithNoIndexInOldConfig_ReturnsRemoveXRobotsTagResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration { Enabled = false, NoIndex = true };
            var oldXRobotsTag = new XRobotsTagConfiguration { Enabled = true, NoIndex = true };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag, oldXRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Remove, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
        }
        public void CreateXRobotsTagResult_EnabledWithMultipleDirectives_ReturnsSetXRobotsTagWithDirectivesResult()
        {
            var xRobotsTag = new XRobotsTagConfiguration { Enabled = true, NoIndex = true, NoFollow = true };

            var result = _generator.CreateXRobotsTagResult(xRobotsTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Robots-Tag", result.Name);
            Assert.AreEqual("noindex, nofollow", result.Value);
        }
 internal XRobotsTagOptions()
 {
     Config = new XRobotsTagConfiguration();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="XRobotsTagAttribute"/> class
 /// </summary>
 public XRobotsTagAttribute()
 {
     _config = new XRobotsTagConfiguration { Enabled = true };
     _headerConfigurationOverrideHelper = new HeaderConfigurationOverrideHelper();
     _headerOverrideHelper = new HeaderOverrideHelper();
 }
Exemple #35
0
 internal XRobotsTagOptions()
 {
     Config = new XRobotsTagConfiguration();
 }