public List <AnswerDTO> GetAll() { List <AnswerEntity> allanswers = ur.GetAll(); List <AnswerDTO> l1 = Mapper.Map <List <AnswerDTO> >(allanswers); return(l1); }
public void ArchiveAnswer_Correct() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IAnswerRepository ARepo = new AnswerRepository(context); IQuestionRepository QRepo = new QuestionRepository(context); var question = new QuestionTO { Questioning = "Not hungry", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "Don't wanna", LastName = "Eat" } }; var addedQuestion = QRepo.Insert(question); QRepo.Save(); var answer = new AnswerTO { Answering = "must be the donuts", AnswerTime = DateTime.Now.AddHours(1), QuestionId = addedQuestion.Id, Savior = new UserTO { FirstName = "Any", LastName = "Officer" } }; var addedAnswer = ARepo.Insert(answer); ARepo.Save(); Assert.AreEqual(1, ARepo.GetAll().Count()); var deletedAnswer = ARepo.Delete(addedAnswer); ARepo.Save(); var all = ARepo.GetAll(); Assert.AreEqual(0, all.Count()); Assert.IsTrue(deletedAnswer); Assert.IsTrue(ARepo.Get(addedAnswer.Id).IsDeleted); }
public void GetAllTest() { var data = repository.GetAll(); //Xunit.Assert.NotNull(data); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(data); //Xunit.Assert.True(data.Count() > 0); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(data.Count() > 0); }
public void GetAllAnswers_NoQuestionInDb_ThrowException() { var options = new DbContextOptionsBuilder <AskContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new AskContext(options); IAnswerRepository answerRepository = new AnswerRepository(context); Assert.ThrowsException <ArgumentNullException>(() => answerRepository.GetAll()); }
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 UpdateAnswer_Correct() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IAnswerRepository ARepo = new AnswerRepository(context); IQuestionRepository QRepo = new QuestionRepository(context); var question = new QuestionTO { Questioning = "Maybe it's working", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "Call me", LastName = "Kevin" } }; var addedQuestion = QRepo.Insert(question); QRepo.Save(); var answer = new AnswerTO { Answering = "No shit Sherlock", AnswerTime = DateTime.Now.AddHours(1), QuestionId = addedQuestion.Id, Savior = new UserTO { FirstName = "Dr", LastName = "Watson" } }; var addedAnswer = ARepo.Insert(answer); ARepo.Save(); addedAnswer.Answering = "Can't be right"; var updatedAnswer = ARepo.Update(addedAnswer); ARepo.Save(); Assert.AreEqual(1, ARepo.GetAll().Count()); Assert.AreEqual(1, QRepo.Get(addedAnswer.QuestionId).Answers.Count()); Assert.AreEqual("Can't be right", ARepo.Get(updatedAnswer.Id).Answering); }
public void GetAll_WillReturn_Records() { Assert.True(_db.GetAll().ToList().Count > 0); }
/// <summary> /// Bind the context and the session with the content /// </summary> /// <param name="context">Context page</param> /// <param name="session">Session object</param> /// <param name="id">Content ID</param> /// <param name="userId">current user ID</param> public void Bind(HttpContextBase context, ISession session, int?id, int?userId, int?LanguageId) { ContentRepository contentrepository = new ContentRepository(session); if (contentrepository.Entity != null) { QuestionRepository questionrepository = new QuestionRepository(session); FileattachRepository file = new FileattachRepository(session); contentrepository.Entity.ContentId = id; contentrepository.LoadByKey(); if (contentrepository.Entity.Frienlyname != null) { file.Entity.ContentId = questionrepository.Entity.ContentId = contentrepository.Entity.ContentId; questionrepository.LoadByKey(); this.ObjContent = contentrepository.Entity; this.ObjQuestion = questionrepository.Entity; this.CollFiles = file.GetAll(); } contentrepository.Entity = new Content(); contentrepository.Entity.ContentId = this.ObjContent.ContentId; contentrepository.Entity.SectionId = this.ObjContent.SectionId; if (id.HasValue) { int totalCount = 0; AnswerRepository answer = new AnswerRepository(session); IdeaRepository idea = new IdeaRepository(session); CommentRepository comment = new CommentRepository(session); BlogEntryRepository blog = new BlogEntryRepository(session); idea.Entity.ContentId = blog.Entity.ContentId = answer.Entity.ContentId = id.Value; this.CollAnswers = answer.GetAll(); this.CollIdeas = idea.IdeasPaging(1, 6, out totalCount, id.Value, userId); this.IdeasCount = totalCount; foreach (IdeasPaging item in this.CollIdeas) { item.CollComment = comment.CommentsPaging(1, 3, out totalCount, item.IdeaId.Value); this.CommentsCount = totalCount; } this.BlogEntries = blog.BlogContentEntriesPaging(1, 6, out totalCount); this.BlogEntriesCount = totalCount; foreach (BlogEntriesPaging blogEntry in this.BlogEntries) { blogEntry.CollComment = comment.CommentsPagingContent(1, 3, out totalCount, blogEntry.ContentId.Value); this.CommentsCount = totalCount; } this.TopIdeas = idea.TopIdeas(10); this.Statistics = contentrepository.GetContentStatistics(id.Value); } } this.CollContent = contentrepository.GetNewsRelationFrontEnd(); }
public void GetAllAnswers_Correct() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IAnswerRepository ARepo = new AnswerRepository(context); IQuestionRepository QRepo = new QuestionRepository(context); var question1 = new QuestionTO { Questioning = "How can I stop being Rickrolled ?", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "Don't wanna", LastName = "Eat" } }; var question2 = new QuestionTO { Questioning = "Never Gonna what?", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "Rick", LastName = "Ashley" } }; var addedQuestion1 = QRepo.Insert(question1); var addedQuestion2 = QRepo.Insert(question2); QRepo.Save(); var answer1 = new AnswerTO { Answering = "Maybe Someone Else know this", AnswerTime = DateTime.Now.AddHours(1), QuestionId = addedQuestion1.Id, Savior = new UserTO { FirstName = "Random", LastName = "Joe" } }; var answer2 = new AnswerTO { Answering = "Why should I know this ? ", AnswerTime = DateTime.Now.AddHours(1), QuestionId = addedQuestion1.Id, Savior = new UserTO { FirstName = "Someone", LastName = "Else" } }; var answer3 = new AnswerTO { Answering = "Give you up, Let you down", AnswerTime = DateTime.Now.AddHours(1), QuestionId = addedQuestion2.Id, Savior = new UserTO { FirstName = "A specific", LastName = "Asshole" } }; var addedAnswer1 = ARepo.Insert(answer1); var addedAnswer2 = ARepo.Insert(answer2); var addedAnswer3 = ARepo.Insert(answer3); ARepo.Save(); Assert.AreEqual(3, ARepo.GetAll().Count()); }
private void DisplayData() { Model = repository.GetAll(1, 8); }
public IEnumerable <Answer> GetAll() { var answers = AnswerRepository.GetAll(); return(answers); }
public IEnumerable <Answer> GetAll() { return(answerRepo.GetAll()); }