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);
        }
Esempio n. 2
0
        public void VstsClient_can_create_feature_with_default_config()
        {
            var sut = new VstsClient(Settings.Default.Url, IntegrationTests.GetPAT());

            var task = sut.PutAsync($"Test-Flag-{Guid.NewGuid()}", "true");

            task.GetAwaiter().GetResult();


            var result = task.Result;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
            Assert.AreEqual("Task", result.Fields["System.WorkItemType"]);
            Assert.AreEqual("true", result.Fields["System.Description"]);
        }
Esempio n. 3
0
        public void VstsClient_can_get_empty_features()
        {
            var settings = new VstsSettings {
                AdditionalQueryFilter = "and [System.Tags] Contains 'ThisWillNotExist'"
            };

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

            var task = sut.GetAsync();

            task.GetAwaiter().GetResult();;


            var result = task.Result;

            Assert.IsFalse(result.Any());
        }
        public static async Task DeleteAllDefaultFeatureFlags()
        {
            var settings   = new VstsSettings();
            var testClient = new VstsClient(Settings.Default.Url, IntegrationTests.GetPAT(), settings);

            var query = new Wiql
            {
                Query = $"Select [System.Id] from WorkItems where [System.TeamProject] = '{Settings.Default.Url.LocalPath.Trim('/')}' and [System.WorkItemType] = 'Task' or [System.WorkItemType] = 'FeatureFlag'"
            };

            var result = await testClient.WorkItemTrackingHttpClient.QueryByWiqlAsync(query);

            if (result.WorkItems.Any())
            {
                foreach (var wit in result.WorkItems)
                {
                    await testClient.WorkItemTrackingHttpClient.DeleteWorkItemAsync(wit.Id, destroy : true);
                }
            }
        }
Esempio n. 5
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());
        }
Esempio n. 6
0
        public void VstsClient_can_get_features_with_special_config()
        {
            var config = new VstsSettings
            {
                WorkItemType          = "FeatureFlag",
                ValueField            = "FeatureFlag.Value",
                AdditionalQueryFilter = "and [System.Tags] Contains 'FeatureFlag' and [Microsoft.VSTS.Common.Priority] = 1"
            };

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

            var task = sut.GetAsync();

            task.GetAwaiter().GetResult();;


            var result = task.Result;

            Assert.IsTrue(result.Any());
        }
        public void EndToEnd_flag_gets_created_automatically_for_environment()
        {
            var environmentKey = Guid.NewGuid().ToString();

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

            // the flag should not exist and is created for the new environment
            var state = Feature <Demo.DemoFeature> .Is().Enabled;

            // the new flag should have the state "false" per default.
            state.Should().BeFalse();
        }
Esempio n. 8
0
        public void VstsClient_can_create_feature_with_special_config()
        {
            var config = new VstsSettings
            {
                WorkItemType = "FeatureFlag",
                ValueField   = "FeatureFlag.Value"
            };

            config.AdditionalFields.Add("Microsoft.VSTS.Common.Priority", "1");

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

            var task = sut.PutAsync($"Test-Flag-{Guid.NewGuid()}", "true");

            task.GetAwaiter().GetResult();;


            var result = task.Result;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
            Assert.AreEqual("FeatureFlag", result.Fields["System.WorkItemType"]);
            Assert.AreEqual("true", result.Fields[config.ValueField]);
        }