public void Add_MissingName_Rejected() { var input = _vehiclesGenerator.Create(); input.Name = null; var result = _unitUnderTests.Add(input); Assert.IsNotNull(result, "creation result is missing"); Assert.AreEqual(StatusCodes.Status400BadRequest, result.StatusCode, "Item without obligatory name was added, when shouldn't"); }
public async Task VehicleController_Add_WhenVehicleExists_ShouldReturnVehicleAlreadyExistsStatusCode() { // Arrange var vinReference = StringHelper.RandomString(6); _mockVehicleRepository .Setup(m => m.GetByVinAsync(It.IsAny <string>())) .ReturnsAsync(TestDataHelper.GetVehicle(vinReference)) .Verifiable(); _mockVehicleRepository .Setup(m => m.AddAsync(It.IsAny <Vehicle>())) .Returns(Task.FromResult <object>(null)) .Verifiable(); // Act var vehiclesController = new VehiclesController(_mockVehicleRepository.Object, _mockLogger.Object); var result = await vehiclesController.Add(new VehicleModel { VehicleNumber = vinReference, TrafficServiceProvider = "Pegasus Travels", Make = "Volvo", Model = "Transporter", Year = "2016", Seats = new List <VehicleModel.Seat> { new VehicleModel.Seat { SeatNumber = "1", Position = "Aisle" }, new VehicleModel.Seat { SeatNumber = "2", Position = "Middle" }, new VehicleModel.Seat { SeatNumber = "3", Position = "Window" } } }); var statusCodeResult = result as ObjectResult; // Assert Assert.IsNotNull(statusCodeResult); Assert.AreEqual(ErrorCodes.VEHICLE_ALREADY_EXISTS, statusCodeResult.StatusCode.Value); _mockVehicleRepository.Verify(m => m.GetByVinAsync(It.IsAny <string>()), Times.Once); _mockVehicleRepository.Verify(m => m.AddAsync(It.IsAny <Vehicle>()), Times.Never); }
public Vehicle(string Model, SharpDX.Vector3 Position, VehiclesController VehiclesController) { Element = new ivmp_server_core.Vehicle(Model, Position); VehiclesController.Add(Element); }