public void EndToEnd_gets_the_correct_flag_for_environment()
        {
            var environmentKey = Guid.NewGuid().ToString();

            var testSettings = new VstsSettings();

            testSettings.AddEnvironment(environmentKey);

            var testClient = new VstsClient(Settings.Default.Url, IntegrationTests.GetPAT(), testSettings);
            var task       = testClient.PutAsync("Demo.DemoFeature", "True");

            task.GetAwaiter().GetResult();;

            var id = task.Result.Id;


            Features.Are
            .NamedBy
            .TypeFullName()
            .And
            .ConfiguredBy
            .VstsConfig()
            .WithVSTSUrl(Settings.Default.Url)
            .WithPrivateAccessToken(IntegrationTests.GetPAT())
            .WithEnvironment(environmentKey)
            .WithCacheTimeout(TimeSpan.FromMilliseconds(100))
            .PreloadedFeatures()
            .GetAwaiter().GetResult();



            Feature <Demo.DemoFeature> .Is().Enabled.Should().BeTrue();

            // turn off the feature
            var doc = new JsonPatchDocument();

            doc.Add(new JsonPatchOperation
            {
                Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Replace,
                Path      = "/fields/" + testSettings.ValueField,
                Value     = "False"
            });

            var t = testClient.WorkItemTrackingHttpClient.UpdateWorkItemAsync(doc, id);

            t.GetAwaiter().GetResult();

            // give the cache time to expire
            Thread.Sleep(100);

            // get value from cache
            Feature <Demo.DemoFeature> .Is().Enabled.Should().BeTrue();

            // give the operation in the background time to finish
            Thread.Sleep(2000);

            Feature <Demo.DemoFeature> .Is().Enabled.Should().BeFalse();

            testClient.WorkItemTrackingHttpClient.DeleteWorkItemAsync(id, destroy: true);
        }
        public void VstsEnvironments_can_add_environment_to_default_settings()
        {
            var settings = new VstsSettings();

            settings.AddEnvironment("XXX");

            settings.AdditionalFields["System.Tags"].Should().Be("FeatureFlag,XXX");
            settings.AdditionalQueryFilter.Should().Be("and [System.Tags] Contains 'FeatureFlag' and [System.Tags] Contains 'XXX'");
        }
        public void VstsEnvironments_can_add_environment_to_settings_without_tags()
        {
            var settings = new VstsSettings();

            settings.AdditionalFields.Clear();
            settings.AdditionalQueryFilter = "";

            settings.AddEnvironment("XXX");

            settings.AdditionalFields["System.Tags"].Should().Be("XXX");
            settings.AdditionalQueryFilter.Should().Be("and [System.Tags] Contains 'XXX'");
        }
예제 #4
0
        public void VstsClient_can_get_features_with_default_config()
        {
            var settings = new VstsSettings();

            settings.AddEnvironment(Guid.NewGuid().ToString());

            var sut = new VstsClient(Settings.Default.Url, IntegrationTests.GetPAT(), settings);

            // make sure on eitem exists
            sut.PutAsync($"Test-Flag-{Guid.NewGuid()}", "true").GetAwaiter().GetResult();

            var task = sut.GetAsync();

            task.GetAwaiter().GetResult();;


            var result = task.Result;

            Assert.IsTrue(result.Any());
        }