Beispiel #1
0
 public ActionResult List()
 {
     return(Json(manager.LoadBasket <Basket>(BasketId)));
 }
        public void CreateFruitAndBasket()
        {
            BasketCreateRequest basketCreateRequest = new BasketCreateRequest();

            basketCreateRequest.Fruit.Add(CreateApple <FujiApple>());
            basketCreateRequest.Fruit.Add(CreateApple <GalaApple>());
            basketCreateRequest.Fruit.Add(CreateApple <HoneycrispApple>());

            basketCreateRequest.Fruit.Add(CreateOrange <BloodOrange>());
            basketCreateRequest.Fruit.Add(CreateOrange <NavelOrange>());
            basketCreateRequest.Fruit.Add(CreateOrange <ValenciaOrange>());

            for (int i = 0; i < 3; i++)
            {
                basketCreateRequest.Fruit.Add(CreateBanana());
            }

            Dictionary <string, int> entityTypeCounts = dataManager.GetEntityTypeCounts();

            foreach (string entityType in new string[] { "FujiApple", "GalaApple", "HoneycrispApple", "BloodOrange", "NavelOrange", "ValenciaOrange" })
            {
                Assert.True(entityTypeCounts.ContainsKey(entityType));
                Assert.AreEqual(1, entityTypeCounts[entityType]);
            }
            Assert.True(entityTypeCounts.ContainsKey("Banana"));
            Assert.AreEqual(3, entityTypeCounts["Banana"]);
            Assert.False(entityTypeCounts.ContainsKey("EmpireApple"));

            manager.CreateBasket(basketCreateRequest);

            BasketByIds        b1 = manager.LoadBasket <BasketByIds>(basketCreateRequest.Id);
            BasketByReferences b2 = manager.LoadBasket <BasketByReferences>(basketCreateRequest.Id);
            BasketByOjects     b3 = manager.LoadBasket <BasketByOjects>(basketCreateRequest.Id);

            Assert.AreEqual(basketCreateRequest.Fruit.Count, b1.Fruit.Count);
            Assert.AreEqual(basketCreateRequest.Fruit.Count, b2.Fruit.Count());
            Assert.AreEqual(basketCreateRequest.Fruit.Count, b3.Fruit.Count());

            for (var i = 0; i < 9; i++)
            {
                Assert.AreEqual(basketCreateRequest.Fruit[i], b1.Fruit[i]);
                Assert.AreEqual(basketCreateRequest.Fruit[i], b2.Fruit.ElementAt(i).Id);
                Assert.AreEqual(basketCreateRequest.Fruit[i], b3.Fruit.ElementAt(i).Id);
            }

            Assert.IsInstanceOf <FujiAppleReference>(b2.Fruit.ElementAt(0));
            Assert.IsInstanceOf <FujiApple>(b3.Fruit.ElementAt(0));
            Assert.IsInstanceOf <GalaAppleReference>(b2.Fruit.ElementAt(1));
            Assert.IsInstanceOf <GalaApple>(b3.Fruit.ElementAt(1));
            Assert.IsInstanceOf <HoneycrispAppleReference>(b2.Fruit.ElementAt(2));
            Assert.IsInstanceOf <HoneycrispApple>(b3.Fruit.ElementAt(2));
            Assert.IsInstanceOf <BloodOrangeReference>(b2.Fruit.ElementAt(3));
            Assert.IsInstanceOf <BloodOrange>(b3.Fruit.ElementAt(3));
            Assert.IsInstanceOf <NavelOrangeReference>(b2.Fruit.ElementAt(4));
            Assert.IsInstanceOf <NavelOrange>(b3.Fruit.ElementAt(4));
            Assert.IsInstanceOf <ValenciaOrangeReference>(b2.Fruit.ElementAt(5));
            Assert.IsInstanceOf <ValenciaOrange>(b3.Fruit.ElementAt(5));

            for (var i = 6; i < 9; i++)
            {
                Assert.IsInstanceOf <BananaReference>(b2.Fruit.ElementAt(i));
                Assert.IsInstanceOf <Banana>(b3.Fruit.ElementAt(i));
            }

            Assert.AreEqual(3, b3.Fruit.OfType <Apple>().Count());
            Assert.AreEqual(3, b3.Fruit.OfType <Apple>().Where(x => x.Color == "red").Count());
        }