Exemple #1
0
        public void GetSegmentNamesTest()
        {
            // Arrange.
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

            // Act & Assert.
            var result = segmentCache.GetSegmentNames();

            Assert.AreEqual(0, result.Count);

            var keys = new List <string> {
                "abcd", "1234"
            };
            var segmentName = "test";

            segmentCache.AddToSegment(segmentName, keys);
            segmentCache.AddToSegment($"{segmentName}-1", keys);
            segmentCache.AddToSegment($"{segmentName}-2", keys);

            result = segmentCache.GetSegmentNames();
            Assert.AreEqual(3, result.Count);
            Assert.IsTrue(result.Contains(segmentName));
            Assert.IsTrue(result.Contains($"{segmentName}-1"));
            Assert.IsTrue(result.Contains($"{segmentName}-2"));
        }
Exemple #2
0
        public void GetSegmentKeysTest()
        {
            // Arrange.
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());
            var keys         = new List <string> {
                "abcd", "1234"
            };
            var segmentName = "test";

            segmentCache.AddToSegment(segmentName, keys);

            // Act & Assert.
            var result = segmentCache.GetSegmentKeys(segmentName);

            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(result.Contains("abcd"));
            Assert.IsTrue(result.Contains("1234"));

            var otherSegment = "segmentName";
            var otherKeys    = new List <string>();

            result = segmentCache.GetSegmentKeys(otherSegment);
            Assert.AreEqual(0, result.Count);

            segmentCache.AddToSegment(otherSegment, otherKeys);
            result = segmentCache.GetSegmentKeys(otherSegment);
            Assert.AreEqual(0, result.Count);
        }
Exemple #3
0
        public void SetAndGetChangeNumberTest()
        {
            //Arrange
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());
            var segmentName  = "test";

            //Act
            segmentCache.AddToSegment(segmentName, null);
            segmentCache.SetChangeNumber(segmentName, 1234);
            var result = segmentCache.GetChangeNumber(segmentName);

            //Assert
            Assert.AreEqual(1234, result);
        }
Exemple #4
0
        public void IsNotInSegmentTest()
        {
            //Arrange
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());
            var keys         = new List <string> {
                "1234"
            };
            var segmentName = "test";

            //Act
            segmentCache.AddToSegment(segmentName, keys);
            var result = segmentCache.IsInSegment(segmentName, "abcd");

            //Assert
            Assert.IsFalse(result);
        }
        public void MatchShouldReturnFalseIfSegmentEmptyWithKey()
        {
            //Arrange
            var segmentName  = "test-segment";
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

            segmentCache.AddToSegment(segmentName, null);

            var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache);

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

            //Assert
            Assert.IsFalse(result);
        }
Exemple #6
0
        public void RemoveKeyFromSegmentTest()
        {
            //Arrange
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());
            var keys         = new List <string> {
                "1234"
            };
            var segmentName = "test";

            //Act
            segmentCache.AddToSegment(segmentName, keys);
            var result = segmentCache.IsInSegment(segmentName, "1234");

            segmentCache.RemoveFromSegment(segmentName, keys);
            var result2 = segmentCache.IsInSegment(segmentName, "1234");

            //Assert
            Assert.IsTrue(result);
            Assert.IsFalse(result2);
        }
        public void MatchShouldReturnTrueOnMatchingSegment()
        {
            //Arrange
            var keys = new List <string>();

            keys.Add("test1");
            keys.Add("test2");

            var segmentName  = "test-segment";
            var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary <string, Segment>());

            segmentCache.AddToSegment(segmentName, keys);

            var matcher = new UserDefinedSegmentMatcher(segmentName, segmentCache);

            //Act
            var result = matcher.Match("test2");

            //Assert
            Assert.IsTrue(result);
        }