Ejemplo n.º 1
0
        public void Test_SetMessage_Integration()
        {
            string oldValue;
            // Arrange
            var message = new MessageDTO
            {
                Id = 1,
                Text = "new message text"
            };
            using (var db = new MessagesDBEntities())
            {
                var dbMessage = db.Messages.First(x => x.Id == message.Id);
                oldValue = dbMessage.Message;
            }

            //Act
            var result = _controller.SetMessage(message);

            using (var db = new MessagesDBEntities())
            {
                //dbMessage should be changed
                var dbMessage = db.Messages.First(x => x.Id == 1);

                // Assert
                Assert.IsInstanceOf<System.Web.Http.IHttpActionResult>(result);
                Assert.AreEqual(message.Text, dbMessage.Message);

                //Get back value in db
                dbMessage.Message = oldValue;
                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Set message text for the message
 /// </summary>
 /// <param name="id">Message id</param>
 /// <param name="messageText">New message text</param>
 /// <returns>Updated message entity</returns>
 public void SetMessage(int id, string messageText)
 {
     using (var db = new MessagesDBEntities())
     {
         var message = db.Messages.FirstOrDefault(x => x.Id == id);
         if (message == null) return;
         message.Message = messageText;
         db.SaveChanges();
     }
 }