public IActionResult Post([FromForm] FakeVehicle fakeVehicle) { if (!ModelState.IsValid) { throw new Exception("Model is invalid -> it should have been auto checked and auto 400 returned."); } _fakeVehicleRepository.Add(fakeVehicle); return(CreatedAtRoute("GetId", new { id = fakeVehicle.Id }, null)); }
public void InitiateCommentsCollection_WhenObjectIsConstructed() { // arrange string make = "mercedes"; string model = "benz"; decimal price = 150m; var vehicleType = VehicleType.Car; var vehicle = new FakeVehicle(make, model, price, vehicleType); // act and assert Assert.IsNotNull(vehicle.Comments); }
public void AssingVehicleTypeCorrectly_WhenVechicleIsConstructed() { // arrange string make = "mercedes"; string model = "benz"; decimal price = 150m; var vehicleType = VehicleType.Car; var vehicle = new FakeVehicle(make, model, price, vehicleType); // act and assert Assert.AreEqual(vehicleType, vehicle.Type); }
public void Add(FakeVehicle fakeVehicle) { if (fakeVehicle == null) { throw new ArgumentNullException(nameof(fakeVehicle)); } // NOTE: Obviously, not thread safe. fakeVehicle.Id = _fakeVehicles.Count + 1; _fakeVehicles.Add(fakeVehicle.Id, fakeVehicle); }
public void Can_Evade_Trouble_And_Alert_Offending_Driver() { // Arrange (set up a scenario) FakeVehicle fakeVehicle = new FakeVehicle(); Driver target = new Driver(fakeVehicle); // Act (attempt the operation) bool success = target.EvasiveManeuvers(true); // Assert (verify the result) Assert.IsTrue(success); Assert.IsTrue(fakeVehicle.CalledHonkHorn == 1); Assert.IsTrue(fakeVehicle.CalledApplyBrakes == 1); }
public void ShouldReturnStringContainingNoComments_WhenNoCommentsInCollection() { // arrange string make = "mercedes"; string model = "benz"; decimal price = 150m; var vehicleType = VehicleType.Car; var vehicle = new FakeVehicle(make, model, price, vehicleType); string expectedString = "NO COMMENTS"; // act var resultString = vehicle.PrintComments(); // assert StringAssert.Contains(expectedString, resultString); }
public void ShouldCallToStringToAllCommentsInCollection_WhenCalled() { // arrange string make = "mercedes"; string model = "benz"; decimal price = 150m; var vehicleType = VehicleType.Car; var vehicle = new FakeVehicle(make, model, price, vehicleType); var commentMock = new Mock <IComment>(); commentMock.Setup(x => x.ToString()); vehicle.Comments.Add(commentMock.Object); // act vehicle.PrintComments(); // assert commentMock.Verify(x => x.ToString(), Times.Once); }