static void Main(string[] args) { var carController = new CarsController(); var detailController = new DetailsController(); var manufacturerController = new ManufacturerController(); var manufacturerService = new ManufacturerService(); //var allCars = carController.GetAll(); //var carById = carController.GetId(1); var allDetails = detailController.GetAll(); //var detailById = detailController.GetId(2); //detailController.Insert(null); //detailController.Update(null); //detailController.Delete(1002); carController.Add(null); //carController.Update(null); //carController.Delete(6); var allManufacturers = manufacturerController.GetAll(); //var richcars = manufacturerController.GetRich(); var mostexpensive = manufacturerService.GetMostExpensive(); Console.ReadKey(); }
public void AddCar_ShouldThrowArgumentNullException_WhenCalledWithCarWithModelNullOrEmpty(string model) { var car = new CarChild(make: "actual make", model: model); var controller = new CarsController(); Assert.Throws <ArgumentNullException>(() => controller.Add(car)); }
public void AddCar_ShouldThrowArgumentNullException_WhenCalledWithCarWithMakeNullOrEmpty(string make) { var car = new CarChild(make: make, model: "valid model"); var controller = new CarsController(); Assert.Throws <ArgumentNullException>(() => controller.Add(car)); }
public void Add_ShouldThrowArgumentNullException_WhenCarIsNull() { var mockedRepo = Mock.Create <ICarsRepository>(); var controller = new CarsController(mockedRepo); Assert.ThrowsException <ArgumentNullException>(() => controller.Add(null)); }
public void AddCar_ShouldReturnIView_IfCarIsValid() { var car = new CarChild(5, "make", "model", 2000); var mockRepo = new Mock <ICarsRepository>(); mockRepo.Setup(x => x.GetById(5)).Returns(car); var controller = new CarsController(mockRepo.Object); Assert.IsInstanceOf <IView>(controller.Add(car)); }
public void Add_ShouldThrowArgumentNullException_WhenCarMakeIsEmpty() { var car = Mock.Create <ICar>(); Mock.Arrange(() => car.Model).Returns("valid"); Mock.Arrange(() => car.Make).Returns(""); var mockedRepo = Mock.Create <ICarsRepository>(); var controller = new CarsController(mockedRepo); Assert.ThrowsException <ArgumentNullException>(() => controller.Add(car)); }
public void Details_ShouldThrowArgumentNullException_IfCarIsNull() { Car car = null; var carKid = new CarChild(5, "6", "7", 2000); var mockedRepo = new Mock <ICarsRepository>(); mockedRepo.Setup(x => x.GetById(It.IsAny <int>())).Returns(car); var controller = new CarsController(mockedRepo.Object); Assert.Throws <ArgumentNullException>(() => controller.Add(carKid)); }
public void AddCar_ShouldCallRepositoryGetByIdWithSameIDPassed_IfCarIsValid() { var expectedId = 8; var car = new CarChild(id: expectedId, make: "make", model: "model"); var mockedRepo = new Mock <ICarsRepository>(); mockedRepo.Setup(x => x.GetById(expectedId)).Returns(car).Verifiable(); var controller = new CarsController(mockedRepo.Object); controller.Add(car); mockedRepo.Verify(x => x.GetById(expectedId), Times.Once); }
public void AddCar_ShouldCallRepositoryAddCar_WithCarPassed() { var car = new CarChild(id: 5, make: "make", model: "model"); var mockedRepo = new Mock <ICarsRepository>(); mockedRepo.Setup(x => x.Add(car)).Verifiable(); mockedRepo.Setup(x => x.GetById(5)).Returns(car); var controller = new CarsController(mockedRepo.Object); controller.Add(car); mockedRepo.Verify(x => x.Add(car), Times.Once); }
public void Add_ShouldCallRepoCall_WhenCarIsValid() { var mockedCar = Mock.Create <ICar>(); Mock.Arrange(() => mockedCar.Make).Returns("make"); Mock.Arrange(() => mockedCar.Model).Returns("model"); var mockedRepo = Mock.Create <ICarsRepository>(); Mock.Arrange(() => mockedRepo.Add(mockedCar)).OccursOnce(); var controller = new CarsController(mockedRepo); controller.Add(mockedCar); Mock.Assert(mockedRepo); }
public void Create_ReturnsBadRequest_GivenInvalidCar() { // Arrange & Act var mockService = new Mock <ICarService>(); var controller = new CarsController(mockService.Object); mockService.Setup(repo => repo.Add(null)) .Returns(new ErrorResult()); controller.ModelState.AddModelError("error", "some error"); // Act var result = controller.Add(car: null); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void Add_CarParameterMakeOrModelAreNull_ShouldThrowTheCorrectExceptionMessage() { var actual = false; Car car = new FakeCar(); var controller = new CarsController(); try { controller.Add(car); } catch (ArgumentNullException ex) { actual = ex.Message.Contains("Car make and model cannot be empty"); } Assert.IsTrue(actual); }
public void Create_ReturnsOkResult_GivenInvalidCar() { // Arrange & Act var testCar = GetTestCar().Data; var mockService = new Mock <ICarService>(); var controller = new CarsController(mockService.Object); mockService.Setup(repo => repo.Add(testCar)) .Returns(new SuccessResult()); // Act var result = controller.Add(testCar); // Assert Assert.IsType <OkObjectResult>(result); }
public void Add_CarParameterIsNull_ShouldThrowTheCorrectExceptionMessage() { var actual = false; Car car = null; var controller = new CarsController(); try { controller.Add(car); } catch (ArgumentNullException ex) { actual = ex.Message.Contains("Car cannot be null"); } Assert.IsTrue(actual); }
public void Add_ShouldReturnIView_WhenCarIsValid() { var hardcodedId = 5; var mockedCar = Mock.Create <ICar>(); Mock.Arrange(() => mockedCar.Id).Returns(hardcodedId); Mock.Arrange(() => mockedCar.Make).Returns("make"); Mock.Arrange(() => mockedCar.Model).Returns("model"); var mockedRepo = Mock.Create <ICarsRepository>(); Mock.Arrange(() => mockedRepo.GetById(hardcodedId)).Returns(mockedCar); var controller = new CarsController(mockedRepo); Assert.IsInstanceOfType(controller.Add(mockedCar), typeof(IView)); }
public void Add_ShouldAccessICarsRepositoryAddMethod() { var car = new Car(); car.Make = "asd"; car.Model = "ass"; car.Id = 1; var fakeCarRepo = new Mock <ICarsRepository>(); fakeCarRepo.Setup(cp => cp.GetById(It.IsAny <int>())).Returns(car); fakeCarRepo.Setup(cp => cp.Add(It.IsAny <Car>())); var controller = new CarsController(fakeCarRepo.Object); var actual = controller.Add(car); fakeCarRepo.Verify(repo => repo.Add(It.IsAny <Car>()), Times.Exactly(1)); }
public void Add_ShouldAccessICarsRepositoryAddMethod() { // Arrange var car = new Car(); car.Make = "Mazda"; car.Model = "MX-7"; car.Id = 1; var fakeCarRepo = new Mock <ICarsRepository>(); fakeCarRepo.Setup(z => z.GetById(It.IsAny <int>())).Returns(car); fakeCarRepo.Setup(z => z.Add(It.IsAny <Car>())); var controller = new CarsController(fakeCarRepo.Object); // Act var actual = controller.Add(car); // Assert fakeCarRepo.Verify(repo => repo.Add(It.IsAny <Car>()), Times.Exactly(1)); }
public void AddCar_ShouldThrowArgumentNullException_WhenCalledWithNull() { var controller = new CarsController(); Assert.Throws <ArgumentNullException>(() => controller.Add(null)); }