public void Update(Contact contact)
 {
     var collection = Database.GetCollection<BsonDocument>("Contacts");
     var filter = Builders<BsonDocument>.Filter;
     var update = Builders<BsonDocument>.Update.Set("PhoneNumbers", contact.PhoneNumbers);
     collection.UpdateOne(filter.Eq("FirstName", contact.FirstName) & filter.Eq("LastName", contact.LastName), update);
 }
        public void MultipleReadInsertTest()
        {
            var mongoDb = new MongoDbContactOperations("testDb");
            mongoDb.DeleteCollection("Contacts");
            const string contactFirstName = "Cagri";
            const string contactLastName = "Ozer";
            const string phone1 = "05367369622";
            const string phone2 = "02163162577";
            var expectedContact = new Contact()
            {
                LastName = contactLastName,
                FirstName = contactFirstName,
                PhoneNumbers = { phone1, phone2 }
            };
            mongoDb.Insert(expectedContact);
            const string secondContactFirstName = "Arthur";
            const string secondContactLastName = "Dent";
            const string secondPhone1 = "08024424242";
            const string secondPhone2 = "08085151992";
            var secondExpectedContact = new Contact()
            {
                LastName = secondContactLastName,
                FirstName = secondContactFirstName,
                PhoneNumbers = { secondPhone1, secondPhone2 }
            };
            mongoDb.Insert(secondExpectedContact);
            const string thirdContactFirstName = "Cagri";
            const string thirdContactLastName = "Devasa";
            const string thirdPhone1 = "05365834094";
            const string thirdPhone2 = "02169321466";
            var thirdExpectedContact = new Contact()
            {
                LastName = thirdContactLastName,
                FirstName = thirdContactFirstName,
                PhoneNumbers = { thirdPhone1, thirdPhone2 }
            };
            mongoDb.Insert(thirdExpectedContact);

            var expectedContactList = new List<Contact>() { expectedContact, thirdExpectedContact };
            var contacts = mongoDb.Read("Cagri").ToList();

            CollectionAssert.AreEqual(expectedContactList, contacts);
        }
        public void ReadInsertTest()
        {
            var mongoDb = new MongoDbContactOperations("testDb");
            mongoDb.DeleteCollection("Contacts");
            const string contactFirstName = "Cagri";
            const string contactLastName = "Ozer";
            const string phone1 = "05367369622";
            const string phone2 = "02163162577";
            var expectedContact = new Contact()
            {
                LastName = contactLastName,
                FirstName = contactFirstName,
                PhoneNumbers = { phone1, phone2 }
            };
            mongoDb.Insert(expectedContact);

            var contact = mongoDb.Read("Cagri", "Ozer");

            Assert.AreEqual(contact, expectedContact);
        }
 public void Insert(Contact contact)
 {
     var collection = Database.GetCollection<Contact>("Contacts");
     collection.InsertOne(contact);
 }
        public void UpdateTest()
        {
            var mongoDb = new MongoDbContactOperations("testDb");
            mongoDb.DeleteCollection("Contacts");
            const string contactFirstName = "Cagri";
            const string contactLastName = "Ozer";
            const string phone1 = "05367369622";
            const string phone2 = "02163162577";
            var expectedContact = new Contact()
            {
                LastName = contactLastName,
                FirstName = contactFirstName,
                PhoneNumbers = { phone1, phone2 }
            };
            mongoDb.Insert(expectedContact);
            const string secondContactFirstName = "Arthur";
            const string secondContactLastName = "Dent";
            const string secondPhone1 = "08024424242";
            const string secondPhone2 = "08085151992";
            var secondExpectedContact = new Contact()
            {
                LastName = secondContactLastName,
                FirstName = secondContactFirstName,
                PhoneNumbers = { secondPhone1, secondPhone2 }
            };
            mongoDb.Insert(secondExpectedContact);
            const string thirdContactFirstName = "Cagri";
            const string thirdContactLastName = "Devasa";
            const string thirdPhone1 = "05365834094";
            const string thirdPhone2 = "02169321466";
            var thirdExpectedContact = new Contact()
            {
                LastName = thirdContactLastName,
                FirstName = thirdContactFirstName,
                PhoneNumbers = { thirdPhone1, thirdPhone2 }
            };
            mongoDb.Insert(thirdExpectedContact);

            thirdExpectedContact.PhoneNumbers.Add("1234567123");
            mongoDb.Update(thirdExpectedContact);

            var updatedContact = mongoDb.Read(thirdExpectedContact.FirstName, thirdContactLastName);
            Assert.AreEqual(updatedContact, thirdExpectedContact);

        }
 public void Insert(Contact contact)
 {
     ContactsList.Add(contact);
 }
 public void Update(Contact contact)
 {
     ContactsList.Remove(ContactsList.Single(p => p.FirstName == contact.FirstName && p.LastName == contact.LastName));
     ContactsList.Add(contact);
 }