本文整理汇总了C#中Box.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# Box.AddItem方法的具体用法?C# Box.AddItem怎么用?C# Box.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box
的用法示例。
在下文中一共展示了Box.AddItem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Adding_same_item_more_than_once_should_sum_quanitities
public void Adding_same_item_more_than_once_should_sum_quanitities()
{
var box = new Box();
var item = new Item { Name = "Test Item" };
box.AddItem(3, item);
Assert.Equal(3, box.Contents.First().Quantity);
box.AddItem(2, item);
Assert.Equal(5, box.Contents.First().Quantity);
Assert.Equal(1, box.Contents.Count);
}
示例2: Adding_new_item_to_box_should_have_correct_quantity
public void Adding_new_item_to_box_should_have_correct_quantity()
{
var box = new Box();
box.AddItem(3, new Item { Name = "Test Item" });
Assert.Equal(3, box.Contents.First().Quantity);
}
示例3: Adding_item_with_negative_quanity_throws_error
public void Adding_item_with_negative_quanity_throws_error()
{
var box = new Box();
var item = new Item { Name = "Test Item" };
Assert.Throws<InvalidOperationException>(() => box.AddItem(-3, item));
}
示例4: Can_reduce_an_item_without_removing_it
public void Can_reduce_an_item_without_removing_it()
{
var box = new Box();
var item = new Item {Name = "Test Item"};
box.AddItem(2, item);
Assert.Equal(2, box.Contents.First(x => x.Item == item).Quantity);
box.ReduceItem(1, item);
Assert.Equal(1, box.Contents.First(x => x.Item == item).Quantity);
}
示例5: Can_remove_an_item
public void Can_remove_an_item()
{
var box = new Box();
var item = new Item {Name = "Test Item"};
box.AddItem(1, item);
Assert.Equal(1, box.Contents.Count(x => x.Item == item));
box.RemoveItem(item);
Assert.Empty(box.Contents);
}
示例6: Reducing_an_item_by_equal_or_more_than_current_quantity_removes_item
public void Reducing_an_item_by_equal_or_more_than_current_quantity_removes_item()
{
var box = new Box();
var item = new Item {Name = "Test Item"};
box.AddItem(2, item);
Assert.Equal(2, box.Contents.First(x => x.Item == item).Quantity);
box.ReduceItem(2, item);
Assert.Equal(0, box.Contents.Count(x => x.Item == item));
}