public void Update_computer_name() { ComputersController computersController = new ComputersController(); _managementController.AddComputer(new AddComputerDto { Name = "TestComputer", Description = "New computer", Price = 1500, ImageFilename = "test.png" }); ComputerInfoDto computerInfoDto = computersController.FindComputerByName("TestComputer"); UpdateComputerDto updateComputerDto = new UpdateComputerDto { Name = "Amstrad CPC", Description = "New Amstrad with 128Kb", Price = 1000, ImageFilename = "amstrad.png" }; _managementController.UpdateComputer(computerInfoDto.Id, updateComputerDto); ComputerInfoDto updatedComputer = computersController.GetComputerInfo(computerInfoDto.Id); Assert.AreEqual(computerInfoDto.Id, updatedComputer.Id); Assert.AreEqual(updateComputerDto.Name, updatedComputer.Name); Assert.AreEqual(updateComputerDto.Description, updatedComputer.Description); Assert.AreEqual(updateComputerDto.Price, updatedComputer.Price); Assert.AreEqual(updateComputerDto.ImageFilename, updatedComputer.ImageFilename); }
public void UpdateComputer(string computerId, UpdateComputerDto updateComputerDto) { AuthenticationService.AuthenticateRoot(_username, _password); ValidationService.ValidateUpdateComputerDto(updateComputerDto); Computer computer = QueryService.FindComputerByGuid(computerId); if (computer == null) { throw new Exception("Computer not found. Id: " + computerId); } computer.Name = updateComputerDto.Name; computer.Description = updateComputerDto.Description; computer.Price = updateComputerDto.Price; computer.ImageFilename = updateComputerDto.ImageFilename; DatabaseContext.GetEntities().Save(); }
public static void ValidateUpdateComputerDto(UpdateComputerDto updateComputerDto) { if (string.IsNullOrEmpty(updateComputerDto.Name)) { throw new Exception("Computer Name cannot be null or empty"); } if (string.IsNullOrEmpty(updateComputerDto.Description)) { throw new Exception("Computer Description cannot be null or empty"); } if (string.IsNullOrEmpty(updateComputerDto.ImageFilename)) { throw new Exception("Computer Filename cannot be null or empty"); } if (updateComputerDto.Price < 0) { throw new Exception("Computer price cannot be negative"); } }