public Contact UpdateContact(int id, Contact item)
        {
            IMongoQuery query = Query.EQ("ContactID", id);
            item.LastModified = "Today";
            IMongoUpdate update = Update
                .Set("ContactID", item.ContactID)
                .Set("FirstName", item.FirstName)
                .Set("LastName", item.LastName);

            _contacts.Update(query, update);
            return item;
        }
        public Contact AddContact(Contact item)
        {
            Contact contact = new Contact
            {
                Id = ObjectId.GenerateNewId(),
                ContactID = item.ContactID,
                FirstName = item.FirstName,
                LastName = item.LastName,
                LastModified = DateTime.Now.Date.ToString()

            };
            _contacts.Insert(contact);
            return item;
        }
        public void Delete_ShouldRemoveContact()
        {
            var quanti = _repo.GetAllContacts().Count();
            var contact = new Contact
            {
                Id = ObjectId.GenerateNewId(),
                ContactID = 123,
                FirstName = "Gionni",
                LastName = "Buonni",
                LastModified = DateTime.Now.Date.ToString()
            };
            _repo.AddContact(contact);
            _repo.RemoveContact(contact.ContactID);
            var tuttiDopoRemove = _repo.GetAllContacts().Count();

            Assert.AreEqual(true, tuttiDopoRemove == quanti);
        }
        public void Update_ShouldEditContact()
        {
            int id = 2;
            string nome = "Johnny";
            string data_modificata = "Today";
            var contact = _repo.GetContact(id);
            IMongoQuery query = Query.EQ("ContactID", id);

            using (TransactionScope ts = new TransactionScope())
            {
                IMongoUpdate update = Update
                    .Set("ContactID", id)
                    .Set("FirstName", nome)
                    .Set("LastName", contact.LastName)
                    .Set("LastModified", data_modificata);

                Contact daModificare = new Contact
                {
                    ContactID = contact.ContactID,
                    FirstName = nome,
                    LastName = contact.LastName,
                    LastModified = data_modificata
                };
                _contacts.Update(query, update);
                _repo.UpdateContact(id, daModificare);

                Assert.AreEqual(true, daModificare.FirstName == nome);
                scope.Dispose();

            }
        }
Exemplo n.º 5
0
 private static void PrintContact(Contact contact)
 {
     Console.WriteLine("  ID:            {0}", contact.Id);
     Console.WriteLine("  ContactID:     {0}", contact.ContactID);
     Console.WriteLine("  Name:          {0}", contact.FirstName);
     Console.WriteLine("  LastName:      {0}", contact.LastName);
     Console.WriteLine("  Last Modified: {0}", contact.LastModified);
     Console.WriteLine();
 }