public void Should_Return_Equals_Message_When_Objects_Are_The_Same() { //Arrange var jsonSides = new Json { Id = 1, JsonId = JsonId, Left = _modelHelper.Left, Right = _modelHelper.Left }; //Act var result = _diffService.ProcessDiff(jsonSides); //Assert Assert.Equal(JsonId, result.Id); Assert.Equal("Objects are the same", result.Message); Assert.Empty(result.Inconsistencies); }
public async Task <IActionResult> Diff(string id) { //parameter validation - fails if null or empty if (id == null || id.Trim() == string.Empty) { return(BadRequest("Id field is required.")); } //retrieves object from database var json = await _jsonRepository.GetById(id); //fails if Id doesn't exist if (json == null) { return(BadRequest("There is no JSON stored under given ID.")); } //fails if LEFT or RIGHT sides are empty if (json.Left == null || json.Right == null) { return(BadRequest("Left and Right side are required to peform diff.")); } try { //Process differences and build response object var response = _diffService.ProcessDiff(json); return(Ok(response)); } catch (Exception ex) { //Logs and Returns bad request if fails when processing differences _logger.LogError($"Failed to process diff. Stack Trace: {ex.StackTrace}"); return(BadRequest($"Failed to process diff. Error Message: {ex.Message}")); } }