/// <summary> /// Execute the request based on the input properties. /// </summary> /// <param name="input">Inputs required to update a Platform.</param> /// <returns></returns> public PlatformResponse Execute(UpdatePlatformNameInput input) { var platformResponse = new PlatformResponse(); try { CheckInputValidity(input); Log.Information("Updating name Platform with Id: [{Id}] to [{NewName}]...", input.Id, input.NewName); var platformToUpdate = Repository.SingleOrDefault(p => p.Id == input.Id); if (platformToUpdate == null) { var exception = new Exception($"Failed to find platform with Id: [{input.Id}]."); Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message); HandleErrors(platformResponse, exception, 404); } else { var previousName = platformToUpdate.Name; platformToUpdate.Name = input.NewName; var updatedPlatform = Repository.Update(platformToUpdate); platformResponse.Platform = updatedPlatform; platformResponse.StatusCode = 200; Log.Information("Updated Platform from [{PreviousName}] to [{NewName}].", previousName, input.NewName); } } catch (Exception exception) { Log.Error(exception, "Failed to update Platform."); HandleErrors(platformResponse, exception); } return(platformResponse); }
public async Task InvalidInputNameIsEmpty(string name) { var invalidInput = new UpdatePlatformNameInput { Id = 666, NewName = name }; var response = await request.ExecuteAsync(invalidInput); response.Should().NotBeNull(); response.ErrorResponse.Should().NotBeNull(); response.ErrorResponse.ErrorSummary.Should().NotBeNullOrWhiteSpace(); response.ErrorResponse.ErrorSummary.Should().BeEquivalentTo("Input NewName cannot be empty."); response.StatusCode.HasValue.Should().BeTrue(); response.StatusCode.Should().Be(500); }
public async Task InvalidInputIdNotValid(int Id) { var invalidInput = new UpdatePlatformNameInput { Id = Id, NewName = "Something" }; var response = await request.ExecuteAsync(invalidInput); response.Should().NotBeNull(); response.ErrorResponse.Should().NotBeNull(); response.ErrorResponse.ErrorSummary.Should().NotBeNullOrWhiteSpace(); response.ErrorResponse.ErrorSummary.Should().BeEquivalentTo($"Input {nameof(Id)} must be 1 or greater."); response.StatusCode.HasValue.Should().BeTrue(); response.StatusCode.Should().Be(500); }
private void CheckInputValidity(UpdatePlatformNameInput input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (input.Id <= 0) { throw new ArgumentException($"Input {nameof(input.Id)} must be 1 or greater."); } if (string.IsNullOrWhiteSpace(input.NewName)) { throw new ArgumentException($"Input {nameof(input.NewName)} cannot be empty."); } }
public IActionResult Put(UpdatePlatformNameInput input) { return(ExecuteAndHandleRequest(() => RequestAggregate.UpdatePlatformNameRequest.Execute(input))); }
public async Task <IActionResult> Put(UpdatePlatformNameInput input) { return(await ExecuteAndHandleRequestAsync(() => RequestAsyncAggregate.UpdatePlatformNameRequestAsync.ExecuteAsync(input))); }