Beispiel #1
0
        public async Task happy_path_test_version1()
        {
            _server.Given(
                Request
                .Create()
                .WithPath("/features")
                .WithHeader("Accept", "application/json")
                .UsingGet())
            .RespondWith(
                Response
                .Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBodyFromFile("resources/features-v1.json")
                );

            var uri               = new Uri("http://localhost:" + _server.Ports.First());
            var config            = UnleashConfig.TheBuilder().AppName("test").UnleashAPI(uri).Build();
            var httpToggleFetcher = new HttpToggleFetcher(config);
            var response          = await httpToggleFetcher.FetchToggles();

            var featureX = response.ToggleCollection.GetToggle("featureX");

            Assert.True(featureX.IsEnabled);
        }
Beispiel #2
0
        public async Task should_handle_errors()
        {
            var httpCodes = new[] { 400, 401, 403, 404, 500, 503 };

            foreach (var httpCode in httpCodes)
            {
                _server.Given(
                    Request
                    .Create()
                    .WithPath("/features")
                    .WithHeader("Accept", "application/json")
                    .UsingGet())
                .RespondWith(
                    Response
                    .Create()
                    .WithStatusCode(httpCode)
                    .WithHeader("Content-Type", "application/json")
                    );


                var uri               = new Uri("http://localhost:" + _server.Ports.First());
                var config            = UnleashConfig.TheBuilder().AppName("test").UnleashAPI(uri).Build();
                var httpToggleFetcher = new HttpToggleFetcher(config);
                var response          = await httpToggleFetcher.FetchToggles();

                Assert.False(response.IsChanged);
            }
        }
Beispiel #3
0
        public void given_empty_body()
        {
            _server.Given(
                Request
                .Create()
                .WithPath("/features")
                .WithHeader("Accept", "application/json")
                .UsingGet())
            .RespondWith(
                Response
                .Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                );


            var uri               = new Uri("http://localhost:" + _server.Ports.First());
            var config            = UnleashConfig.TheBuilder().AppName("test").UnleashAPI(uri).Build();
            var httpToggleFetcher = new HttpToggleFetcher(config);

            Assert.ThrowsAnyAsync <Exception>(async() => await httpToggleFetcher.FetchToggles());
        }