Exemplo n.º 1
0
        public void Build_WhenNoValues_ReturnsNull()
        {
            var builder = new FeaturePolicyBuilder();

            var result = builder.Build();

            result.Should().BeNullOrEmpty();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Configure a feature policy.
        /// </summary>
        /// <param name="configure">Configure the Feature-Policy header</param>
        /// <returns>The complete Feature-Policy header</returns>
        public static FeaturePolicyHeader Build(Action <FeaturePolicyBuilder> configure)
        {
            var builder = new FeaturePolicyBuilder();

            configure(builder);

            return(new FeaturePolicyHeader(builder.Build()));
        }
Exemplo n.º 3
0
        public void Build_AddAccelerometer_WhenIncludesAllAndNone_ThrowsInvalidOperationException()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddAccelerometer()
            .None()
            .All();

            Assert.Throws <InvalidOperationException>(() => builder.Build());
        }
Exemplo n.º 4
0
        public void Build_AddSyncXHR_WhenIncludesSelf_WritesSelf()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddSyncXHR().Self();

            var result = builder.Build();

            result.Should().Be("sync-xhr 'self'");
        }
Exemplo n.º 5
0
        public void Build_CustomFeatureDirectiveBuilder_AddsValues()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddCustomFeature("push").None();
            builder.AddCustomFeature("vibrate").All();

            var result = builder.Build();

            result.Should().Be("push 'none'; vibrate *");
        }
Exemplo n.º 6
0
        public void Build_AddingTheSameDirectiveTwice_OverwritesThePreviousCopy()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddAccelerometer().Self();
            builder.AddAccelerometer().None();

            var result = builder.Build();

            result.Should().Be("accelerometer 'none'");
        }
Exemplo n.º 7
0
        public void Build_CustomFeatureDirective_AddsValues()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddCustomFeature("push", "'none'");
            builder.AddCustomFeature("vibrate", "*");
            builder.AddCustomFeature("something-else", string.Empty);

            var result = builder.Build();

            result.Should().Be("push 'none'; vibrate *; something-else");
        }
Exemplo n.º 8
0
        public void Build_AddAccelerometer_WhenAddsMultipleValue_ReturnsAllValues()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddAccelerometer()
            .Self()
            .For("http://testUrl.com");

            var result = builder.Build();

            result.Should().Be("accelerometer 'self' http://testUrl.com");
        }
Exemplo n.º 9
0
        public void Build_AddAccelerometer_WhenIncludesAll_OnlyWritesAll()
        {
            var builder = new FeaturePolicyBuilder();

            builder.AddAccelerometer()
            .Self()
            .For("http://testUrl.com")
            .All();

            var result = builder.Build();

            result.Should().Be("accelerometer *");
        }