Beispiel #1
0
        private static void TestBagOperation(IBag <Order> bag)
        {
            var total = 0;

            for (var i = 0; i < 1000; i++)
            {
                bag.Add(new Order {
                    Id = i + 1
                }, i + 1);
                total += i + 1;
            }

            var itemNumber = 0;

            foreach (var item in bag)
            {
                itemNumber++;
            }
            Assert.Equal(itemNumber, bag.Count);

            Assert.Equal(total, bag.Count);

            for (var i = 0; i < 1000; i++)
            {
                var count = bag[new Order {
                                    Id = i + 1
                                }];
                Assert.Equal(count, i + 1);
                Assert.True(bag.Contains(new Order {
                    Id = i + 1
                }));
            }

            for (var i = 2000; i < 3000; i++)
            {
                Assert.False(bag.Contains(new Order {
                    Id = i
                }));
            }

            Assert.Equal(1000, bag.ToUnique().Count);

            for (var i = 400; i < 600; i++)
            {
                Assert.True(bag.Remove(new Order {
                    Id = i
                }, 100));
                total -= 100;
                Assert.Equal(total, bag.Count);
            }

            Assert.Equal(1000, bag.ToUnique().Count);

            bag.Clear();
            Assert.Equal(0, bag.Count);
        }