Esempio n. 1
0
        public void MobileServiceCollectionCanInsertAndNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock <Book> query = new MobileServiceTableQueryMock <Book>();

            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection <Book> collection = new MobileServiceCollection <Book>(query);

            List <string> properties         = new List <string>();
            List <string> expectedProperties = new List <string>()
            {
                "Count", "Item[]"
            };
            List <NotifyCollectionChangedAction> actions         = new List <NotifyCollectionChangedAction>();
            List <NotifyCollectionChangedAction> expectedActions = new List <NotifyCollectionChangedAction>()
            {
                NotifyCollectionChangedAction.Add
            };

            Book book = new Book();

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);
            collection.Insert(0, book);

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(book, collection[0]);
            Assert.IsTrue(properties.SequenceEqual(expectedProperties));
            Assert.IsTrue(actions.SequenceEqual(expectedActions));
        }
Esempio n. 2
0
        private async void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            var customer = TextCustomer.SelectedItem as MobileCustomer;

            if (customer != null)
            {
                var order = new MobileOrder
                {
                    Item               = TextOrder.Text,
                    MobileCustomerId   = customer.Id,
                    Quantity           = 1,
                    MobileCustomerName = customer.Name
                };

                await ordersTable.InsertAsync(order);

                orders.Insert(0, order);

                // clear the UI fields
                TextCustomer.SelectedIndex = -1;
                TextOrder.Text             = String.Empty;
                TextOrder.Focus(FocusState.Programmatic);
            }
        }
        public void MobileServiceCollectionCanInsertAndNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock<Book> query = new MobileServiceTableQueryMock<Book>();
            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection<Book, Book> collection = new MobileServiceCollection<Book, Book>(query);

            List<string> properties = new List<string>();
            List<string> expectedProperties = new List<string>() { "Count", "Item[]" };
            List<NotifyCollectionChangedAction> actions = new List<NotifyCollectionChangedAction>();
            List<NotifyCollectionChangedAction> expectedActions = new List<NotifyCollectionChangedAction>() { NotifyCollectionChangedAction.Add };

            Book book = new Book();

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);
            collection.Insert(0, book);

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(book, collection[0]);
            Assert.IsTrue(properties.SequenceEqual(expectedProperties));
            Assert.IsTrue(actions.SequenceEqual(expectedActions));
        }