public AttributesController initAttributesController(IAttributesManager IAttributesManager)
 {
     AttributesController controller = new AttributesController(IAttributesManager);
     controller.Request = this.request;
     controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = this.config;
     controller.Request.Properties["requestId"] = new Guid().ToString();
     controller.RequestContext.RouteData = this.routeData;
     return controller;
 }
        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));
        }
        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);
        }