public void ViewModel_with_nested_properties_should_notify(ITotalLineItemsViewModel viewModel)
        {
            // ARRANGE
            viewModel.PropertyChanged += (_, e) => ActualNotifications.Add(e.PropertyName);

            ExpectedNotifications.AddRange(new[] {
                //viewModel.LineItem1 = viewModel.CreateLineItem1();
                "LineItem1",
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItem1.Quantity = 1;
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItem1.Price = 99.99m;
                "TotalCost",
                //viewModel.LineItem2 = viewModel.CreateLineItem2();
                "LineItem2",
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItem2.Quantity = 2;
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItem2.Price = 50.00m;
                "TotalCost",
                //viewModel.LineItem3 = viewModel.CreateLineItem3();
                "LineItem3",
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItem3 = null;
                "LineItem3",
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
            });

            // ACT
            viewModel.CreateLineItem1();
            viewModel.LineItem1.Quantity = 1;
            viewModel.LineItem1.Price    = 99.99m;
            viewModel.CreateLineItem2();
            viewModel.LineItem2.Quantity = 2;
            viewModel.LineItem2.Price    = 50.00m;
            viewModel.CreateLineItem3();
            viewModel.LineItem3 = null;

            // ASSERT
            AssertNotificationsEqual();
        }
Пример #2
0
        public void SimpleViewModel_should_notify(ILineItemViewModel viewModel)
        {
            viewModel.PropertyChanged += (_, e) => ActualNotifications.Add(e.PropertyName);

            ExpectedNotifications.AddRange(new[]
            {
                //viewModel.Quantity = 1;
                "Quantity",
                "Cost",
                //viewModel.Price = 99.99m;
                "Price",
                "Cost"
            });

            viewModel.Quantity = 1;
            viewModel.Price    = 99.99m;

            AssertNotificationsEqual();
        }
        public void SimpleCollectionViewModel_with_simple_collection_should_notify(ISimpleCollectionViewModel viewModel)
        {
            // ARRANGE
            viewModel.PropertyChanged += (_, e) => ActualNotifications.Add(e.PropertyName);

            ExpectedNotifications.AddRange(new[]
            {
                //ViewModel.StringCollection = new ObservableCollection<String>();
                "StringCollection",
                "StringCollectionCount",
                //ViewModel.StringCollection.Add("Hello");
                "StringCollectionCount",
                //ViewModel.StringCollection.Add("World");
                "StringCollectionCount",
            });

            // ACT
            viewModel.StringCollection = new ObservableCollection <String>();
            viewModel.StringCollection.Add("Hello");
            viewModel.StringCollection.Add("World");

            // ASSERT
            AssertNotificationsEqual();
        }
        public void TwoDeepCollectionViewModel_should_notify(IDeepCollectionViewModel viewModel)
        {
            // ARRANGE
            viewModel.PropertyChanged += (_, e) => ActualNotifications.Add(e.PropertyName);

            ExpectedNotifications.AddRange(new[]
            {
                //viewModel.LineItems = new ObservableCollection<ILineItemViewModel>();
                "LineItems",
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.AddNewLineItem();
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItems[0].Quantity = 1;
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItems[0].Price = 99.99m;
                "TotalCost",
                //viewModel.AddNewLineItem();
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItems[1].Quantity = 2;
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItems[1].Price = 50.00m;
                "TotalCost",
                //viewModel.AddNewLineItem();
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItems.RemoveAt(2);
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
                //viewModel.LineItems = newLineItems;
                "LineItems",
                "TotalLineItems",
                "TotalItemQuantity",
                "TotalCost",
            });

            // ACT
            viewModel.LineItems = new ObservableCollection <ILineItemViewModel>();
            viewModel.AddNewLineItem();
            viewModel.LineItems[0].Quantity = 1;
            viewModel.LineItems[0].Price    = 99.99m;
            viewModel.AddNewLineItem();
            viewModel.LineItems[1].Quantity = 2;
            viewModel.LineItems[1].Price    = 50.00m;
            viewModel.AddNewLineItem();
            viewModel.LineItems.RemoveAt(2);
            var newLineItems = new ObservableCollection <ILineItemViewModel>();
            var newLineItem1 = (ILineItemViewModel)Activator.CreateInstance(viewModel.LineItems[0].GetType());

            newLineItem1.Quantity = 1;
            newLineItem1.Price    = 99.99m;
            newLineItems.Add(newLineItem1);
            viewModel.LineItems = newLineItems;

            // ASSERT
            AssertNotificationsEqual();
        }