public async Task DetailsGet_ShouldCallRepositoryToGetDetailsForExistingEntityAndReturnViewWithData()
        {
            // Arrange

            // Act
            var result = await _controller.Details(_existingLabel.LabelId);

            var viewResult = (ViewResult)result;
            var model      = (Label)viewResult.Model;

            // Assert
            _mockRepository.Verify(mr => mr.GetById(_existingLabel.LabelId), Times.Once);
            Assert.Null(viewResult.ViewName);
            Assert.Equal(_existingLabel, model);
        }
예제 #2
0
        public async void Details_CallsGetByIdOnce()
        {
            // Arrange
            var repoMock = new Mock <IRepository <Label> >();

            repoMock.Setup(repo => repo.GetById(It.IsAny <int>())).ReturnsAsync(_testLabel1);
            var controller = new LabelsController(repoMock.Object);

            // Act
            await controller.Details(_testLabel1.Id);

            // Assert
            repoMock.Verify(repo => repo.GetById(It.IsAny <int>()), Times.Once);
        }
예제 #3
0
        public async void Details_ReturnsCorrectView()
        {
            // Arrange
            var repoMock = new Mock <IRepository <Label> >();

            repoMock.Setup(repo => repo.GetById(It.IsAny <int>())).ReturnsAsync(_testLabel1);
            var controller = new LabelsController(repoMock.Object);

            // Act
            var result = (ViewResult)await controller.Details(_testLabel1.Id);

            // Assert
            Assert.Null(result.ViewName);
        }
예제 #4
0
        public async void Details_ReturnsNotFound_WhenLabelIsNull()
        {
            // Arrange
            var repoMock = new Mock <IRepository <Label> >();

            repoMock.Setup(repo => repo.GetById(It.IsAny <int>())).ReturnsAsync(null as Label);
            var controller = new LabelsController(repoMock.Object);

            // Act
            var result = await controller.Details(null);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }