示例#1
0
        public void AddWithItemCount()
        {
            var set = new ItemSet();
            var itemWithoutStack = new Item {
                Id = "test_1", ShortDescr = "Test1"
            };

            set.Add(itemWithoutStack, 1);
            Assert.AreEqual(1, set.CountItems("test_1"));

            set.Add(itemWithoutStack, 3);
            Assert.AreEqual(4, set.CountItems("test_1"));


            var itemWithoutStack2 = new Item {
                Id = "test_2", ShortDescr = "Test2"
            };

            set.Add(itemWithoutStack2, 2);
            Assert.AreEqual(2, set.CountItems("test_2"));


            var itemWithLimitedStack = new Item {
                Id = "test_3", ShortDescr = "Test3", MaxCount = 5
            };

            itemWithLimitedStack.AddQuantity(1);

            set.Add(itemWithLimitedStack, 1);
            Assert.AreEqual(1, set.CountItems("test_3"));

            set.Add(itemWithLimitedStack, 1);
            Assert.AreEqual(2, set.CountItems("test_3"));
            Assert.AreEqual(1, set.Count(item => item.Id == "test_3"));

            set.Add(itemWithLimitedStack, 4);
            Assert.AreEqual(6, set.CountItems("test_3"));
            Assert.AreEqual(2, set.Count(item => item.Id == "test_3"));

            set.Add(itemWithLimitedStack, 100);
            Assert.AreEqual(106, set.CountItems("test_3"));
            Assert.AreEqual(22, set.Count(item => item.Id == "test_3"));


            var itemWithUnlimitedStack = new Item {
                Id = "test_4", ShortDescr = "Test3", MaxCount = 0
            };

            itemWithUnlimitedStack.AddQuantity(1);

            set.Add(itemWithUnlimitedStack, 1);
            Assert.AreEqual(1, set.CountItems("test_4"));

            set.Add(itemWithUnlimitedStack, 200);
            Assert.AreEqual(201, set.CountItems("test_4"));
        }