public DepenendencyRule(Severity severity, LibraryMatcher source, LibraryMatcher target, DependencyMatcher dependency, bool allow,
     ConfigLocation location)
     : base(severity, location)
 {
     Source = source ?? ((l, r) => true);
     Target = target ?? ((l, r) => true);
     Dependency = dependency ?? ((d, r) => true);
     Allow = allow;
 }
Esempio n. 2
0
        public void MatchShouldReturnFalseIfNullSplitClient()
        {
            //Arrange
            var          treatments  = new List <string>();
            var          matcher     = new DependencyMatcher("test1", treatments);
            ISplitClient splitClient = null;

            //Act
            var result = matcher.Match(new Key("test2", "test2"), null, splitClient);

            //Assert
            Assert.IsFalse(result);
        }
Esempio n. 3
0
        public void MatchShouldReturnFalseIfEmptyTreatmentList()
        {
            //Arrange
            var treatments      = new List <string>();
            var matcher         = new DependencyMatcher("test1", treatments);
            var splitClientMock = new Mock <ISplitClient>();

            splitClientMock.Setup(x => x.GetTreatment("test", "test1", null, false, false)).Returns("on");

            //Act
            var result = matcher.Match(new Key("test2", "test2"), null, splitClientMock.Object);

            //Assert
            Assert.IsFalse(result);
        }
Esempio n. 4
0
        public void MatchShouldReturnTrueOnMatchingKey()
        {
            //Arrange
            var treatments = new List <string>()
            {
                "on"
            };
            var matcher         = new DependencyMatcher("test1", treatments);
            var splitClientMock = new Mock <ISplitClient>();
            var key             = new Key("test", "test");

            splitClientMock.Setup(x => x.GetTreatment(key, "test1", null, false, false)).Returns("on");
            //Act
            var result = matcher.Match(key, null, splitClientMock.Object);

            //Assert
            Assert.IsTrue(result);
        }
Esempio n. 5
0
        public void MatchShouldReturnFalseIfEmptyTreatmentList()
        {
            //Arrange
            var treatments    = new List <string>();
            var matcher       = new DependencyMatcher("test1", treatments);
            var key           = new Key("test2", "test2");
            var evaluatorMock = new Mock <IEvaluator>();

            evaluatorMock
            .Setup(mock => mock.EvaluateFeature(key, "test1", null))
            .Returns(new TreatmentResult("label", "on"));

            //Act
            var result = matcher.Match(key, null, evaluatorMock.Object);

            //Assert
            Assert.IsFalse(result);
        }
Esempio n. 6
0
        private bool ParseRule(string line, ConfigLocation location, string separator, Severity severity, DependencyMatcher dependencyFilter)
        {
            var pos = line.IndexOf(separator, StringComparison.Ordinal);
            if (pos < 0)
                return false;

            var left = ParseLibraryMatcher(line.Substring(0, pos)
                .Trim(), location);
            var right = ParseLibraryMatcher(line.Substring(pos + separator.Length)
                .Trim(), location);

            config.Rules.Add(new DepenendencyRule(severity, left, right, dependencyFilter, separator == DEPENDS, location));

            return true;
        }
Esempio n. 7
0
        private static UniqueProjectRule NewUniqueNameProjectRule(ConfigLocation l, Severity s, DependencyMatcher d)
        {
            if (d != null)
                throw new ConfigParserException(l, "No dependency details are possible in project rules");

            return new UniqueProjectRule(p => p.ProjectName != null, p => p.Name, p => "named " + p.Name, s, l);
        }
Esempio n. 8
0
        private static UniqueProjectRule NewUniqueGuidProjectRule(ConfigLocation l, Severity s, DependencyMatcher d)
        {
            if (d != null)
                throw new ConfigParserException(l, "No dependency details are possible in project rules");

            return new UniqueProjectRule(p => p.Guid != null, p => p.Guid.ToString(), p => "with GUID " + p.Guid, s, l);
        }
Esempio n. 9
0
        private static NoCircularDepenendenciesRule NewNoCircularDepenendenciesRule(ConfigLocation l, Severity s, DependencyMatcher d)
        {
            if (d != null)
                throw new ConfigParserException(l, "No dependency details are possible in project rules");

            return new NoCircularDepenendenciesRule(s, l);
        }
 public UniqueDependenciesRule(Severity severity, DependencyMatcher filter, ConfigLocation location)
     : base(severity, location)
 {
     this.filter = filter ?? ((d, r) => true);
 }
Esempio n. 11
0
        public static DependencyMatcher And(this DependencyMatcher p1, DependencyMatcher p2)
        {
            if (p1 == null)
                return p2;

            if (p2 == null)
                return p1;

            return (a1, a2) => p1(a1, a2) && p2(a1, a2);
        }