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(); } }
/// <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; }
public void Test_GetMessage(int dayId, int languageId) { // Arrange var expected = new MessageDTO { DayId = dayId, LanguageId = languageId, Text = string.Format("test messgae for day {0}, language {1}", dayId, languageId) }; _messageService.Setup(x => x.GetMessage(It.IsIn(dayId), It.IsIn(languageId))).Returns(expected); // Act var result = _controller.GetMessage(dayId, languageId); var response = result as OkNegotiatedContentResult<MessageDTO>; // Assert Assert.IsInstanceOf<IHttpActionResult>(result); Assert.IsNotNull(response); Assert.AreEqual(expected, response.Content); }
public void Test_SetMessage() { // Arrange var expected = new MessageDTO { Id = 1, Text = "new message text" }; _messageService.Setup(x => x.SetMessage(expected.Id, expected.Text)); // Act var result = _controller.SetMessage(expected); // Assert Assert.IsInstanceOf<IHttpActionResult>(result); }