public void ToTEF_ProvidingNull_ThrowException() { //ARRANGE AnswerTO answer = null; //ACT Assert.ThrowsException <ArgumentNullException>(() => answer.ToEF()); }
public void ToEF_Successful() { //ARRANGE DateTime date = DateTime.Now; var question = new QuestionTO { Id = 1, IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var answer = new AnswerTO { Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = question, }; //ACT var result = answer.ToEF(); //Assert Assert.AreEqual(answer.AuthorId, result.AuthorId); Assert.AreEqual(answer.Message, result.Message); }
public AnswerTO Insert(AnswerTO entity) { if (entity is null) { throw new ArgumentNullException(); } if (entity.Id != 0) { return(entity); } var question = context.Questions.FirstOrDefault(x => x.Id == entity.QuestionId); var result = context.Answers.Add(entity.ToEF()); question.Answers.Add(result.Entity); return(result.Entity.ToTO()); }
public AnswerTO Create(AnswerTO entity) { if (entity is null) { throw new ArgumentNullException(); } if (entity.Id != 0) { return(entity); } var answerEF = entity.ToEF(); answerEF.AssociatedQuestion = askContext.Questions.First(x => x.Id == entity.AssociatedQuestion.Id && entity.AssociatedQuestion.IsResolved != true); var result = askContext.Answers.Add(answerEF); askContext.SaveChanges(); return(result.Entity.ToTransferObject()); }
public AnswerTO Update(AnswerTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Id <= 0) { throw new ArgumentException(nameof(entity)); } var updated = context.Answers.FirstOrDefault(e => e.Id == entity.Id); if (updated != default) { updated.UpdateFromDetached(entity.ToEF()); } Save(); return(context.Answers.Update(updated).Entity.ToTO()); }