public JsonResult GetAllProducts(Currency?currency)
        {
            ProductDataConsolidator productDataConsolidator = new ProductDataConsolidator();
            var products = productDataConsolidator.GetAll(currency);

            return(Json(new { Success = true, products = JsonConvert.SerializeObject(products) }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public void GetAllProducts(Currency?currency)
        {
            string expected1 = ProductType.Lawnmover.ToString();
            string expected2 = ProductType.PhoneCase.ToString();
            string expected3 = ProductType.TShirt.ToString();

            var productConsolidator = new ProductDataConsolidator();
            var result = productConsolidator.GetAll(currency);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Where(x => x.Type.Equals(expected1)).Select(x => x.Type).FirstOrDefault());
            Assert.IsNotNull(result.Where(x => x.Type.Equals(expected2)).Select(x => x.Type).FirstOrDefault());
            Assert.IsNotNull(result.Where(x => x.Type.Equals(expected3)).Select(x => x.Type).FirstOrDefault());
        }
Пример #3
0
        public void TestRate()
        {
            var consolidator = new ProductDataConsolidator();

            var l = new LawnmowerRepository();
            var p = new PhoneCaseRepository();
            var t = new TShirtRepository();

            var lawnmowers = l.GetAll();
            var phoneCases = p.GetAll();
            var tshirts    = t.GetAll();

            consolidator.Consolidate(lawnmowers);
            consolidator.Consolidate(phoneCases);
            consolidator.Consolidate(tshirts);

            var products = consolidator.GetAll();

            var rate = 0.67;

            consolidator.Rate = 0.67;

            var i = 0;

            foreach (var lawnmower in lawnmowers)
            {
                AssertEqual(products[i++], lawnmower, rate);
            }


            foreach (var phoneCase in phoneCases)
            {
                AssertEqual(products[i++], phoneCase, rate);
            }


            foreach (var tshirt in tshirts)
            {
                AssertEqual(products[i++], tshirt, rate);
            }
        }
Пример #4
0
        public void GetAll()
        {
            var lawnmowerRepoMock = GetRepositoryMock(
                new[]
            {
                new Lawnmower
                {
                    Id             = Guid.NewGuid(),
                    Name           = "RideOn Lawnmower1",
                    Price          = 1.0,
                    FuelEfficiency = "efficient",
                    IsVehicle      = true
                }
            }
                );
            var phoneCaseRepoMock = GetRepositoryMock(
                new[]
            {
                new PhoneCase
                {
                    Id          = Guid.NewGuid(),
                    Name        = "Fancy",
                    Price       = 20.0,
                    Colour      = "red gofaster stripes",
                    Material    = "diamond",
                    TargetPhone = "All your phone are belong to us!"
                },
                new PhoneCase
                {
                    Id          = Guid.NewGuid(),
                    Name        = "Boring",
                    Price       = 0.11,
                    Colour      = "brown",
                    Material    = "wood",
                    TargetPhone = "flip fones"
                }
            }
                );
            var teeShirtRepoMock = GetRepositoryMock(
                new[]
            {
                new TShirt
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Minecraft",
                    Colour    = "Green",
                    Price     = 81.24,
                    ShirtText = "CreeperFace"
                }
            }
                );


            var consolidator = new ProductDataConsolidator(
                lawnmowerRepoMock.Object,
                phoneCaseRepoMock.Object,
                teeShirtRepoMock.Object
                );


            var products = consolidator.GetAll()
                           .ToList();


            Assert.AreEqual(4, products.Count, "Count mismatch!");
            CollectionAssert.AllItemsAreNotNull(products, "Contains null!");
            CollectionAssert.AllItemsAreInstancesOfType(products, typeof(Product), "Bad type contents!");
            CollectionAssert.AllItemsAreUnique(products, "Doubleup!");
            Assert.AreEqual(1, products.Count(p => p.Type == "Lawnmower"), "lawn count!");
            Assert.AreEqual(2, products.Count(p => p.Type == "Phone Case"), "case count!");
            Assert.AreEqual(1, products.Count(p => p.Type == "T-Shirt"), "shirt count!");
        }