コード例 #1
0
        public void TestFilter()
        {
            var alvm = new AddressListViewModel();

            var alivm1 = new AddressListItemViewModel(new Address
            {
                FirstName = "Bob",
                LastName  = "Newbie",
                Email     = "*****@*****.**"
            });
            var alivm2 = new AddressListItemViewModel(new Address
            {
                FirstName = "Steve",
                LastName  = "steverson",
                Email     = "*****@*****.**"
            });

            alvm.AddAddressListItemViewModel(alivm1);
            alvm.AddAddressListItemViewModel(alivm2);

            alvm.Filter = "newb";
            Assert.AreSame(alivm1, alvm.AddressListItemViewModels.Single());

            alvm.Filter = "";
            Assert.AreEqual(2, alvm.AddressListItemViewModels.Count);

            alvm.Filter = "ERSON";
            Assert.AreSame(alivm2, alvm.AddressListItemViewModels.Single());

            alvm.Filter = "foo bar";
            Assert.IsFalse(alvm.AddressListItemViewModels.Any());
        }
コード例 #2
0
        public void TestSort()
        {
            var alvm = new AddressListViewModel();


            var alivm1 = new AddressListItemViewModel(new Address
            {
                FirstName = "Bob",
                // lowercase to make sure case is ignored - steverson would go before newbie if it wasn't
                LastName = "newbie",
                Email    = "*****@*****.**"
            });
            var alivm2 = new AddressListItemViewModel(new Address
            {
                FirstName = "Steve",
                // lowercase to make sure case is ignored - steverson would go after newbie if it wasn't
                LastName = "Steverson",
                Email    = "*****@*****.**"
            });

            // Insert them in backwards sorted order (S before N)
            alvm.AddAddressListItemViewModel(alivm2);
            alvm.AddAddressListItemViewModel(alivm1);

            // Check that they were automatically sorted - Newbie comes before Steverson
            Assert.AreEqual(alivm1, alvm.AddressListItemViewModels[0]);
            Assert.AreEqual(alivm2, alvm.AddressListItemViewModels[1]);
        }
コード例 #3
0
        public void TestExternalDeletion()
        {
            var alvm = new AddressListViewModel();

            var address = new Address
            {
                FirstName = "Bob",
                LastName  = "Newbie",
                Email     = "*****@*****.**"
            };

            using (var db = new MailerEntities())
            {
                db.Addresses.Add(address);
                db.SaveChanges();
            }

            var alivm1 = new AddressListItemViewModel(address);

            alvm.AddAddressListItemViewModel(alivm1);
            Assert.AreEqual(1, alvm.AddressListItemViewModels.Count);

            alivm1.Delete();
            Assert.AreEqual(0, alvm.AddressListItemViewModels.Count);

            using (var db = new MailerEntities())
            {
                // ensure that it was removed
                Assert.IsFalse(db.Addresses.Any(addr => addr.AddressID == address.AddressID));
            }
        }
コード例 #4
0
        public void TestRemoval()
        {
            var alvm = new AddressListViewModel();

            var address = new Address
            {
                FirstName = "Bob",
                LastName  = "Newbie",
                Email     = "*****@*****.**"
            };


            var alivm1 = new AddressListItemViewModel(address);

            alvm.AddAddressListItemViewModel(alivm1);
            Assert.AreEqual(1, alvm.AddressListItemViewModels.Count);

            alvm.RemoveAddressListItemViewModel(alivm1);
            Assert.AreEqual(0, alvm.AddressListItemViewModels.Count);
        }