public AttributeDataObject GetAttribute(HttpRequestMessage Request, string ApiUser, string AttributeId) { LoggingUtility log = LoggerFactory.GetLogger(); String requestId = Request.Properties["requestId"].ToString(); AttributeDataObject data = new AttributeDataObject(); string OperationName = operationName.GetAttributeOptions.ToString(); log.ProcessingDebug(requestId, "Received GET Attribute details request."); parameters.Add("AttributeId", AttributeId); try { log.ProcessingDebug(requestId, "Getting Attribute details from database."); var attribute = AttributeRespository.GetAttributeDetails(AttributeId); if (attribute == null) { //Edit for R184 data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_INVALID_ATTRIBUTE_ARGUMENT, parameters)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_INVALID_ATTRIBUTE_ARGUMENT, parameters)); } else { data.Attribute = attribute; } } catch (Exception e) { //Edit for R184 data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); log.InfoJson(new Methods().Exception_ToLogObject(requestId, ApiUser, OperationType, OperationName, e)); } finally { //If the response has errors, insert an error message into the logs //Edit for R184 if (data.Errors != null) { log.InfoJson(new Methods().Error_ToLogObject(requestId, ApiUser, OperationType, OperationName, parameters, data.Errors)); log.ProcessingDebug(requestId, "GET Attribute details request was unsuccessful."); } //R185 Modification //if (_responseEnvelope.Data.Errors.Count != 0) //{ // log.InfoJson(new Methods().Error_ToLogObject(_responseEnvelope.Meta.Id, RequestContext.Principal.Identity.Name, OperationType, OperationName, parameters, _responseEnvelope.Data.Errors)); // detailedLog.ProcessingDebug(_responseEnvelope.Meta.Id, "GET Offer attributes request was unsuccessful."); // _responseEnvelope.Status = false; //} //The response has no errors, we insert a request successful message into the logs else { log.InfoJson(new Methods().Response_ToLogObject(requestId, ApiUser, OperationType, OperationName, parameters, data)); log.ProcessingDebug(requestId, "GET Attribute details was successful."); } } return data; }
public void GetAttributeWithOptionTest() { var IAttributesManager = new Mock<IAttributesManager>(); OkNegotiatedContentResult<AttributeResponse> response; AttributeDataObject AttributeWithOptionData = new AttributeDataObject() { Errors = new List<ErrorObject>(), Attribute = new AttributeDetailsApiObject() }; IAttributesManager.Setup(i => i.GetAttribute(It.IsAny<HttpRequestMessage>(), It.IsAny<string>(), It.IsAny<string>())).Returns(AttributeWithOptionData); controller = new InitController("Attributes").initAttributesController(IAttributesManager.Object); response = controller.GetAttribute(It.IsAny<string>()) as OkNegotiatedContentResult<AttributeResponse>; Assert.NotNull(response.Content.Data.Attribute); Assert.Null(response.Content.Data.Errors); }
public void GetAttributeWithOptionFailureTest() { var IAttributesManager = new Mock<IAttributesManager>(); OkNegotiatedContentResult<AttributeResponse> response; AttributeDataObject AttributeWithOptionData = new AttributeDataObject() { Errors = new List<ErrorObject>(){ new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL) }, Attribute = null }; IAttributesManager.Setup(i => i.GetAttribute(It.IsAny<HttpRequestMessage>(), It.IsAny<string>(), It.IsAny<string>())).Returns(AttributeWithOptionData); controller = new InitController("Attributes").initAttributesController(IAttributesManager.Object); response = controller.GetAttribute(It.IsAny<string>()) as OkNegotiatedContentResult<AttributeResponse>; Assert.Null(response.Content.Data.Attribute); Assert.NotNull(response.Content.Data.Errors); Assert.True(response.Content.Data.Errors.Exists(i => i.Code == 3000)); }