public async Task TruckHandler_Delete_invalid_no_delete_found() { var mockContextRepository = new Mock <IContextRepository>(); var mockTruckRepository = new Mock <ITruckRepository>(); TruckDeleteCommand trunkDeleteCommand = new TruckDeleteCommand(); trunkDeleteCommand.Id = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9"; Truck _truck = new Truck(); _truck.Id = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9"; _truck.Color = "Red"; _truck.Description = "desciption"; _truck.Image = "img1.jpg"; _truck.Model = EnumModel.FH; _truck.ModelYear = DateTime.Now.Year; mockTruckRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_truck); mockContextRepository.Setup(x => x.Delete(It.IsAny <string>())).ReturnsAsync(false); TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object); var _return = await _handler.Handle(trunkDeleteCommand); Assert.False(_return.Success); Assert.Equal(HttpStatusCode.BadRequest, _return.Code); Assert.False((bool)_return.Data); }
public async Task TruckHandler_Update_invalid_no_data_found() { var mockContextRepository = new Mock <IContextRepository>(); var mockTruckRepository = new Mock <ITruckRepository>(); TruckUpdateCommand trunlUpdateCommand = new TruckUpdateCommand(); trunlUpdateCommand.Id = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9"; trunlUpdateCommand.Color = "Blue"; trunlUpdateCommand.Image = "img.jpg"; trunlUpdateCommand.Description = "desciption"; trunlUpdateCommand.Model = 1; trunlUpdateCommand.ModelYear = DateTime.Now.Year; Truck _truck = new Truck(); _truck = null; mockTruckRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_truck); mockContextRepository.Setup(x => x.Update(It.IsAny <Truck>())).ReturnsAsync(true); TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object); var _return = await _handler.Handle(trunlUpdateCommand); Assert.False(_return.Success); Assert.Equal(HttpStatusCode.NotFound, _return.Code); Assert.Null(_return.Data); }
public void Work() { var vehicles = new List <IVehicle> { new Truck(), new Car(), new SUV(), new SportCar(), new Bicycle(), }; var sportCarHandler = new SportCarHandler(); var suvHandler = new SUVHandler(); var carHandler = new CarHandler(); var TruckHandler = new TruckHandler(); sportCarHandler.SetNext(suvHandler).SetNext(carHandler) .SetNext(TruckHandler); foreach (var vehicle in vehicles) { var result = sportCarHandler.Handle(vehicle); if (result == null) { Console.Write($"{vehicle.GetType().Name} can't be filled by fuel"); } } }
public async Task TruckHandler_Update_valid() { var mockContextRepository = new Mock <IContextRepository>(); var mockTruckRepository = new Mock <ITruckRepository>(); TruckUpdateCommand trunlUpdateCommand = new TruckUpdateCommand(); trunlUpdateCommand.Id = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9"; trunlUpdateCommand.Color = "Blue"; trunlUpdateCommand.Image = "img.jpg"; trunlUpdateCommand.Description = "description"; trunlUpdateCommand.Model = 1; trunlUpdateCommand.ModelYear = DateTime.Now.Year; Truck _truck = new Truck(); _truck.Id = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9"; _truck.Color = "Red"; _truck.Image = "img1.jpg"; _truck.Model = EnumModel.FH; _truck.Description = "description"; _truck.YearOfManufacture = DateTime.Now.Year; _truck.ModelYear = DateTime.Now.Year; mockTruckRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_truck); mockContextRepository.Setup(x => x.Update(It.IsAny <Truck>())).ReturnsAsync(true); TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object); var _return = await _handler.Handle(trunlUpdateCommand); Assert.True(_return.Success); Assert.Equal(HttpStatusCode.OK, _return.Code); Assert.True((bool)_return.Data); Assert.Equal("45f65a56-e30d-4a61-8e40-e14a4cc35ce9", _truck.Id); Assert.Equal("Red", _truck.Color); Assert.Equal("img1.jpg", _truck.Image); Assert.Equal(EnumModel.FH, _truck.Model); Assert.Equal(DateTime.Now.Year, _truck.ModelYear); Assert.Equal(DateTime.Now.Year, _truck.YearOfManufacture); Assert.Equal("description", _truck.Description); }
public async Task TruckHandler_insert_invalid() { var mockContextRepository = new Mock <IContextRepository>(); var mockTruckRepository = new Mock <ITruckRepository>(); TruckInsertCommand trunlInsertCommand = new TruckInsertCommand(); trunlInsertCommand.Color = "Blue"; trunlInsertCommand.Image = "img.jpg"; trunlInsertCommand.Description = "desciption"; trunlInsertCommand.Model = 1; trunlInsertCommand.ModelYear = DateTime.Now.Year; mockContextRepository.Setup(x => x.Add(It.IsAny <Truck>())).ReturnsAsync(false); TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object); var _return = await _handler.Handle(trunlInsertCommand); Assert.False(_return.Success); Assert.False((bool)_return.Data); Assert.Equal(HttpStatusCode.BadRequest, _return.Code); }
public async Task TruckHandler_Delete_invalid_no_data_found() { var mockContextRepository = new Mock <IContextRepository>(); var mockTruckRepository = new Mock <ITruckRepository>(); TruckDeleteCommand trunkDeleteCommand = new TruckDeleteCommand(); trunkDeleteCommand.Id = "45f65a56-e30d-4a61-8e40-e14a4cc35ce9"; Truck _truck = new Truck(); _truck = null; mockTruckRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_truck); mockContextRepository.Setup(x => x.Delete(It.IsAny <string>())).ReturnsAsync(true); TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object); var _return = await _handler.Handle(trunkDeleteCommand); Assert.False(_return.Success); Assert.Equal(HttpStatusCode.NotFound, _return.Code); Assert.Null(_return.Data); }
public List <int> getAvailableTrucks() { return(TruckHandler.GetAvailableTrucks()); }
public List <int> getFunctionalTrucks() { return(TruckHandler.GetFunctionalTrucks()); }
//get all trucks public List <Truck> getTrucks() { return(TruckHandler.GetTrucks()); }
public Truck getTruck(int truckId) { return(TruckHandler.GetTruck(truckId)); }
public void updateTruck(int truckId, string status) { TruckHandler.UpdateTruck(truckId, status); }
public void createTruck(string status) { TruckHandler.CreateTruck(status); }