public async Task Index_Given_ResultFromService_Should_ReturnViewModelWithExpectedName()
        {
            // Arrange
            const string expectedName = "Example";

            var items = new List <JobCategory>
            {
                new JobCategory
                {
                    Name = expectedName
                }
            };

            var serviceMock = new Mock <IJobCategoryService>();

            serviceMock.Setup(x => x.GetAllCategories()).ReturnsAsync(items);

            var controller = new JobCategoryController(serviceMock.Object, _mapper);

            // Act
            var result = await controller.Index();

            // Assert
            var viewResult = (ViewResult)result;
            var model      = (IList <JobCategoryViewModel>)viewResult.Model;
            var actualName = model.First().Name;

            Assert.Equal(expectedName, actualName);
        }
        public async Task Index_Given_ThreeResultsFromService_Should_ReturnCorrectNumberOfViewModels()
        {
            // Arrange
            var items = new List <JobCategory>
            {
                new JobCategory(),
                new JobCategory(),
                new JobCategory()
            };

            var serviceMock = new Mock <IJobCategoryService>();

            serviceMock.Setup(x => x.GetAllCategories()).ReturnsAsync(items);

            var controller = new JobCategoryController(serviceMock.Object, _mapper);

            // Act
            var result = await controller.Index();

            // Assert
            var viewResult = (ViewResult)result;
            var model      = (IList <JobCategoryViewModel>)viewResult.Model;

            Assert.Equal(3, model.Count);
        }
        public async Task Index_Given_NoResultsFromService_Should_ReturnEmptyModel()
        {
            // Arrange
            var serviceMock = new Mock <IJobCategoryService>();

            serviceMock.Setup(x => x.GetAllCategories()).ReturnsAsync(new List <JobCategory>());

            var controller = new JobCategoryController(serviceMock.Object, _mapper);

            // Act
            var result = await controller.Index();

            // Assert
            var viewResult = (ViewResult)result;
            var model      = (IList <JobCategoryViewModel>)viewResult.Model;

            Assert.Empty(model);
        }