Esempio n. 1
0
        public void CatalogAccessor_Product_CRUD()
        {
            var accessor = CreateCatalogAccessor();
            var catalog  = CreateCatalog();
            var saved    = CreateProduct(catalog);

            Assert.IsNotNull(saved);
            Assert.IsTrue(saved.Id > 0);

            var loaded = accessor.FindProduct(saved.Id);

            Assert.IsNotNull(loaded);
            Assert.IsTrue(loaded.Id > 0);
            Assert.AreEqual(saved.Id, loaded.Id);
            Assert.AreEqual(saved.Price, loaded.Price);

            loaded.Name = "LOADED";
            accessor.SaveProduct(catalog.Id, loaded);
            var loaded2 = accessor.FindProduct(loaded.Id);

            Assert.AreEqual("LOADED", loaded.Name);

            // rebuild the accessor to update the context with the new catalog id
            AmbientContext context = new AmbientContext()
            {
            };

            accessor = new AccessorFactory(context, new UtilityFactory(context)).CreateAccessor <ICatalogAccessor>();
            var products = accessor.FindAllProductsForCatalog(catalog.Id);

            Assert.IsNotNull(products);
            Assert.AreEqual(1, products.Length);

            accessor.DeleteProduct(catalog.Id, loaded.Id);

            var loaded3 = accessor.FindProduct(loaded.Id);

            Assert.IsNull(loaded3);
        }