Ejemplo n.º 1
0
        public void Update_LambdaModifier_AllContactsUpdated()
        {
            var updateName      = "1234";
            var notUpdateName   = "13";
            var updatedLastName = "bbbb";

            var book = new PhoneBook
            {
                new Contact
                {
                    FirstName = updateName
                },
                new Contact
                {
                    FirstName = updateName
                },
                new Contact
                {
                    FirstName = notUpdateName
                }
            };


            book.Update(x => x.FirstName == updateName, x =>
            {
                x.LastName = updatedLastName;
                return(x);
            });

            var updatedContactsCount    = book.Count(x => x.FirstName == updateName && x.LastName == updatedLastName);
            var notUpdatedContactsCount = book.Count(x => x.LastName == null);

            Assert.Equal(updatedContactsCount, 2);
            Assert.Equal(notUpdatedContactsCount, 1);
        }
Ejemplo n.º 2
0
        public void Update_NewContact_AllContactsUpdated()
        {
            var updateName    = "1234";
            var notUpdateName = "13";

            var book = new PhoneBook
            {
                new Contact
                {
                    FirstName = updateName
                },
                new Contact
                {
                    FirstName = updateName
                },
                new Contact
                {
                    FirstName = notUpdateName
                }
            };

            var newContact = new Contact();

            book.Update(x => x.FirstName == updateName, newContact);

            var newContactsCount = book.Count(x => x == newContact);

            Assert.Equal(newContactsCount, 2);
            Assert.NotEqual(book.Single(x => x.FirstName == notUpdateName), newContact);
        }
Ejemplo n.º 3
0
        public void Delete_Contact_ContactDeleted()
        {
            var deleteContact = new Contact();

            var book = new PhoneBook
            {
                new Contact(),
                new Contact(),
                new Contact(),
                deleteContact
            };

            book.Delete(deleteContact);

            var contactsCount = book.Count();

            Assert.Equal(contactsCount, 3);
            Assert.DoesNotContain(deleteContact, book);
        }