コード例 #1
0
ファイル: FeatureManagerTests.cs プロジェクト: Morebis-GIT/CI
        public void DependsOnWhenCalledThenShouldReturnParentFeatureFlags()
        {
            var featureOne = new FeatureStateTestData {
                Id = 1, Name = nameof(FeatureName.First), Enabled = false
            };
            var featureTwo = new FeatureStateTestData
            {
                Id        = 2,
                Name      = nameof(FeatureName.Second),
                Enabled   = true,
                ParentIds = new List <int> {
                    1
                }
            };
            var featureThree = new FeatureStateTestData
            {
                Id        = 3,
                Name      = nameof(FeatureName.Third),
                Enabled   = true,
                ParentIds = new List <int> {
                    1, 2
                }
            };

            _ = _mockFeatureSettingsProvider.Setup(p => p.GetForTenant(It.IsAny <int>()))
                .Returns(new[] { featureOne, featureTwo, featureThree });

            _ = _featureManager.Features.Count.Should().Be(3);
            var featureFlagOne =
                _ = _featureManager.Features.FirstOrDefault(x => x.Name.Equals(nameof(FeatureName.First)));

            _ = featureFlagOne.Should().NotBeNull();
            _ = featureFlagOne.DependsOn.Should().BeEmpty();
            var featureFlagTwo =
                _ = _featureManager.Features.FirstOrDefault(x => x.Name.Equals(nameof(FeatureName.Second)));

            _ = featureFlagTwo.Should().NotBeNull();
            _ = featureFlagTwo.DependsOn.Should().ContainSingle(ff => ff.Name.Equals(nameof(FeatureName.First)));
            var featureFlagThree =
                _ = _featureManager.Features.FirstOrDefault(x => x.Name.Equals(nameof(FeatureName.Third)));

            _ = featureFlagThree.Should().NotBeNull();
            _ = featureFlagThree.DependsOn.Should().HaveCount(2);
            _ = featureFlagThree.DependsOn.Should().Contain(ff =>
                                                            ff.Name.Equals(nameof(FeatureName.First)) || ff.Name.Equals(nameof(FeatureName.Second)));
        }
コード例 #2
0
ファイル: FeatureManagerTests.cs プロジェクト: Morebis-GIT/CI
        public void IsEnabledWhenCalledWithChildFeatureThenShouldThrowException(string featureName, bool childEnabled, bool parentEnabled)
        {
            var feature = new FeatureStateTestData {
                Id = 2, Name = featureName, Enabled = childEnabled
            };
            var parentFeature = new FeatureStateTestData {
                Id = 1, Name = Guid.NewGuid().ToString("N"), Enabled = parentEnabled
            };

            feature.ParentIds = new List <int> {
                parentFeature.Id
            };

            _ = _mockFeatureSettingsProvider.Setup(p => p.GetForTenant(It.IsAny <int>()))
                .Returns(new[] { parentFeature, feature });

            _ = _featureManager.IsEnabled(featureName).Should().Be(childEnabled && parentEnabled);
        }
コード例 #3
0
ファイル: FeatureManagerTests.cs プロジェクト: Morebis-GIT/CI
        public void IsEnabledWhenCalledWithNonExistentFeatureNameThenShouldReturnFalse(FeatureStateTestData testData)
        {
            _ = _mockFeatureSettingsProvider.Setup(p => p.GetForTenant(It.IsAny <int>())).Returns(new[]
            {
                new FeatureStateTestData {
                    Name = nameof(FeatureName.Default)
                }
            });

            _ = _featureManager.IsEnabled(testData.Name).Should().Be(false);
        }
コード例 #4
0
ファイル: FeatureManagerTests.cs プロジェクト: Morebis-GIT/CI
        public void GetFeaturesStateWhenCalledWithValidFeatureNameThenShouldReturnFeatureState(FeatureStateTestData testData)
        {
            _ = _mockFeatureSettingsProvider.Setup(p => p.GetForTenant(It.IsAny <int>())).Returns(new[] { testData });

            _ = _featureManager.Features.Count.Should().Be(1);

            var firstFeature = _featureManager.Features.First();

            _ = firstFeature.Name.Should().BeEquivalentTo(testData.Name);
            _ = firstFeature.IsEnabled.Should().Be(testData.Enabled);
            _ = firstFeature.IsShared.Should().Be(testData.IsShared);
        }
コード例 #5
0
ファイル: FeatureManagerTests.cs プロジェクト: Morebis-GIT/CI
        public void IsEnabledWhenCalledWithValidFeatureNameThenShouldReturnFeatureState(FeatureStateTestData testData)
        {
            _ = _mockFeatureSettingsProvider.Setup(p => p.GetForTenant(It.IsAny <int>())).Returns(new[] { testData });

            _ = _featureManager.IsEnabled(testData.Name).Should().Be(testData.Enabled);
        }