コード例 #1
0
        public void NameValuePairRepository_DeleteRange()
        {
            var mockDependency = new Mock <INameValuePairConstraints>();

            mockDependency.Setup(x => x.Match(It.IsAny <NameValuePair>())).Returns(passThrough);
            var target       = new NameValuePairRepository(mockDependency.Object);
            var total        = RandomGenerator.Random.Next(5, 10);
            var pairsDeleted = new List <NameValuePair>();
            var pairsKept    = new List <NameValuePair>();

            for (var i = 0; i < total; i++)
            {
                var pair = new NameValuePair
                {
                    Name  = RandomGenerator.RandomString(),
                    Value = RandomGenerator.RandomString()
                };
                target.Add(pair);
                if (RandomGenerator.RandomBoolean(0.5))
                {
                    pairsDeleted.Add(pair);
                }
                else
                {
                    pairsKept.Add(pair);
                }
            }

            target.RemoveRange(pairsDeleted);
            var list = target.List() as List <NameValuePair>;

            CollectionAssert.AreEqual(pairsKept, list);
        }
コード例 #2
0
        public void NameValuePairRepository_FilterOnName()
        {
            var mockDependency = new Mock <INameValuePairConstraints>();

            mockDependency.Setup(x => x.Match(It.IsAny <NameValuePair>())).Returns(passThrough);
            var target        = new NameValuePairRepository(mockDependency.Object);
            var total         = RandomGenerator.Random.Next(5, 10);
            var pairsFiltered = new List <NameValuePair>();
            var mark          = "FILTERED";

            for (var i = 0; i < total; i++)
            {
                var pair = new NameValuePair
                {
                    Name  = RandomGenerator.RandomString() + mark + RandomGenerator.RandomString(),
                    Value = RandomGenerator.RandomString()
                };
                target.Add(pair);
                pairsFiltered.Add(pair);

                pair = new NameValuePair
                {
                    Name  = RandomGenerator.RandomString(),
                    Value = RandomGenerator.RandomString()
                };
                while (pair.Name.Contains(mark))
                {
                    pair = new NameValuePair
                    {
                        Name  = RandomGenerator.RandomString(),
                        Value = RandomGenerator.RandomString()
                    }
                }
                ;
                target.Add(pair);
            }

            var list = target.Filter(new FilterSetting
            {
                Type  = FilterSetting.ValueType.NAME,
                Value = mark
            }) as List <NameValuePair>;

            CollectionAssert.AreEqual(pairsFiltered, list);
        }
コード例 #3
0
        public void NameValuePairRepository_MatchesConstraintWhenAddingPair()
        {
            var mockDependency = new Mock <INameValuePairConstraints>();
            var target         = new NameValuePairRepository(mockDependency.Object);
            var pair           = new NameValuePair
            {
                Name  = RandomGenerator.RandomString(),
                Value = RandomGenerator.RandomString()
            };

            target.Add(pair);
            mockDependency.Verify(x => x.Match(pair), Times.Once);
        }
コード例 #4
0
        public void NameValuePairRepository_List()
        {
            var mockDependency = new Mock <INameValuePairConstraints>();

            mockDependency.Setup(x => x.Match(It.IsAny <NameValuePair>())).Returns(passThrough);
            var target = new NameValuePairRepository(mockDependency.Object);
            var total  = RandomGenerator.Random.Next(5, 10);
            var pairs  = new List <NameValuePair>();

            for (var i = 0; i < total; i++)
            {
                var pair = new NameValuePair
                {
                    Name  = RandomGenerator.RandomString(),
                    Value = RandomGenerator.RandomString()
                };
                target.Add(pair);
                pairs.Add(pair);
            }

            var list = target.List() as List <NameValuePair>;

            CollectionAssert.AreEqual(pairs, list);
        }