Esempio n. 1
0
        public void Get_Featured()
        {
            // arrange
            var category1 = new Category()
            {
                Name = "Category 1"
            };

            PetaPocoCategoryService.Add(category1);
            var product1 = new Product()
            {
                Name = "Product 1", Price = 11, Category = category1.Id, Rates = 5, HpFeatured = true
            };
            var product2 = new Product()
            {
                Name = "Product 2", Price = 22, Category = category1.Id, Rates = 1
            };
            var id1 = PetaPocoProductService.Add(product1);

            PetaPocoProductService.Add(product2);

            // act
            var result = PetaPocoProductService.GetFeatured(1);

            // assert
            Assert.AreEqual(1, result.Count());
            Assert.IsTrue(result.First().HpFeatured);
            Assert.AreEqual(id1, result.First().Id);
        }
Esempio n. 2
0
        public void Get_Top_Rates()
        {
            // arrange
            var category1 = new Category()
            {
                Name = "Category 1"
            };

            PetaPocoCategoryService.Add(category1);
            var product1 = new Product()
            {
                Name = "Product 1", Price = 11, Category = category1.Id, Rates = 5
            };
            var product2 = new Product()
            {
                Name = "Product 2", Price = 22, Category = category1.Id, Rates = 1
            };
            var id1 = PetaPocoProductService.Add(product1);

            PetaPocoProductService.Add(product2);

            // act
            var result = PetaPocoProductService.GetTopRated(1);

            // assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(5, result.First().Rates);
            Assert.AreEqual(id1, result.First().Id);
        }
Esempio n. 3
0
        public void When_Try_To_Search_Product_By_Category_Name_List_Of_Products_Is_Returned_Properly()
        {
            // arrange
            var category1 = new Category()
            {
                Name = "Rock"
            };

            PetaPocoCategoryService.Add(category1);

            var product1 = new Product()
            {
                Name = "Product 1", Price = 11, Category = category1.Id, Rates = 5, HpFeatured = true
            };
            var product2 = new Product()
            {
                Name = "Product 2 MySearch", Price = 22, Category = category1.Id, Rates = 1
            };
            var id1 = PetaPocoProductService.Add(product1);

            PetaPocoProductService.Add(product2);

            // act 1
            var totalItems = 0;
            var result     = PetaPocoProductService.Search("Rock", null, out totalItems);

            // assert 1
            Assert.AreEqual(2, totalItems);
        }
Esempio n. 4
0
        public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
        {
            if (source == null)
            {
                return(null);
            }

            var array = JsonConvert.DeserializeObject <int[]>((string)source);
            var ps    = new PetaPocoProductService("onlineStoreDb");

            return(array.Select(x => ps.GetById(x)).Where(x => x != null));
        }
        public BaseUnitTest()
        {
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var indexOfBin    = baseDirectory.LastIndexOf(@"\bin\", StringComparison.CurrentCultureIgnoreCase);
            var appDataPath   = string.Format(@"{0}\App_Data\", baseDirectory.Substring(0, indexOfBin));

            // Set |DataDirectory| value
            AppDomain.CurrentDomain.SetData("DataDirectory", appDataPath);

            Context = new Mock <HttpContextBase>();
            Context.Setup(ctx => ctx.Session).Returns(new HttpSessionMock());

            PetaPocoCategoryService = new PetaPocoCategoryService("onlineStoreDbTest");
            PetaPocoProductService  = new PetaPocoProductService("onlineStoreDbTest");
        }
Esempio n. 6
0
        public void Are_Crud_Methods_Working()
        {
            var category1 = new Category()
            {
                Name = "Category 1"
            };

            PetaPocoCategoryService.Add(category1);
            var product1 = new Product()
            {
                Name = "Product 1", Price = 11, Category = category1.Id
            };
            var product2 = new Product()
            {
                Name = "Product 2", Price = 22, Category = category1.Id
            };

            // create
            var id1 = PetaPocoProductService.Add(product1);
            var id2 = PetaPocoProductService.Add(product2);

            Assert.IsNotNull(id1 != 0);
            Assert.IsNotNull(id2 != 0);

            // read
            var item1 = PetaPocoProductService.GetById(id1);
            var item2 = PetaPocoProductService.GetById(id2);

            Assert.IsNotNull(item1);
            Assert.IsNotNull(item2);

            // update
            var newPrice = 11.5M;

            item1.Price = newPrice;
            PetaPocoProductService.Update(item1);
            var updatedItem = PetaPocoProductService.GetById(id1);

            Assert.IsNotNull(updatedItem);
            Assert.IsTrue(newPrice == item1.Price);

            // delete
            PetaPocoProductService.Delete(id1);
            PetaPocoProductService.Delete(item2);
            var leftItems = PetaPocoProductService.GetAll(null);

            Assert.AreEqual(0, leftItems.Count());
        }
        private static void AddOrSave(IContent e)
        {
            if (e.ContentType.Alias == "Product")
            {
                var productService = new PetaPocoProductService("umbracoDbDSN");
                var pocoObj        = Mapper.Map <Product>(e);
                var product        = productService.GetById(e.Id);

                if (product == null)
                {
                    productService.Add(pocoObj);
                }
                else
                {
                    productService.Update(pocoObj);
                }
            }

            if (e.ContentType.Alias == "Category")
            {
                var categoryService = new PetaPocoCategoryService("umbracoDbDSN");
                var pocoObj         = new Category()
                {
                    Id = e.Id, Name = e.Name
                };
                var category = categoryService.GetById(e.Id);

                if (category == null)
                {
                    categoryService.Add(pocoObj);
                }
                else
                {
                    categoryService.Update(pocoObj);
                }
            }
        }