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();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Get all days
 /// </summary>
 /// <returns>Day of week collection</returns>
 public IList<DayDTO> GetDays()
 {
     using (var db = new MessagesDBEntities())
     {
         return db.Days.Select(x => new DayDTO
         {
             Id = x.Id,
             Name = x.Name
         }).ToList();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Get all languages
 /// </summary>
 /// <returns>Languages collection</returns>
 public IList<LanguageDTO> GetLanguages()
 {
     using (var db = new MessagesDBEntities())
     {
         return db.Languages.Select(x => new LanguageDTO
         {
             Id = x.Id,
             Name = x.Name,
             PartialFlagPath = x.PartialFlagPath
         }).ToList();
     }
 }
Ejemplo n.º 5
0
        public void Test_GetMessage_Integration(int dayId, int languageId)
        {          
            using (var db = new MessagesDBEntities())
            {
                // Arrange
                var dbMessage = db.Messages.First(x => x.DayId == dayId && x.LanguageId == languageId);
                
                //Act
                var result = _controller.GetMessage(dayId, languageId);
                var response = result as OkNegotiatedContentResult<MessageDTO>;

                // Assert
                Assert.IsInstanceOf<System.Web.Http.IHttpActionResult>(result);
                Assert.IsNotNull(response);
                Assert.AreEqual(dbMessage.Message, response.Content.Text);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Get message of the day by param
 /// </summary>
 /// <param name="dayId">Day id</param>
 /// <param name="languageId">Language id</param>
 /// <returns>Message entity</returns>
 public MessageDTO GetMessage(int dayId, int languageId)
 {
     var result = new MessageDTO();
     using (var db = new MessagesDBEntities())
     {
         var message = db.Messages.FirstOrDefault(x => x.DayId == dayId && x.LanguageId == languageId);
         if (message != null)
             result = new MessageDTO
             {
                 Id = message.Id,
                 DayId = message.DayId ?? 0,
                 Day = message.Days != null ? message.Days.Name : "",
                 LanguageId = message.LanguageId ?? 0,
                 Language = message.Languages != null ? message.Languages.Name : "",
                 Text = message.Message
             };
     }
     return result;
 }