Exemplo n.º 1
0
        public void NullHttpContextAccessor_Returns_Empty()
        {
            var provider = new HttpRequestFeatureFlagProvider(null, HeaderName);

            var flags = provider.GetFlags();

            Assert.Empty(flags);
        }
Exemplo n.º 2
0
        public void EmptyHeaders_Returns_Empty()
        {
            var headerValues = new HeaderDictionary();

            IHttpContextAccessor httpContextAccessorMock = GetHttpContextAccessor(headerValues);
            var provider = new HttpRequestFeatureFlagProvider(httpContextAccessorMock, HeaderName);

            var flags = provider.GetFlags();

            Assert.Empty(flags);
        }
Exemplo n.º 3
0
        public void NullHttpContext_Returns_Empty()
        {
            var httpContextAccessorMock = new Mock <IHttpContextAccessor>();

            httpContextAccessorMock.Setup(x => x.HttpContext).Returns((HttpContext)null);

            var provider = new HttpRequestFeatureFlagProvider(httpContextAccessorMock.Object, HeaderName);

            var flags = provider.GetFlags();

            Assert.Empty(flags);
        }
Exemplo n.º 4
0
        public void HeadersContainsKeyButEmpty_Returns_Empty()
        {
            var headerValues = new HeaderDictionary();

            headerValues.Add("X-Test-Header", new StringValues());

            IHttpContextAccessor httpContextAccessorMock = GetHttpContextAccessor(headerValues);
            var provider = new HttpRequestFeatureFlagProvider(httpContextAccessorMock, HeaderName);

            var flags = provider.GetFlags();

            Assert.Empty(flags);
        }
Exemplo n.º 5
0
        public void SingleValue_Returns_OnlyFlagAndEnabled()
        {
            string flagName = nameof(flagName);

            HeaderDictionary headerValues = GetFeatureHeader(flagName);

            IHttpContextAccessor httpContextAccessorMock = GetHttpContextAccessor(headerValues);
            var provider = new HttpRequestFeatureFlagProvider(httpContextAccessorMock, HeaderName);

            var flags = provider.GetFlags();

            var singleFlag = Assert.Single(flags);

            Assert.True(singleFlag.Enabled);
        }
Exemplo n.º 6
0
        public void MultipleCorrectValue_Returns_All_AndRemovesEmptyResults()
        {
            string flagName1 = nameof(flagName1);
            string flagName2 = nameof(flagName2);

            HeaderDictionary headerValues = GetFeatureHeader($"{flagName1};;  ;;{flagName2}");

            IHttpContextAccessor httpContextAccessorMock = GetHttpContextAccessor(headerValues);
            var provider = new HttpRequestFeatureFlagProvider(httpContextAccessorMock, HeaderName);

            var flags = provider.GetFlags();

            Assert.Equal(2, flags.Count());

            var first = flags.ElementAt(0);

            Assert.NotNull(first);
            Assert.Equal(flagName1, first.Name);

            var second = flags.ElementAt(1);

            Assert.NotNull(second);
            Assert.Equal(flagName2, second.Name);
        }