public void GetUndefinedAttributeUnsafe() { var testFeature = new TestFeature(); testFeature.Attributes = new DictionaryFeatureAttributeCollection(); var value = FeatureAttributeAccessorHelper.GetAttributeValue(testFeature, "unknown"); Assert.IsNull(value); }
public void GetAllAttributes() { var testFeature = new TestFeature { Attributes = new DictionaryFeatureAttributeCollection {{"attrib", "blah"}} }; var allAttributes = FeatureAttributeAccessorHelper.GetFeatureAttributeNames(testFeature); Assert.AreEqual(new[] { "attrib", "Other", "Name" }, allAttributes); }
public void Features_ReturnsFeatures() { // Arrange var feature = new TestFeature(); var provider = new FeatureProvider(new IFeature[] { feature }); // Act var features = provider.Features; // Assert Assert.NotNull(features); Assert.Contains(features, f => f == feature); }
public void SetFeature_UpdateExisting_ReturnsUpdatedFeature() { var alternativeFeature = new TestFeature(); featureSet.SetFeature <TestFeature>(testFeature); featureSet.SetFeature <TestFeature>(alternativeFeature); var retrievedFeature = featureSet.GetFeature <TestFeature>(); CMSAssert.All( () => Assert.AreEqual(alternativeFeature, retrievedFeature, "SetFeature didn't update the original feature."), () => Assert.AreNotEqual(testFeature, retrievedFeature, "Retrieved feature was the same as original feature.") ); }
public void IsEnabled_WithProvider_QueriesSuppliedProvider() { var mockProvider = new Mock <IFeatureSettingValueProvider>(); var basicFeature = new TestFeature { SettingValueProvider = mockProvider.Object }; mockProvider.Setup( p => p.GetSetting(It.Is <IFeature>(f => f == basicFeature), It.IsAny <IDefaultSettingStrategy>(), It.IsAny <string>())) .Returns(new FeatureValue(string.Empty)); var result = basicFeature.IsEnabled; mockProvider.Verify(p => p.GetSetting(It.Is <IFeature>(f => f == basicFeature), It.IsAny <IDefaultSettingStrategy>(), It.IsAny <string>())); }
public void IsEnabled_Always_PassesDefaultSettingStrategyIntoValueProvider() { var mockProvider = new Mock <IFeatureSettingValueProvider>(); var mockStrategy = new Mock <IDefaultSettingStrategy>(); var basicFeature = new TestFeature { SettingValueProvider = mockProvider.Object, DefaultIsEnabledSettingStrategy = mockStrategy.Object }; mockProvider.Setup( p => p.GetSetting(It.IsAny <IFeature>(), It.Is <IDefaultSettingStrategy>(s => s == mockStrategy.Object), It.IsAny <string>())) .Returns(new FeatureValue(string.Empty)); var result = basicFeature.IsEnabled; mockProvider.Verify(p => p.GetSetting(It.IsAny <IFeature>(), It.Is <IDefaultSettingStrategy>(s => s == mockStrategy.Object), It.IsAny <string>())); }
public void GetAttributeFast() { var testFeature = new TestFeature(); testFeature.Attributes = new DictionaryFeatureAttributeCollection(); object value; TestHelper.AssertIsFasterThan(70, () => { for (int i = 0; i < 10000; i++) { value = FeatureAttributeAccessorHelper.GetAttributeValue( testFeature, "Other", false); } }); }
public void PopulateFeature_SkipProviders_ForOtherFeatures() { // Arrange var manager = new PartManager(); manager.Parts.Add(new OtherPart("OtherPart")); manager.PartFeatureProviders.Add( new TestPartFeatureProvider((f, n) => f.Values.Add($"TestPartFeatureProvider{n}"))); var feature = new TestFeature(); // Act manager.PopulateFeature(feature); // Assert Assert.Empty(feature.Values.ToArray()); }
[Category(TestCategory.WorkInProgress)] // slow public void GetAttributeFast() { var testFeature = new TestFeature(); testFeature.Attributes = new DictionaryFeatureAttributeCollection(); object value; TestHelper.AssertIsFasterThan(100, () => { for (int i = 0; i < 10000; i++) { value = FeatureAttributeAccessorHelper.GetAttributeValue( testFeature, "Other", false); } }); }
private static void GetTests(string folderPath, TestFolder parentFolder, IMessageLogger logger) { if (string.IsNullOrEmpty(folderPath)) { return; } foreach (string source in Directory.EnumerateDirectories(folderPath)) { TestFolder folder = new TestFolder { Name = Path.GetFileNameWithoutExtension(source), Path = source }; GetTests(source, folder, logger); if (folder.Folders.Count > 0 || folder.Files.Count > 0) { parentFolder.Folders.Add(folder); } } foreach (string source in Directory.EnumerateFiles(folderPath, $"*{Constant.TestsPs1}")) { TestFile file = new TestFile { Name = Path.GetFileNameWithoutExtension(source), Path = source }; if (DiscoverPesterTests(source, file.Describes, logger)) { if (file.Describes.Count > 0) { parentFolder.Files.Add(file); } } } foreach (string source in Directory.EnumerateFiles(folderPath, $"*{Constant.Feature}")) { TestFeature feature = DiscoverPesterFeatures(source, null); if (feature != null) { parentFolder.Features.Add(feature); } } }
static XElement WriteTestFeature(TestFeature instance) { var element = new XElement("TestFeature"); element.SetAttributeValue("Name", instance.Name); if (instance.Description != null) { element.SetAttributeValue("Description", instance.Description); } if (instance.DefaultValue != null) { element.SetAttributeValue("DefaultValue", instance.DefaultValue); } if (instance.Constant != null) { element.SetAttributeValue("Constant", instance.Constant); } return(element); }
public void PopulateFeature_InvokesOnlyProviders_ForAGivenFeature() { // Arrange var manager = new PartManager(); manager.Parts.Add(new TestPart("TestPart")); manager.PartFeatureProviders.Add( new TestPartFeatureProvider((f, n) => f.Values.Add($"TestPartFeatureProvider{n}"))); manager.PartFeatureProviders.Add( new OtherPartFeatureProvider((f, n) => f.Values.Add($"OtherPartFeatureProvider{n}"))); var feature = new TestFeature(); var expectedResults = new[] { "TestPartFeatureProviderTestPart" }; // Act manager.PopulateFeature(feature); // Assert Assert.Equal(expectedResults, feature.Values.ToArray()); }
public void GetFeatureState_ReturnsEnabledFeatureState_WhenConfigurationMissing_AndFeatureEnabledByDefault() { // Arrange var moduleId = new ModuleId("Test"); var featureId = new FeatureId(moduleId, "FeatureA"); var feature = new TestFeature(featureId, enabledByDefault: true); var featureProvider = CreateFeatureProvider(feature); var configuration = CreateConfiguration(new Dictionary <string, string> { }); var featureStateProvider = new FeatureStateProvider(featureProvider, configuration); // Act var state = featureStateProvider.GetFeatureState(featureId); // Assert Assert.NotNull(state); Assert.Equal(featureId, state.FeatureId); Assert.True(state.Enabled); Assert.NotNull(state.ConfigurationSection); }
public void GetFeatureState_ReturnsDisabledFeatureState_ForNestedBooleanValue() { // Arrange var moduleId = new ModuleId("Test"); var featureId = new FeatureId(moduleId, "FeatureA"); var feature = new TestFeature(featureId); var featureProvider = CreateFeatureProvider(feature); var configuration = CreateConfiguration(new Dictionary <string, string> { ["Features:Test.FeatureA:Enabled"] = "false" }); var featureStateProvider = new FeatureStateProvider(featureProvider, configuration); // Act var state = featureStateProvider.GetFeatureState(featureId); // Assert Assert.NotNull(state); Assert.Equal(featureId, state.FeatureId); Assert.False(state.Enabled); Assert.NotNull(state.ConfigurationSection); }
protected static TestFeature DiscoverPesterFeatures(string source, IMessageLogger logger) { if (!File.Exists(source)) { return(null); } Gherkin.Parser parser = new Gherkin.Parser(); GherkinDocument document = parser.Parse(source); TestFeature feature = new TestFeature { Name = Path.GetFileNameWithoutExtension(source), Path = source, Document = document }; foreach (ScenarioDefinition scenario in document.Feature.Children) { if (scenario is ScenarioOutline outline) { foreach (Examples example in outline.Examples) { TestScenario testScenario = new TestScenario() { Name = $"{scenario.Name}\n Examples:{example.Name}", Path = source, Scenario = scenario }; feature.Scenarios.Add(testScenario); foreach (TableRow row in example.TableBody) { foreach (Step step in scenario.Steps) { TestStep testStep = new TestStep() { Name = step.Text, Path = source, Step = step }; testScenario.Steps.Add(testStep); } } } } else { TestScenario testScenario = new TestScenario() { Name = scenario.Name, Path = source, Scenario = scenario }; feature.Scenarios.Add(testScenario); foreach (Step step in scenario.Steps) { TestStep testStep = new TestStep() { Name = step.Text, Path = source, Step = step }; testScenario.Steps.Add(testStep); } } } if (feature.Scenarios.Count == 0) { return(null); } return(feature); }
public void OneTimeSetUp() { testFeature = new TestFeature(); }
public TestFeatureModel(TestFeature feature) { Feature = feature; }
public void TestGetHashCodeMatch() { var feature1 = new TestFeature(nameof(TestFeature)); feature1.GetHashCode().Should().Be(feature1.GetHashCode()); }
public void ToggledFeatureShouldBeEnabledIfConfiguredSoInAppSettings() { testFeature = new TestFeature(); Assert.That(testFeature.IsFeatureEnabled(), Is.True); }
public void GetAttributeDisplayNameInAttributeCollection() { var feature = new TestFeature(); feature.Attributes = new DictionaryFeatureAttributeCollection(); feature.Attributes["Jan"] = 3; var displayName = FeatureAttributeAccessorHelper.GetAttributeDisplayName(feature, "Jan"); Assert.AreEqual("Jan", displayName); }
public AttributeMapper(TestFeature feature) { _feature = feature; }
public void Add(TestFeature feature) { features.Add(feature); }
public void GetAttributeDisplayNameNonExistentProperty() { var feature = new TestFeature(); feature.Attributes = new DictionaryFeatureAttributeCollection(); feature.Attributes["Jan"] = 3; var displayName = FeatureAttributeAccessorHelper.GetAttributeDisplayName(feature, "Piet"); }