public void Validate_ShouldContainNotification_WhenIdIsZero() { var notifications = new UpdateDriverCommand() .Validate(); notifications.Should().ContainEquivalentOf(new Notification("driver.id", "Driver id must be informed")); }
public async Task <ActionResult> Update(int id, UpdateDriverCommand driver) { driver.Id = id; await mediator.Send(driver); return(ResponsePut()); }
public void Validate_ShouldNotContainNotification_WhenIdIsValid() { var notifications = new UpdateDriverCommand { Id = 1 } .Validate(); notifications.Where(n => n.Code == "driver.id") .Should().BeEmpty(); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateDriverCommand command) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var response = await this._mediator.Send(command); return(this.Ok()); }
public async Task <ActionResult> PutAsync(Guid driverId, [FromBody] ModifyDriverDto driverInfo) { var command = new UpdateDriverCommand(driverId, driverInfo); try { await _mediator.Send(command); return(Ok()); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } }
public async Task Handle_ShouldNotCallNotification_WhenInvalidDriver() { var command = new UpdateDriverCommand { Id = 1, Name = "Name", BodyAvarageTemperature = 36, Gender = Gender.Male, Height = 1.74m, Weight = 73 }; await instance.Handle(command, new CancellationToken()); driverRepository.Verify(x => x.Update(It.IsAny <Driver>(), It.IsAny <CancellationToken>())); notificationService.VerifyNoOtherCalls(); }
public Task <bool> Handle(UpdateDriverCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } var driver = new Driver(message.Id, message.Name, message.LastName, message.CarModel, message.CarBrand, message.CarPlate, message.Zipcode, message.Address, message.Coordinates); _driverRepository.Update(driver); if (Commit()) { Bus.RaiseEvent(new DriverRegisteredEvent(driver.Id, driver.Name, driver.LastName, driver.CarModel, driver.CarBrand, driver.CarPlate, driver.Zipcode, driver.Address, driver.Coordinates)); } return(Task.FromResult(true)); }
public async Task Handle_WithData_RefetchesCoordinatesAndUpdatesDriver() { // Arrange var handler = new UpdateDriverCommandHandler(_driverContext, _mapper, _geocoder); var command = new UpdateDriverCommand(_driverId, new ModifyDriverDto { FirstName = "Ciclano", LastName = "da Silva Souza", CarBrand = "Ford", CarModel = "Ecosport", CarRegistrationPlate = "LUJ321", AddressLine1 = "Av Brig Luiz Antonio, 411", AddressLine2 = "Bela Vista", AddressMunicipality = "São Paulo", AddressState = "SP", AddressZipCode = "01317-000" }); // Act await handler.Handle(command, CancellationToken.None); // Assert var driver = await _driverContext.Drivers.FirstAsync(); Assert.Equal("Ciclano", driver.FirstName); Assert.Equal("da Silva Souza", driver.LastName); Assert.Equal("Ford", driver.Car.Brand); Assert.Equal("Ecosport", driver.Car.Model); Assert.Equal("LUJ321", driver.Car.RegistrationPlate); Assert.Equal("Av Brig Luiz Antonio, 411", driver.Address.Line1); Assert.Equal("Bela Vista", driver.Address.Line2); Assert.Equal("São Paulo", driver.Address.Municipality); Assert.Equal("SP", driver.Address.State); Assert.Equal("01317-000", driver.Address.ZipCode); Assert.Equal(20, driver.Address.Coordinates.Latitude); Assert.Equal(-30, driver.Address.Coordinates.Longitude); }
public async Task UpdateDriver(int id, [FromBody] UpdateDriverCommand command) { command.SetId(id); await Mediator.Send(command); }