public void GetbyIdShouldRequestListIds() { QuestionsRepository target = new QuestionsRepository(StackClientFactoryMock.Object); StackClient.Setup(c => c.GetQuestions(It.Is<IEnumerable<int>>(arr => arr.IsEqual(new[] { 0, 1, 2, 3, 4, 5 })), It.IsAny<int?>(), It.IsAny<int?>(), false, false, null, null, null, null, null)) .Returns(new PagedList<Question>(new List<Question>() { new Question {Id = 1}, new Question {Id = 2}, new Question {Id = 3}, new Question {Id = 4}, new Question {Id = 5}, new Question {Id = 6}} ) { PageSize = 6, TotalItems = 6 }); int[] ids = new[] { 0, 1, 2, 3, 4, 5 }; List<QuestionInfo> actual; actual = target.Get("siteaddr", ids); StackClient.VerifyAll(); var expected = new List<QuestionInfo>() { new QuestionInfo {Id = 1}, new QuestionInfo {Id = 2}, new QuestionInfo {Id = 3}, new QuestionInfo {Id = 4}, new QuestionInfo {Id = 5}, new QuestionInfo {Id = 6} }; CollectionAssert.AreEqual(expected, actual); }
public async Task Get() { // arrange\ var fixture = new Fixture(); for (int i = 0; i < 10; i++) { var question = fixture.Build <Core.CoreModels.Question>() .Without(x => x.Id) .Create(); question.MemberId = 1; var questionId = await _repository.Add(question); } // act var questions = await _repository.Get(); // assert Assert.NotNull(questions); Assert.NotEmpty(questions); }
public IActionResult ViewQuestion(int id) { var questionsRepo = new QuestionsRepository(_connectionString); var question = questionsRepo.Get(id); var viewModel = new ViewQuestionViewModel { Question = question }; if (User.Identity.IsAuthenticated) { var userRepo = new UserRepository(_connectionString); viewModel.CurrentUser = userRepo.GetByEmail(User.Identity.Name); } if (question == null) { return(Redirect("/")); } return(View(viewModel)); }
public void GetShouldReturnListOfQuestionsOnePage() { QuestionsRepository target = new QuestionsRepository(StackClientFactoryMock.Object); StackClient.Setup(c => c.GetQuestionsByUser(c_TestId, QuestionsByUserSort.Activity, SortDirection.Descending, 1, ApiSettings.PageSize, false, false, null, null, null, null, null)) .Returns(new PagedList<Question>(new List<Question>() { new Question {Id = 1}, new Question {Id = 2}} ) { PageSize = 2, TotalItems = 2 }); List<QuestionInfo> actual; actual = target.Get("siteaddr", c_TestId); StackClient.VerifyAll(); var expected = new List<QuestionInfo>() { new QuestionInfo {Id = 1}, new QuestionInfo {Id = 2} }; CollectionAssert.AreEqual(expected, actual); }
public IActionResult Index() { var repo = new QuestionsRepository(_connectionString); return(View(repo.Get())); }