public async Task Details_ReturnsCorrectViewModel() { var solutions = new[] { new Solution { Id = 1, Title = "First Solution", Content = "First Content", Author = new User() }, new Solution { Id = 2, Title = "Second Solution", Content = "Second Content", Author = new User() }, new Solution { Id = 3, Title = "Third Solution", Content = "Third Content", Author = new User() }, }; var context = TestsDbContext.GetDbContext(); context.Solutions.AddRange(solutions); context.SaveChanges(); var controller = new SolutionsController(context, TestsAutoMapper.GetMapper()); var expectedSolution = solutions[1]; var result = await controller.Details(expectedSolution.Id); var model = (result as ViewResult).ViewData.Model as SolutionDetailsViewModel; Assert.IsNotNull(model); Assert.AreEqual(model.Id, expectedSolution.Id); Assert.AreEqual(model.Title, expectedSolution.Title); Assert.AreEqual(model.Content, expectedSolution.Content); Assert.IsInstanceOfType(model, typeof(SolutionDetailsViewModel)); }
public async Task FailedDetailCall() { _solutionRepository.Setup(repo => repo.Get(2, true)).Returns(Task.FromResult <Solution>(null)); var controller = new SolutionsController(_solutionRepository.Object, null, _itemTranslationRepository.Object); var result = await controller.Details(2); Assert.IsType <NotFoundResult>(result); }
public async Task InvalidDetailModel() { var model = new Solution { Id = 0, LastModified = DateTime.UtcNow, Title = "Title 1" }; _solutionRepository.Setup(repo => repo.Get(0, true)).Returns(Task.FromResult <Solution>(null)); var controller = new SolutionsController(_solutionRepository.Object, null, _itemTranslationRepository.Object); var result = await controller.Details(model.Id); Assert.IsType <NotFoundResult>(result); }
public async Task SuccesfulDetailCall() { var model = new Solution { Id = 0, LastModified = DateTime.UtcNow, Title = "Title 1" }; _solutionRepository.Setup(repo => repo.Get(0, true)).Returns(Task.FromResult <Solution>(model)); var controller = new SolutionsController(_solutionRepository.Object, null, _itemTranslationRepository.Object); var result = await controller.Details(model.Id); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(model, viewResult.Model); }