public WebResponse <TMessage> Delete <TMessage>(string uri, MdmRequestInfo requestInfo) { Logger.DebugFormat("Start: MessageRequester.Delete {0}", uri); CheckAndPopulateRequestInfo(ref requestInfo); var requestId = requestInfo.RequestId; var webResponse = new WebResponse <TMessage>() { RequestId = requestId }; this.ResponseHandler(webResponse, uri, client => { client.AddHeader(CoreConstants.UserNameHeader, GetUserName()); client.AddHeader(MdmConstants.MdmRequestHeaderName, requestInfo.Encode()); using (var response = client.Delete(uri)) { this.PopulateWebResponse(webResponse, response, HttpStatusCode.OK); } }); Logger.DebugFormat("Finish: MessageRequester.Delete {0}", uri); return(webResponse); }
public void RequestIdInResponseShouldMatchWithRequestParam() { // given var id = int.Parse(sourcesystem.ToMdmId().Identifier); var mdmReqInfo = new MdmRequestInfo { RequestId = "Test123" }; // when var response = MdmService.Get <SourceSystem>(id); var entity = response.Message; entity.Identifiers = new MdmIdList() { entity.Identifiers.SystemId() }; // then response = MdmService.Update(id, entity, response.Tag, mdmReqInfo); Assert.IsTrue(response.IsValid && response.RequestId == mdmReqInfo.RequestId, "###Error : " + response.Code + " : " + (response.Fault == null ? string.Empty : response.Fault.Message + " : " + response.Fault.Reason)); var mappingId = Guid.NewGuid().ToString(); var mdmUpdateResponse = MdmService.CreateMapping <SourceSystem>(id, new MdmId { SystemName = "Endur", Identifier = mappingId }, mdmReqInfo); Assert.IsTrue(mdmUpdateResponse.IsValid && mdmUpdateResponse.RequestId == mdmReqInfo.RequestId, "###Error : " + response.Code + " : " + (response.Fault == null ? string.Empty : response.Fault.Message + " : " + response.Fault.Reason)); if (mdmUpdateResponse.Message != null && mdmUpdateResponse.Message.MappingId.HasValue) { var mdmDeleteResponse = MdmService.DeleteMapping <SourceSystem>(id, (int)mdmUpdateResponse.Message.MappingId.Value, mdmReqInfo); Assert.IsTrue(mdmDeleteResponse.IsValid && mdmDeleteResponse.RequestId == mdmReqInfo.RequestId, "###Error : " + response.Code + " : " + (response.Fault == null ? string.Empty : response.Fault.Message + " : " + response.Fault.Reason)); } }
public void CreateEntity(MdmRequestInfo requestInfo) { var requester = new Mock <IMessageRequester>(); var service = new MdmEntityService <SourceSystem>("sourcesystem", requester.Object); var sourcesystem = new SourceSystem(); var response = new WebResponse <SourceSystem>() { Code = HttpStatusCode.OK, IsValid = true }; requester.Setup(x => x.Create("sourcesystem", sourcesystem, requestInfo ?? It.IsAny <MdmRequestInfo>())) .Returns(response); requester.Setup(x => x.Request <SourceSystem>(It.IsAny <string>())) .Returns(new WebResponse <SourceSystem> { IsValid = true, Code = HttpStatusCode.OK, Message = sourcesystem, }); // Act var result = (requestInfo == null) ? service.Create(sourcesystem) : service.Create(sourcesystem, requestInfo); // Assert Assert.AreEqual(HttpStatusCode.OK, result.Code, "Status code differ"); Assert.AreEqual(true, result.IsValid, "IsValid differ"); }
public WebResponse <TContract> Create <TContract>(TContract contract, MdmRequestInfo requestInfo, uint version = 0) where TContract : IMdmEntity { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmService.Create<{0}>", typeof(TContract).Name); } return(this.factory.EntityService <TContract>(version).Create(contract, requestInfo)); }
public WebResponse <MdmId> CreateMapping(int id, MdmId identifier, MdmRequestInfo requestInfo) { try { Logger.DebugFormat("Start : CachingMdmEntityService.CreateMapping<{0}> - {1} {2}", this.entityName, id, identifier); return(this.service.CreateMapping(id, identifier)); } finally { Logger.DebugFormat("Stop : CachingMdmEntityService.CreateMapping<{0}>", this.entityName); } }
public WebResponse <TContract> DeleteMapping(int entityId, int mappingId, MdmRequestInfo requestInfo) { try { Logger.DebugFormat("Start: CachePolicyMdmEntityService.DeleteMapping<{0}>: {1} - {2}. Calling service to delete mapping", this.entityName, entityId, mappingId); return(this.service.DeleteMapping(entityId, mappingId, requestInfo)); } finally { Logger.DebugFormat("Stop: CachePolicyMdmEntityService.DeleteMapping<{0}>: {1} - {2}", this.entityName, entityId, mappingId); } }
public WebResponse <MdmId> CreateMapping(int id, MdmId identifier, MdmRequestInfo requestInfo) { try { Logger.DebugFormat("Start: CachePolicyMdmEntityService.CreateMapping<{0}>: {1}. Calling service to create mapping", this.entityName, identifier); return(this.service.CreateMapping(id, identifier, requestInfo)); } finally { Logger.DebugFormat("Stop: CachePolicyMdmEntityService.CreateMapping<{0}>: {1}", this.entityName, identifier); } }
public WebResponse <TContract> DeleteMapping(int entityId, int mappingId, MdmRequestInfo requestInfo) { try { Logger.DebugFormat("Start: CachingMdmEntityService.DeleteMapping<{0}> - '{1}' '{2}'", this.entityName, entityId, mappingId); return(this.service.DeleteMapping(entityId, mappingId)); } finally { Logger.DebugFormat("Stop: CachingMdmEntityService.DeleteMapping<{0}> - '{1}' '{2}'", this.entityName, entityId, mappingId); } }
private static void CheckAndPopulateRequestInfo(ref MdmRequestInfo requestInfo) { if (requestInfo == null) { requestInfo = new MdmRequestInfo(); } if (string.IsNullOrWhiteSpace(requestInfo.RequestId)) { requestInfo.RequestId = Guid.NewGuid().ToString(); } if (string.IsNullOrWhiteSpace(requestInfo.SourceSystem)) { requestInfo.SourceSystem = ConfigurationManager.AppSettings[MdmConstants.MdmRequestSourceSystemName]; } }
public void DeleteMapping(MdmRequestInfo requestInfo) { var requester = new Mock <IMessageRequester>(); var service = new MdmEntityService <SourceSystem>("sourcesystem", requester.Object); requester.Setup(x => x.Delete <SourceSystem>("sourcesystem/77/mapping/33", requestInfo ?? It.IsAny <MdmRequestInfo>())).Returns(new WebResponse <SourceSystem>() { Code = HttpStatusCode.OK, IsValid = true }); // Act var result = (requestInfo == null) ? service.DeleteMapping(77, 33) : service.DeleteMapping(77, 33, requestInfo); // Assert Assert.AreEqual(HttpStatusCode.OK, result.Code, "Status code differ"); Assert.AreEqual(true, result.IsValid, "IsValid differ"); }
/// <summary> /// /// </summary> /// <param name="contract"></param> /// <param name="requestInfo"></param> /// <returns></returns> public WebResponse <TContract> Create(TContract contract, MdmRequestInfo requestInfo) { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmEntityService.Create<{0}>", typeof(TContract).Name); } var response = this.Create(this.BaseUri, contract, requestInfo); if (response.IsValid) { this.ProcessContract(response); } response.LogResponse(); return(response); }
public WebResponse <TContract> Create(TContract contract, MdmRequestInfo requestInfo) { try { Logger.DebugFormat("Start : CachingMdmEntityService.Create<{0}>", this.entityName); var response = this.service.Create(contract, requestInfo); if (response.IsValid) { this.ProcessContract(response); } response.LogResponse(); return(response); } finally { Logger.DebugFormat("Stop : CachingMdmEntityService.Create<{0}>", this.entityName); } }
public WebResponse <MdmId> CreateMapping(int id, MdmId identifier, MdmRequestInfo requestInfo) { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmEntityService.CreateMapping<{0}>: {1} - {2}", this.entityName, id, identifier); } var mapping = new Mapping { // TODO: Flesh out the rest SystemName = identifier.SystemName, Identifier = identifier.Identifier, DefaultReverseInd = identifier.DefaultReverseInd, }; var uri = string.Format(this.mappingUri, id); var response = this.Create <MdmId, MappingResponse>(uri, mapping, requestInfo); WebResponse <MdmId> webResponse; if (response.IsValid) { webResponse = new WebResponse <MdmId> { Code = HttpStatusCode.OK, Message = response.Message.Mappings[0], RequestId = response.RequestId }; } else { webResponse = new WebResponse <MdmId> { IsValid = false, Code = response.Code, Fault = response.Fault, RequestId = response.RequestId }; } webResponse.LogResponse(); return(webResponse); }
public WebResponse <TContract> DeleteMapping(int entityId, int mappingId, MdmRequestInfo requestInfo) { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmEntityService.DeleteMapping<{0}>: {1} - {2}", this.entityName, entityId, mappingId); } var uri = string.Format(this.deleteMappingUri, entityId, mappingId); Logger.DebugFormat("MdmEntityService.DeleteMapping : Uri - {0}", uri); var response = this.requester.Delete <TContract>(uri, requestInfo); if (response.IsValid) { response = new WebResponse <TContract> { Code = HttpStatusCode.OK, IsValid = true, RequestId = response.RequestId }; } else { response = new WebResponse <TContract> { Code = response.Code, IsValid = false, Fault = response.Fault, RequestId = response.RequestId }; } response.LogResponse(); return(response); }
private WebResponse <TResponse> Create <TMessage, TResponse>(string uri, TMessage message, MdmRequestInfo requestInfo) where TResponse : class { try { Logger.DebugFormat("Start : MdmEntityService.Create : Uri - {0}", uri); var request = this.requester.Create(uri, message, requestInfo); var response = new WebResponse <TResponse> { Code = request.Code, IsValid = false, RequestId = request.RequestId, Fault = request.Fault }; if (request.IsValid) { Logger.DebugFormat("MdmEntityService.Create : Valid Response received. Now requesting - {0}", request.Location); response = this.requester.Request <TResponse>(request.Location); response.RequestId = request.RequestId; } response.LogResponse(); return(response); } finally { Logger.DebugFormat("Stop : MdmEntityService.Create"); } }
private WebResponse <TMessage> Create <TMessage>(string uri, TMessage message, MdmRequestInfo requestInfo) where TMessage : class { return(this.Create <TMessage, TMessage>(uri, message, requestInfo)); }
public WebResponse <TContract> Update(int id, TContract contract, string etag, MdmRequestInfo requestInfo) { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmEntityService.Update<{0}>: {1} {2}", this.entityName, id, etag); } var uri = string.Format(this.entityUri, id); Logger.DebugFormat("MdmEntityService.Update : Uri - {0}", uri); var response = this.requester.Update(uri, etag, contract, requestInfo); response.LogResponse(); if (!response.IsValid) { return(response); } var queryString = string.Empty; if (contract.MdmSystemData != null && contract.MdmSystemData.StartDate.HasValue) { queryString = string.Format(this.validAtParam, contract.MdmSystemData.StartDate.Value.ToString(DateFormatString)); } string location = response.Location + queryString; Logger.DebugFormat("MdmEntityService.Update : Received valid response. Now requesting - {0}", location); var r2 = this.requester.Request <TContract>(location); r2.RequestId = response.RequestId; // TODO: Should this just be a IsValid check? if (r2.Code == HttpStatusCode.OK) { this.ProcessContract(r2); } r2.LogResponse(); return(r2); }
public WebResponse <TContract> Update(int id, TContract contract, MdmRequestInfo requestInfo) { return(Update(id, contract, this.etags[id], requestInfo)); }
public WebResponse <TContract> Update(int id, TContract contract, string etag, MdmRequestInfo requestInfo) { try { Logger.DebugFormat("Start : CachingMdmEntityService.Update<{0}> - {1}", this.entityName, id); var response = this.service.Update(id, contract, etag, requestInfo); if (response.IsValid) { this.ProcessContract(response); } response.LogResponse(); return(response); } finally { Logger.DebugFormat("Stop : CachingMdmEntityService.Update<{0}> - {1}", this.entityName, id); } }
public WebResponse <TMessage> Update <TMessage>(string uri, string etag, TMessage message, MdmRequestInfo requestInfo) { Logger.DebugFormat("Start: MessageRequester.Update {0}", uri); CheckAndPopulateRequestInfo(ref requestInfo); var requestId = requestInfo.RequestId; var webResponse = new WebResponse <TMessage>() { RequestId = requestId }; this.ResponseHandler(webResponse, uri, client => { client.AddHeader("If-Match", etag); client.AddHeader(CoreConstants.UserNameHeader, GetUserName()); client.AddHeader(MdmConstants.MdmRequestHeaderName, requestInfo.Encode()); var content = new ObjectContent <TMessage>(message, new XmlMediaTypeFormatter()); using (var response = client.Post(uri, content)) { this.PopulateWebResponse(webResponse, response, HttpStatusCode.NoContent); if (webResponse.IsValid) { webResponse.Location = this.Location(uri, response); } } }); Logger.DebugFormat("Finish: MessageRequester.Update {0}", uri); return(webResponse); }
public WebResponse <MdmId> CreateMapping <TContract>(int id, MdmId identifier, MdmRequestInfo requestInfo, uint version = 0) where TContract : IMdmEntity { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmService.CreateMapping<{0}>: {1} {2}", typeof(TContract).Name, id, identifier); } return(this.factory.EntityService <TContract>(version).CreateMapping(id, identifier, requestInfo)); }
public WebResponse <TContract> DeleteMapping <TContract>(int entityId, int mappingId, MdmRequestInfo requestInfo, uint version = 0) where TContract : IMdmEntity { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmService.DeleteMapping<{0}> : {1} {2}", typeof(TContract).Name, entityId, mappingId); } return(this.factory.EntityService <TContract>(version).DeleteMapping(entityId, mappingId, requestInfo)); }
/// <summary> /// /// </summary> /// <param name="requestInfo"></param> /// <returns></returns> public static string Encode(this MdmRequestInfo requestInfo) { return(Convert.ToBase64String(Encoding.UTF8.GetBytes(requestInfo.DataContractSerialize()))); }
public WebResponse <TContract> Update <TContract>(int id, TContract contract, string etag, MdmRequestInfo requestInfo, uint version = 0) where TContract : IMdmEntity { if (Logger.IsDebugEnabled) { Logger.DebugFormat("MdmService.Update<{0}>: {1} {2}", typeof(TContract).Name, id, etag); } return(this.factory.EntityService <TContract>(version).Update(id, contract, etag, requestInfo)); }