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 TearDown() { Console.WriteLine("TearDown SystemTests"); DevWebServer.Stop(); BrowserApp.Stop(); VstsSettings.RestoreWebConfig(); }
public static void AddTestDocuments() { if (!_isSetup) { return; // DB wasn't touched, so nothing to do here } var dbUri = VstsSettings.GetSetting("dbUri", DefaultDbUri); if (dbUri != DefaultDbUri) { return; // this data is only to help local devs - don't put on live site } using (var repository = New(deleteAllDocuments: false).Register()) { DomainRegistry.ValidationContext = new ValidationContext(true); DomainRegistry.NowUtc = () => DateTime.UtcNow; DomainRegistry.CloudStore = LocalCloudStore.New(clearContainer: false); AddTestBsg(repository, "unitTest"); var coc = AddTestCoc(repository, "unitTest"); AddTestBsg(repository, "unitTestExisting", bsg => { bsg.ApplicantDetails.EmailAddress = coc.UserId; Builder.Modify(bsg) .With(f => f.UserId, coc.UserId) .With(f => f.Declaration, BestStartGrantForms.Dto.DeclarationBuilder.NewValid()) .With(f => f.Completed, DateTime.UtcNow); }); } }
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 ConfigureVsts_with_default_config() { var result = Features.Are.ConfiguredBy.VstsConfig(); var expected = new VstsSettings(); var actual = ((ConfigureVsts)result).Settings; actual.ShouldBeEquivalentTo(expected); }
public void ConfigureVsts_with_custom_settings() { var settings = new VstsSettings { NameField = "CustomSettings" }; var result = Features.Are.ConfiguredBy.VstsConfig().WithSettings(settings); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.NameField.Should().Be("CustomSettings"); }
public void ConfigureVsts_with_Environment() { var settings = new VstsSettings(); var result = Features.Are.ConfiguredBy .VstsConfig() .WithSettings(settings) .WithEnvironment("XXX"); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.AdditionalQueryFilter.Should().Contain("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'"); }
private static void SetUp() { if (_isSetup) { return; } var dbUri = new Uri(VstsSettings.GetSetting("dbUri", DefaultDbUri)); var dbKey = VstsSettings.GetSetting("dbKey", DefaultDbKey); Repository.Init(dbUri, dbKey); _isSetup = true; }
public static void AddEnvironment(this VstsSettings settings, string environment) { if (settings.AdditionalFields.ContainsKey("System.Tags")) { settings.AdditionalFields["System.Tags"] = $"{settings.AdditionalFields["System.Tags"]},{environment}"; } else { settings.AdditionalFields.Add("System.Tags", environment); } settings.AdditionalQueryFilter = $"{settings.AdditionalQueryFilter} and [System.Tags] Contains '{environment}'".TrimStart(); }
private static void SetUp() { if (_isSetup) { return; } var storageConnectionString = VstsSettings.GetSetting("storageConnectionString", DefaultStorageConnectionString); var storageName = VstsSettings.GetSetting("storageName", DefaultStorageName); CloudStore.Init(storageConnectionString, storageName); _isSetup = true; }
public void ConfigureVsts_with_WorkItemType() { var settings = new VstsSettings() { WorkItemType = "Old" }; var result = Features.Are.ConfiguredBy .VstsConfig() .WithSettings(settings) .WithWorkItemType("New"); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.WorkItemType.Should().Be("New"); }
public void ConfigureVsts_with_ValueField() { var settings = new VstsSettings() { ValueField = "Old" }; var result = Features.Are.ConfiguredBy .VstsConfig() .WithSettings(settings) .WithValueField("New"); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.ValueField.Should().Be("New"); }
public void ConfigureVsts_with_CacheTimeout() { var settings = new VstsSettings { CacheTimeout = TimeSpan.FromDays(1) }; var expected = TimeSpan.FromMilliseconds(1); var result = Features.Are.ConfiguredBy .VstsConfig() .WithSettings(settings) .WithCacheTimeout(expected); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.CacheTimeout.Should().Be(expected); }
public void ConfigureVsts_with_PrivateAccessToken() { var settings = new VstsSettings { PrivateAccessToken = "settingspat" }; var expected = "explicit pat"; var result = Features.Are.ConfiguredBy .VstsConfig() .WithSettings(settings) .WithPrivateAccessToken(expected); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.PrivateAccessToken.Should().Be(expected); }
public void ConfigureVsts_with_VSTS_Url() { var settings = new VstsSettings { Url = new Uri("http://settingshost") }; var expected = new Uri("http://explicithost"); var result = Features.Are.ConfiguredBy .VstsConfig() .WithSettings(settings) .WithVSTSUrl(expected); result.Should().NotBeNull(); ((ConfigureVsts)result).Settings.Url.Should().Be(expected); }
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 void VerifyRunning() { var dbUri = VstsSettings.GetSetting("dbUri", DefaultDbUri); if (dbUri != DefaultDbUri) { return; // this is just a check to help local devs } try { using (var tcpClient = new TcpClient()) tcpClient.Connect("localhost", 8081); } catch { Assert.Fail("Could not verify DocumentDB connection - please verify DocumentDB is running"); } }
public static void VerifyRunning() { var storageConnectionString = VstsSettings.GetSetting("storageConnectionString", DefaultStorageConnectionString); if (storageConnectionString != DefaultStorageConnectionString) { return; // this is just a check to help local devs } try { using (var tcpClient = new TcpClient()) tcpClient.Connect("localhost", 10000); } catch { Assert.Fail("Could not verify Azure Blob Storage emulator connection - please verify Storage Emulator is running"); } }
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()); }
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 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); } } }
public void SetUp() { if (TestRegistry.TestHasFailed) { return; // no need to setup Selenium } Console.WriteLine("SetUp SystemTests"); var runHeadless = RunHeadless(); try { VstsSettings.UpdateWebConfig(); DevWebServer.Start(); BrowserApp.Start(runHeadless); } catch { TearDown(); throw; } }
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]); }