Beispiel #1
0
        public void No_Update_Made_If_ContactId_Does_Not_Exist()
        {
            //Arrange
            var incorrectContactId = nonUpdatedContactId + 5;

            //Act
            var result = dataLayer.UpdateContactAsync(incorrectContactId, contacts).Result;

            //Assert
            Assert.IsNull(result.Result); //Not found, should be null
            Assert.AreSame(contacts, contactsContext.Contacts.First());
            Assert.True(result.ErrorStatus == ErrorStatus.Failed);
            Assert.AreEqual(result.ErrorInfo.ErrorMessage, "Contact Not Found");
        }
        public async Task <IActionResult> UpdateContactAsync(int id, ContactsDTO contacts)
        {
            if (id != contacts.ContactId)
            {
                return(BadRequest());
            }

            try
            {
                var result = await dataLayer.UpdateContactAsync(id, contacts);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!(await ContactsExists(id)))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok("Contact Updated Successfully"));
        }