public MockEntitySet(bool raiseCollectionChangedEvents)
                : base(typeof(City))
            {
                this.RaiseCollectionChangedEvents = raiseCollectionChangedEvents;

                MockEntityContainer container = new MockEntityContainer();

                container.AddEntitySet(this, EntitySetOperations.All);
            }
Example #2
0
        /// <summary>
        /// Gets a <see cref="DomainDataSourceView"/> that uses a mocked <see cref="PagedEntityList"/>
        /// as its source, configured to support the operations specified, and using the specified
        /// <paramref name="refreshCallback"/> as the <see cref="Action"/> to invoke when a
        /// <see cref="DomainDataSourceView.Refresh"/> is triggered.
        /// </summary>
        /// <param name="operationsSupported">The operations to be supported on the mock <see cref="EntitySet"/>.</param>
        /// <param name="refreshCallback">The <see cref="Action"/> to call when a refresh occurs.</param>
        /// <returns>The configured <see cref="DomainDataSourceView"/> that uses mocks.</returns>
        private static DomainDataSourceView GetConfigurableView(EntitySetOperations operationsSupported, Action refreshCallback)
        {
            MockEntityContainer ec = new MockEntityContainer();

            ec.CreateSet <City>(operationsSupported);

            IPagedEntityList          pagedList = new MockPagedEntityList(ec.GetEntitySet <City>(), null);
            PagedEntityCollectionView ecv       = new PagedEntityCollectionView(pagedList, refreshCallback);

            return(new DomainDataSourceView(ecv));
        }
        public void CancelingCurrencyChangeIsRespectedOnCommitEdit()
        {
            City first = new City {
                Name = "1"
            };
            City second = new City {
                Name = "2"
            };
            MockEntityContainer ec = new MockEntityContainer();

            ec.CreateSet <City>(EntitySetOperations.All);

            IPagedEntityList          pagedList = new MockPagedEntityList(ec.GetEntitySet <City>(), null);
            PagedEntityCollectionView view      = new PagedEntityCollectionView(pagedList, () => { });

            view.Add(first);
            view.Add(second);

            bool canChangeCurrency = true;
            CurrentChangingEventHandler changingHandler = (sender, e) =>
            {
                if (!canChangeCurrency)
                {
                    Assert.IsTrue(e.IsCancelable,
                                  "Event should be cancelable when commiting an edit.");
                    e.Cancel = true;
                }
            };
            EventHandler changedHandler = (sender, e) =>
            {
                if (!canChangeCurrency)
                {
                    Assert.Fail("Currency changes should only occur when canChangeCurrency is true.");
                }
            };

            view.CurrentChanging += changingHandler;
            view.CurrentChanged  += changedHandler;

            view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            Assert.IsTrue(view.MoveCurrentTo(second),
                          "We should be able to move current to the second item.");

            // Commit an edit but do not allow the currency to change
            canChangeCurrency = false;
            view.EditItem(second);
            second.Name = "0";
            view.CommitEdit();

            Assert.AreEqual(view[1], second,
                            "The edited item should not have moved.");

            // Commit an edit and this time allow the currency to change
            canChangeCurrency = true;
            view.EditItem(second);
            second.Name = "00";
            view.CommitEdit();

            Assert.AreEqual(view[0], second,
                            "The edited item should have moved to the first position in the view.");
        }