public void CreateAnswerCreatesAnswer() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("CreateAnswerCreatesAnswer") .Options; int answerId = 1; string answerString = "Answer String"; int weight = 1; int categoryId = 1; int questionId = 1; var answerLog = new LogLibMod.Answer { AnswerId = answerId, AnswerString = answerString, Weight = weight, CategoryId = categoryId, QuestionId = questionId }; using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new CreateQuizRepository(actContext); //act repo.CreateAnswer(answerLog); repo.Save(); using var assertContext = new DatLib.Entities.ecgbhozpContext(options); var answer = assertContext.Answer.FirstOrDefault(); //assert Assert.Equal(expected: answerId + answerString + weight + categoryId + questionId, actual: answer.AnswerId + answer.AnswerString + answer.Weight + answer.CategoryId + answer.QuestionId); }
//class to entity public static Entities.Answer MapAnswer(LogLib.Answer answer) { return(new Entities.Answer { AnswerId = answer.AnswerId, AnswerString = answer.AnswerString, Weight = answer.Weight, CategoryId = answer.CategoryId, QuestionId = answer.QuestionId }); }