public void Setup() { _goalPatchService = Substitute.For <GoalsPatchService>(); _goalPatch = Substitute.For <GoalPatch>(); _json = JsonConvert.SerializeObject(_goalPatch); }
public string Patch(string goalsJson, GoalPatch goalPatch) { if (string.IsNullOrEmpty(goalsJson)) { return(null); } var obj = JObject.Parse(goalsJson); if (goalPatch.DateGoalCaptured.HasValue) { JsonHelper.UpdatePropertyValue(obj["DateGoalCaptured"], goalPatch.DateGoalCaptured); } if (goalPatch.DateGoalShouldBeCompletedBy.HasValue) { JsonHelper.UpdatePropertyValue(obj["DateGoalShouldBeCompletedBy"], goalPatch.DateGoalShouldBeCompletedBy); } if (goalPatch.DateGoalAchieved.HasValue) { JsonHelper.UpdatePropertyValue(obj["DateGoalAchieved"], goalPatch.DateGoalAchieved); } if (!string.IsNullOrEmpty(goalPatch.GoalSummary)) { JsonHelper.UpdatePropertyValue(obj["GoalSummary"], goalPatch.GoalSummary); } if (goalPatch.GoalType.HasValue) { JsonHelper.UpdatePropertyValue(obj["GoalType"], goalPatch.GoalType); } if (goalPatch.GoalStatus.HasValue) { JsonHelper.UpdatePropertyValue(obj["GoalStatus"], goalPatch.GoalStatus); } if (goalPatch.LastModifiedDate.HasValue) { JsonHelper.UpdatePropertyValue(obj["LastModifiedDate"], goalPatch.LastModifiedDate); } if (!string.IsNullOrEmpty(goalPatch.LastModifiedBy)) { JsonHelper.UpdatePropertyValue(obj["LastModifiedBy"], goalPatch.LastModifiedBy); } return(obj.ToString()); }
public void GoalPatchServiceTests_CheckDateGoalCapturedIsUpdated_WhenPatchIsCalled() { var goalPatch = new GoalPatch { DateGoalCaptured = DateTime.MaxValue }; var patchedGoal = _goalPatchService.Patch(_json, goalPatch); var goal = JsonConvert.DeserializeObject <Models.Goal>(patchedGoal); // Assert Assert.AreEqual(DateTime.MaxValue, goal.DateGoalCaptured); }
public void GoalPatchServiceTests_CheckLastModifiedTouchpointIdIsUpdated_WhenPatchIsCalled() { var goalPatch = new GoalPatch { LastModifiedBy = "0000000111" }; var patchedGoal = _goalPatchService.Patch(_json, goalPatch); var goal = JsonConvert.DeserializeObject <Models.Goal>(patchedGoal); // Assert Assert.AreEqual("0000000111", goal.LastModifiedBy); }
public void GoalPatchServiceTests_CheckGoalSummaryIsUpdated_WhenPatchIsCalled() { var goalPatch = new GoalPatch { GoalSummary = "Summary" }; var patchedGoal = _goalPatchService.Patch(_json, goalPatch); var goal = JsonConvert.DeserializeObject <Models.Goal>(patchedGoal); // Assert Assert.AreEqual("Summary", goal.GoalSummary); }
public string PatchResource(string goalJson, GoalPatch goalPatch) { if (string.IsNullOrEmpty(goalJson)) { return(null); } if (goalPatch == null) { return(null); } goalPatch.SetDefaultValues(); var updatedGoal = _goalPatchService.Patch(goalJson, goalPatch); return(updatedGoal); }
public void Setup() { _goal = Substitute.For <Models.Goal>(); _goalPatch = Substitute.For <GoalPatch>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Interactions/aa57e39e-4469-4c79-a9e9-9cb4ef410382/" + $"ActionPlans/d5369b9a-6959-4bd3-92fc-1583e72b7e51/" + $"Goals/d5369b9a-6959-4bd3-92fc-1583e72b7e51") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _validate = Substitute.For <IValidate>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _patchGoalHttpTriggerService = Substitute.For <IPatchGoalHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); }