public async Task IndexReturnsCorrectViewModel() { var users = new List<ApplicationUser> { new ApplicationUser { Id = It.IsAny<string>() }, new ApplicationUser { Id = It.IsAny<string>() }}; var viewModel = new IndexViewModel { Users = users }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<IndexQuery>())).ReturnsAsync(viewModel); var controller = new SiteController(null, null, mediator.Object); var result = await controller.Index() as ViewResult; var model = result.ViewData.Model as IndexViewModel; Assert.Equal(model.Users.Count(), users.Count()); Assert.IsType<IndexViewModel>(model); }
public void IndexReturnsCorrectViewModel() { var mediator = new Mock<IMediator>(); var users = new List<ApplicationUser>() { new ApplicationUser { Id = It.IsAny<string>() }, new ApplicationUser { Id = It.IsAny<string>() } }; mediator.Setup(x => x.Send(It.IsAny<AllUsersQuery>())).Returns(users); var controller = new SiteController(null, null, mediator.Object); var result = controller.Index(); var model = ((ViewResult)result).ViewData.Model as SiteAdminModel; Assert.Equal(model.Users.Count(), users.Count()); Assert.IsType<SiteAdminModel>(model); }