Ejemplo n.º 1
0
        public ProductViewModel()
        {
            Title            = "Product Management";
            Product          = new ObservableCollection <ProductModel>();
            LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());

            MessagingCenter.Subscribe <NewProductPage, ProductModel>(this, "AddProduct", async(obj, item) =>
            {
                var newItem = item as ProductModel;
                Product.Add(newItem);
                await ProductService.AddItemAsync(newItem);
            });


            MessagingCenter.Subscribe <ProductDetailPage, ProductModel>(this, "UpdateProduct", async(obj, item) =>
            {
                var updatedItem = item as ProductModel;
                await ProductService.UpdateItemAsync(updatedItem);
            });

            MessagingCenter.Subscribe <ProductDetailPage, ProductModel>(this, "DeleteProduct", async(obj, item) =>
            {
                var deleteItem = item as ProductModel;
                await ProductService.DeleteItemAsync(deleteItem.ProductId);
            });
        }
Ejemplo n.º 2
0
        public void AddCustomerService_Test()
        {
            Product product = new Product()
            {
                Name = "SomeProduct",
            };
            bool item = service.AddItemAsync(product).GetAwaiter().GetResult();

            Assert.IsTrue(item);
            var count = service.GetItemsAsync().GetAwaiter().GetResult().Count();

            Assert.AreEqual(2, count);
        }