public void Get_ShouldReturnAllMakes() { mapper.Execute(); var makesMock = new Mock <IVehicleMakesService>(); IQueryable <VehicleMake> makes = new List <VehicleMake>() { new VehicleMake() { Id = 1, Name = "Audi" }, new VehicleMake() { Id = 2, Name = "Ford" } }.AsQueryable(); makesMock.Setup(v => v.GetAll()) .Returns(makes); var controller = new MakesController(makesMock.Object, null); var result = controller.Get(); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <List <VehicleMakeResponseModel> >)); var responseContent = ((OkNegotiatedContentResult <List <VehicleMakeResponseModel> >)result).Content; Assert.AreEqual(responseContent.Count, 2); Assert.AreEqual(responseContent[0].Id, 1); Assert.AreEqual(responseContent[1].Id, 2); makesMock.VerifyAll(); }
public MakesControllerTests() { _makesRepository = new Mock <IMakesRepository>(); _unitOfWork = new Mock <IUnitOfWork>(); _mapper = new Mock <IMapper>(); _controller = new MakesController(_makesRepository.Object, _mapper.Object, _unitOfWork.Object); }
public void Get_ShouldReturnInternalServerErrorAndLogError_WhenMakesServiceisNull() { var controller = new MakesController(null, mockedLogger.Object); var result = controller.Get(); Assert.IsInstanceOfType(result, typeof(InternalServerErrorResult)); mockedLogger.Verify(x => x.LogError(It.IsAny <Exception>(), "", controllerName, "Get")); }