public void It_Saves_A_New_Car_With_Just_That_Feild() { string testCarEngine = "Test new car with only one feild"; Car testCar = new Car(); testCar.Engine = testCarEngine; VehicleService.CreateVehicle(testCar); var builder = new DbContextOptionsBuilder <VehicleRecordDBContext>(); builder.UseInMemoryDatabase("VehicleRecordDB"); using (VehicleRecordDBContext database = new VehicleRecordDBContext(builder.Options)) { Vehicle resultVehicle = database.Vehicles.Where(v => v.Engine == testCarEngine).FirstOrDefault(); Assert.Null(resultVehicle.Make); Assert.Null(resultVehicle.Model); Assert.Equal(testCarEngine, resultVehicle.Engine); Assert.Null(resultVehicle.BodyType); Assert.Null(resultVehicle.Wheels); Assert.Null(resultVehicle.Doors); Assert.Equal((short)VehicleType.Car, resultVehicle.VehicleType); } }
public void It_Returns_A_No_Fields_Provided_Exception() { Car testCar = new Car(); Assert.Throws <AllAttributesNullException>(() => VehicleService.CreateVehicle(testCar)); }
public void It_Saves_A_New_Car_With_All_The_Feilds() { string testCarMake = "Test new car with all feilds"; string testCarModel = "A4"; string testCarEngine = "4 cylinder Petrol Turbo Intercooled 2.0L"; string testCarBodyType = "5 doors 5 seat Wagon"; int testCarWheels = 4; int testCarDoors = 5; Car testCar = new Car(); testCar.Make = testCarMake; testCar.Model = testCarModel; testCar.Engine = testCarEngine; testCar.BodyType = testCarBodyType; testCar.Wheels = testCarWheels; testCar.Doors = testCarDoors; VehicleService.CreateVehicle(testCar); var builder = new DbContextOptionsBuilder <VehicleRecordDBContext>(); builder.UseInMemoryDatabase("VehicleRecordDB"); using (VehicleRecordDBContext database = new VehicleRecordDBContext(builder.Options)) { Vehicle resultVehicle = database.Vehicles.Where(v => v.Make == testCarMake).FirstOrDefault(); Assert.Equal(testCarMake, resultVehicle.Make); Assert.Equal(testCarModel, resultVehicle.Model); Assert.Equal(testCarEngine, resultVehicle.Engine); Assert.Equal(testCarBodyType, resultVehicle.BodyType); Assert.Equal(testCarWheels, resultVehicle.Wheels); Assert.Equal(testCarDoors, resultVehicle.Doors); Assert.Equal((short)VehicleType.Car, resultVehicle.VehicleType); } }
protected async Task HandleValidSubmit() { await VehicleService.CreateVehicle(Vehicle); NavigationManager.NavigateTo("/"); }
public int CreateCar([FromBody] Car car) { VehicleService.CreateVehicle(car); return(0); }