public async void Index_ReturnsCorrectView() { // Arrange var repoMock = new Mock <IRepository <Label> >(); repoMock.Setup(repo => repo.GetAllAsList()).ReturnsAsync(new List <Label> { }); var controller = new LabelsController(repoMock.Object); // Act var result = (ViewResult)await controller.Index(); // Assert Assert.Null(result.ViewName); }
public async void Index_CallsGetAllAsListOnce() { // Arrange var repoMock = new Mock <IRepository <Label> >(); repoMock.Setup(repo => repo.GetAllAsList()).ReturnsAsync(new List <Label> { }); var controller = new LabelsController(repoMock.Object); // Act await controller.Index(); // Assert repoMock.Verify(repo => repo.GetAllAsList(), Times.Once); }
public async Task IndexGet_ShouldCallRepositoryToGetAllEntitiesAndReturnViewWithDataSortedAlphabeticallyByName() { // Arrange // Act var result = await _controller.Index(); var viewResult = (ViewResult)result; var model = (List <Label>)viewResult.Model; // Assert _mockRepository.Verify(mr => mr.GetAllAlphabetical(), Times.Once); Assert.IsType <ViewResult>(result); Assert.Null(viewResult.ViewName); Assert.Equal(model, TestDataGraph.Labels.LabelsAlphabetizedByLabelName); }
public async void Index_ReturnsCorrectList() { // Arrange var list = new List <Label> { _testLabel1, _testLabel2 }; var repoMock = new Mock <IRepository <Label> >(); repoMock.Setup(repo => repo.GetAllAsList()).ReturnsAsync(list); var controller = new LabelsController(repoMock.Object); // Act var result = (ViewResult)await controller.Index(); // Assert Assert.Equal(list, result.Model); }