public void GetQuestionById_Successful() { var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); //ARRANGE DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test!", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var question2 = new QuestionTO { IsResolved = false, Message = "Comment créer un projet MVC 6?", Title = "MVC6", Date = date, AuthorId = 2 }; var question3 = new QuestionTO { IsResolved = false, Message = "Comment faire boucle foreach?", Title = "foreach", Date = date, AuthorId = 2 }; var addedQuestion = questionRepository.Create(question); var addedQuestion2 = questionRepository.Create(question2); var addedQuestion3 = questionRepository.Create(question3); context.SaveChanges(); //ACT var test = questionRepository.GetById(2); //ASSERT Assert.AreEqual("Comment créer un projet MVC 6?", test.Message); }
public void GetALlAnswers_Successful() { //ARRANGE var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); IAnswerRepository answerRepository = new AnswerRepository(context); //ACT DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var question2 = new QuestionTO { IsResolved = false, Message = "Comment créer un projet MVC 6", Title = "MVC6", Date = date, AuthorId = 2 }; var question3 = new QuestionTO { IsResolved = false, Message = "Comment faire boucle foreach", Title = "foreach", Date = date, AuthorId = 2 }; var addedQuestion = questionRepository.Create(question); var addedQuestion2 = questionRepository.Create(question2); var addedQuestion3 = questionRepository.Create(question3); context.SaveChanges(); var answer = new AnswerTO { Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion, }; var answer2 = new AnswerTO { Message = "Oui c'est trop facile les tests avec InMemory", AuthorId = 3, AssociatedQuestion = addedQuestion, }; var answer3 = new AnswerTO { Message = "Tu dois d'abord créer un projet web app avec .Net Core", AuthorId = 1, AssociatedQuestion = addedQuestion2, }; var addedAnswer = answerRepository.Create(answer); var addedAnswer2 = answerRepository.Create(answer2); var addedAnswer3 = answerRepository.Create(answer3); context.SaveChanges(); //Archiving the question related to the answer 3 addedQuestion2.IsResolved = true; questionRepository.Modify(addedQuestion2); context.SaveChanges(); //ACT var test = answerRepository.GetAll(); //ASSERT Assert.AreEqual(3, test.Count()); }
public void ModifyQuestion_Successful() { var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); //ACT DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var result = questionRepository.Create(question); context.SaveChanges(); //ACT result.IsResolved = true; var test = questionRepository.Modify(result); context.SaveChanges(); //ASSERT Assert.AreEqual(true, test.IsResolved); }
public void CreateQuestion_Successful() { // ARRANGE var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); //ACT DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var result = questionRepository.Create(question); //ASSERT Assert.IsNotNull(result); Assert.AreEqual(1, result.Id); Assert.AreEqual("Je n'arrive pas à faire un test", result.Message); Assert.AreEqual("Problème avec Tests", result.Title); Assert.AreEqual(date, result.Date); Assert.AreEqual(false, result.IsResolved); Assert.AreEqual(1, result.AuthorId); }
public void CreateAnswer_AddExistingAnswer_DoNotInsertTwiceInDb() { //ARRANGE var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); IAnswerRepository answerRepository = new AnswerRepository(context); DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var addedQuestion = questionRepository.Create(question); context.SaveChanges(); var answer = new AnswerTO { Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion, }; var result = answerRepository.Create(answer); context.SaveChanges(); //ACT answerRepository.Create(result); context.SaveChanges(); //ASSERT Assert.AreEqual(1, context.Answers.Count()); }
public void CreateQuestion_AddNull_ThrowException() { var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); Assert.ThrowsException <ArgumentNullException>(() => questionRepository.Create(null)); }
public void ModifyAnswer_Successful() { var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); IAnswerRepository answerRepository = new AnswerRepository(context); //ACT DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var question2 = new QuestionTO { IsResolved = false, Message = "Comment créer un projet MVC 6", Title = "MVC6", Date = date, AuthorId = 2 }; var question3 = new QuestionTO { IsResolved = false, Message = "Comment faire boucle foreach", Title = "foreach", Date = date, AuthorId = 2 }; var addedQuestion = questionRepository.Create(question); var addedQuestion2 = questionRepository.Create(question2); var addedQuestion3 = questionRepository.Create(question3); context.SaveChanges(); var answer = new AnswerTO { Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion, }; var result = answerRepository.Create(answer); context.SaveChanges(); //ACT result.Message = "Message modifié"; var test = answerRepository.Modify(result); context.SaveChanges(); //ASSERT Assert.AreEqual("Message modifié", test.Message); }
public async Task CreateQuestionAsync_QuestionIsNotPreviouslySeeded_CreatesNewQuestion() { var question = new Question { Text = "My Question" }; using (var unitOfWork = Initializer.Provider.Create()) { repository.Create(question); await unitOfWork.Commit(); } Assert.IsFalse(question.Id.Equals(0)); }
public void CreateQuestion_AddExistingQuestion_DoNotInsertTwiceInDb() { //ARRANGE var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var result = questionRepository.Create(question); context.SaveChanges(); //ACT questionRepository.Create(result); context.SaveChanges(); //ASSERT Assert.AreEqual(1, context.Questions.Count()); }
public void ModifyAnswer_ProvidingNonExistingId_ThrowException() { var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IQuestionRepository questionRepository = new QuestionRepository(context); IAnswerRepository answerRepository = new AnswerRepository(context); DateTime date = DateTime.Now; var question = new QuestionTO { IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1 }; var addedQuestion = questionRepository.Create(question); context.SaveChanges(); var answer = new AnswerTO { Id = 16783, Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion, }; Assert.ThrowsException <KeyNotFoundException>(() => answerRepository.Modify(answer)); }
public void TestCreateQuestion() { QuestionRepository questionRepo = new QuestionRepository(DatabaseDummy.DatabaseDummyCreate("TestCreateQuestion")); Question question = new Question { QuestionText = "Intrebare3", CorrectAnswer = "49", WrongAnswer1 = "1", WrongAnswer2 = "2", WrongAnswer3 = "3", CategoryId = 34, QuestionDifficulty = 1 }; try { questionRepo.Create(question); Assert.True(true); } catch { Assert.True(false); } }
public void AddQuestion(Question question) => questionRepo.Create(question);
public bool Create(QuestionDTO user) { bool b1 = ur.Create(Mapper.Map <QuestionEntity>(user)); return(b1); }