public void ToTEF_ProvidingNull_ThrowException() { //ARRANGE QuestionTO question = null; //ACT Assert.ThrowsException <ArgumentNullException>(() => question.ToEF()); }
public QuestionTO Add(QuestionTO Entity) { if (Entity is null) { throw new ArgumentNullException(nameof(Entity)); } var question = Entity.ToEF(); question.Form = evaluationContext .Forms .FirstOrDefault(f => f.Id == Entity.FormId); return(evaluationContext.Questions.Add(question).Entity.ToTransfertObject()); }
public QuestionTO Insert(QuestionTO entity) { if (entity is null) { throw new ArgumentNullException(); } if (entity.Id != 0) { return(entity); } entity.Answers = new List <AnswerTO>(); var result = context.Questions.Add(entity.ToEF()); return(result.Entity.ToTO()); }
public QuestionTO Create(QuestionTO entity) { if (entity is null) { throw new ArgumentNullException(); } if (entity.Id != 0) { return(entity); } var questionEF = entity.ToEF(); var result = askContext.Questions.Add(questionEF); askContext.SaveChanges(); return(result.Entity.ToTransferObject()); }
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 }; //ACT var result = question.ToEF(); //Assert Assert.AreEqual(question.Id, result.Id); Assert.AreEqual(question.IsResolved, result.IsResolved); Assert.AreEqual(question.AuthorId, result.AuthorId); Assert.AreEqual(question.Title, result.Title); Assert.AreEqual(question.Date, result.Date); Assert.AreEqual(question.Message, result.Message); }
public QuestionTO Update(QuestionTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Id <= 0) { throw new ArgumentException(nameof(entity)); } var updated = //Get(entity.Id).ToEF(); context.Questions.FirstOrDefault(e => e.Id == entity.Id); if (updated != default) { updated.UpdateFromDetached(entity.ToEF()); } Save(); return(context.Questions.Update(updated).Entity.ToTO()); }