Ejemplo n.º 1
0
		private void DistinctListHack(ShopItem[] purchases)
		{
			for (int itemCount = 0; itemCount < purchases.Length; itemCount++)
			{
				var item = purchases[itemCount];
				item.Id += itemCount;
				_basket.Add(item);
			}			
		}
Ejemplo n.º 2
0
		public void AddAllPurchasesToBasket(ShopItem[] purchases)
		{
			if ((_basket as DistinctList<ShopItem>) != null)
				DistinctListHack(purchases);

			for (int itemCount = 0; itemCount < purchases.Length; itemCount++)
			{
				_basket.Add(purchases[itemCount]);
			}
		}
		public void should_not_add_the_same_item_twice()
		{
			var sut = new DistinctList<ShopItem>();

			var item = new ShopItem { Id = 1, Name = "Megaphone", Price = 200m };

			sut.Add(item);
			sut.Add(item);

			Assert.That(sut.Count(), Is.EqualTo(1));
		}
		public void should_be_able_to_get_an_item_using_an_index()
		{
			var sut = new IndexedList<ShopItem>();
			
			var item = new ShopItem { Id = 1, Name = "Megaphone", Price = 200m }; 
			
			sut.Add(item);

			var result = sut.GetItem(0);

			Assert.That(result, Is.EqualTo(item));
		}
		public void should_be_able_to_add_items_to_the_list()
		{
			var sut = new SimpleList<ShopItem>();

			var item1 = new ShopItem {Id = 1, Name = "Megaphone", Price = 200m};

			sut.Add(item1);
			sut.Add(item1);
			sut.Add(item1);

			Assert.That(sut.Count(), Is.EqualTo(3));
		}
		public void client_test_harness()
		{
			//var basket = new SimpleList<ShopItem>();
			//var basket = new IndexedList<ShopItem>();
			var basket = new DistinctList<ShopItem>();

			var client = new Client(basket);

			var item1 = new ShopItem {Id = 1, Name = "Megaphone", Price = 200m};
			var item2 = new ShopItem {Id = 2, Name = "Trumpet", Price = 20m};
			var item3 = new ShopItem {Id = 3, Name = "Telescope", Price = 3200m};
			
			ShopItem[] purchases = {item1, item1, item1, item2, item3, item3};

			client.AddAllPurchasesToBasket(purchases);

			Assert.That(basket.Count(), Is.EqualTo(6));
		}