コード例 #1
0
        public CodebookDataObject GetPublishedAttributes(HttpRequestMessage Request, string ApiUser)
        {
            LoggingUtility log = LoggerFactory.GetLogger();
            String requestId = Request.Properties["requestId"].ToString();
            CodebookDataObject data = new CodebookDataObject();
            string OperationName = operationName.GetAttributes.ToString();
            log.ProcessingDebug(requestId, "Received GET Attributes request.");
            try
            {
                log.ProcessingDebug(requestId, "Getting published attributes from database.");
                var attributes = AttributeRespository.SelectPublishedAttributes().ToList();
                if (attributes != null && attributes.Count > 0)
                {
                    data.Attributes = attributes;
                }
                else
                {
                    data.Errors.Add(new ErrorObject(ErrorKey.ERR_PROVIDER_NO_PUBLISHED_ATTRIBUTES));
                }
            }
            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
                if (data.Errors.Count != 0)
                {
                    log.InfoJson(new Methods().Error_ToLogObject(requestId, ApiUser, OperationType, OperationName, parameters, data.Errors));
                    log.ProcessingDebug(requestId, "GET Attributes request was unsuccessful.");
                }

                //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 Attributes request was successful.");
                }
            }
            return data;
        }
コード例 #2
0
        public void GetPublishedAttributesFailureTest()
        {
            var IAttributesManager = new Mock<IAttributesManager>();
            OkNegotiatedContentResult<CodebookResponse> response;
            CodebookDataObject AttributesData = new CodebookDataObject()
            {
                Errors = new List<ErrorObject>()
                {
                    new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)
                },
                Attributes = null
            };

            IAttributesManager.Setup(i => i.GetPublishedAttributes(It.IsAny<HttpRequestMessage>(), It.IsAny<string>())).Returns(AttributesData);
            controller = new InitController("Attributes").initAttributesController(IAttributesManager.Object);
            response = controller.GetAttributes() as OkNegotiatedContentResult<CodebookResponse>;

            Assert.Null(response.Content.Data.Attributes);
            Assert.NotNull(response.Content.Data.Errors);
            Assert.True(response.Content.Data.Errors.Exists(i => i.Code == 2999));
        }
コード例 #3
0
 public CodebookResponse(string RequestId, bool status = false)
 {
     this.Status = status;
     this.Data = new CodebookDataObject();
     this.Meta = new MetaDataObject(RequestId);
 }
コード例 #4
0
        public void GetPublishedAttributesTest()
        {
            var IAttributesManager = new Mock<IAttributesManager>();
            OkNegotiatedContentResult<CodebookResponse> response;
            CodebookDataObject AttributesData = new CodebookDataObject()
            {
                Errors = new List<ErrorObject>(),
                Attributes = new List<AttributeApiObject>()
                {
                    new AttributeApiObject()
                }
            };

            IAttributesManager.Setup(i => i.GetPublishedAttributes(It.IsAny<HttpRequestMessage>(), It.IsAny<string>())).Returns(AttributesData);
            controller = new InitController("Attributes").initAttributesController(IAttributesManager.Object);
            response = controller.GetAttributes() as OkNegotiatedContentResult<CodebookResponse>;

            Assert.NotNull(response.Content.Data.Attributes);
            Assert.NotEmpty(response.Content.Data.Attributes);
            Assert.Null(response.Content.Data.Errors);
        }