Ejemplo n.º 1
0
        public void TC_VerifyContactDeletedByContactId()
        {
            Random generator    = new Random();
            string firstname    = generator.Next(0, 1000000).ToString("D6");
            var    inputContact = new Contact()
            {
                FirstName   = firstname,
                LastName    = "Test",
                Email       = "*****@*****.**",
                PhoneNumber = "9087654321",
                Status      = 1
            };

            contactController.CreatePost(inputContact);
            List <Contact> lstContactsFromAPI = serviceAccessLayer.GetAllContacts();

            Assert.IsTrue(lstContactsFromAPI.Where(C => C.FirstName == inputContact.FirstName).Any());

            Contact updateContact = lstContactsFromAPI.Where(C => C.FirstName == inputContact.FirstName).FirstOrDefault();

            //Delete contact by contactId
            serviceAccessLayer.DeleteContact(updateContact.Id);
            Contact lstdeletedContact = serviceAccessLayer.GetContactById(updateContact.Id);

            Assert.IsNull(lstdeletedContact);
        }
        // Delete: /Contact/1
        public ActionResult Delete(int id)
        {
            bool isDeleted = serviceAccessLayer.DeleteContact(id);

            if (isDeleted)
            {
                return(Content("<script language='javascript' type='text/javascript'>alert('Contact details deleted successfully.');window.location.href = '/Contact/Index';</script>"));
            }

            ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");

            return(View());
        }