public void Setup() { _jsonHelper = Substitute.For <JsonHelper>(); _sessionPatchService = Substitute.For <SessionPatchService>(); _sessionPatch = Substitute.For <SessionPatch>(); _json = JsonConvert.SerializeObject(_sessionPatch); }
public void SessionPatchServiceTests_CheckLastModifiedDateIsUpdated_WhenPatchIsCalled() { var sessionPatch = new SessionPatch { LastModifiedDate = DateTime.MaxValue }; var patchedSession = _sessionPatchService.Patch(_json, sessionPatch); var session = JsonConvert.DeserializeObject <Session>(patchedSession); // Assert Assert.AreEqual(DateTime.MaxValue, session.LastModifiedDate); }
public void SessionPatchServiceTests_CheckReasonForNonAttendanceIsUpdated_WhenPatchIsCalled() { var sessionPatch = new SessionPatch { ReasonForNonAttendance = ReasonForNonAttendance.Forgot }; var patchedSession = _sessionPatchService.Patch(_json, sessionPatch); var session = JsonConvert.DeserializeObject <Session>(patchedSession); // Assert Assert.AreEqual(ReasonForNonAttendance.Forgot, session.ReasonForNonAttendance); }
public void SessionPatchServiceTests_CheckSessionAttendedIsUpdated_WhenPatchIsCalled() { var sessionPatch = new SessionPatch { SessionAttended = true }; var patchedSession = _sessionPatchService.Patch(_json, sessionPatch); var session = JsonConvert.DeserializeObject <Session>(patchedSession); // Assert Assert.AreEqual(true, session.SessionAttended); }
public void SessionPatchServiceTests_CheckVenuePostCodeIsUpdated_WhenPatchIsCalled() { var sessionPatch = new SessionPatch { VenuePostCode = "CV1 1VC" }; var patchedSession = _sessionPatchService.Patch(_json, sessionPatch); var session = JsonConvert.DeserializeObject <Session>(patchedSession); // Assert Assert.AreEqual("CV1 1VC", session.VenuePostCode); }
public void SessionPatchServiceTests_CheckLastModifiedByUpdated_WhenPatchIsCalled() { var sessionPatch = new SessionPatch { LastModifiedTouchpointId = "0000000111" }; var patchedSession = _sessionPatchService.Patch(_json, sessionPatch); var session = JsonConvert.DeserializeObject <Session>(patchedSession); // Assert Assert.AreEqual("0000000111", session.LastModifiedTouchpointId); }
public string PatchResource(string sessionJson, SessionPatch sessionPatch) { if (string.IsNullOrEmpty(sessionJson)) { return(null); } if (sessionPatch == null) { return(null); } sessionPatch.SetDefaultValues(); var updatedSession = _sessionPatchService.Patch(sessionJson, sessionPatch); return(updatedSession); }
public string Patch(string sessionJson, SessionPatch sessionPatch) { if (string.IsNullOrEmpty(sessionJson)) { return(null); } var obj = JObject.Parse(sessionJson); if (sessionPatch.DateandTimeOfSession.HasValue) { JsonHelper.UpdatePropertyValue(obj["DateandTimeOfSession"], sessionPatch.DateandTimeOfSession); } if (!string.IsNullOrEmpty(sessionPatch.VenuePostCode)) { JsonHelper.UpdatePropertyValue(obj["VenuePostCode"], sessionPatch.VenuePostCode); } if (sessionPatch.SessionAttended.HasValue) { JsonHelper.UpdatePropertyValue(obj["SessionAttended"], sessionPatch.SessionAttended); } if (sessionPatch.ReasonForNonAttendance.HasValue) { JsonHelper.UpdatePropertyValue(obj["ReasonForNonAttendance"], sessionPatch.ReasonForNonAttendance.Value); } if (sessionPatch.LastModifiedDate.HasValue) { JsonHelper.UpdatePropertyValue(obj["LastModifiedDate"], sessionPatch.LastModifiedDate); } if (!string.IsNullOrEmpty(sessionPatch.LastModifiedTouchpointId)) { JsonHelper.UpdatePropertyValue(obj["LastModifiedTouchpointId"], sessionPatch.LastModifiedTouchpointId); } return(obj.ToString()); }
public void Setup() { _session = Substitute.For <Session>(); _sessionPatch = Substitute.For <SessionPatch>(); _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Sessions/1e1a555c-9633-4e12-ab28-09ed60d51cb3") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _validate = Substitute.For <IValidate>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _patchSessionHttpTriggerService = Substitute.For <IPatchSessionHttpTriggerService>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); _httpRequestMessageHelper.GetApimURL(_request).Returns("http://localhost:7071/"); }