Пример #1
0
        public override void OnException(HttpActionExecutedContext context)
        {
            var request = context.Request.RequestUri.AbsolutePath;

            var response = new ResponseContentModel(WebApiExceptionReturnCode.INTERNAL_SERVER_ERROR, request);

            if (context.Exception is NotImplementedException)
            {
                response = new ResponseContentModel(WebApiExceptionReturnCode.NOT_IMPLEMENTED, request);
            }
            if (context.Exception is WebException)
            {
                response = new ResponseContentModel(WebApiExceptionReturnCode.GATEWAY_TIMEOUT, request);
            }
            if (context.Exception is UserFriendlyException)
            {
                var exception = context.Exception as UserFriendlyException;
                response = new ResponseContentModel(exception.Code, exception.Message, request);
            }

            context.Response = new HttpResponseMessage(response.HttpStatusCode)
            {
                Content = new StringContent(JsonConvert.SerializeObject(response, serializerSettings), Encoding.UTF8, "application/json")
            };
        }
Пример #2
0
 public void TestInitialise()
 {
     _response = new ResponseContentModel(new TimeSpan(1000),
                                          HttpStatusCode.OK,
                                          new DateTime(),
                                          new TestResponseType());
 }
Пример #3
0
        public void TestInitialise()
        {
            _apiResponseService    = new Mock <IApiResponseService>();
            _parameterCheckService = new Mock <ICheckRequiredParametersService>();
            _createMessageService  = new Mock <ICreateMessageService>();
            _responseRecorder      = new Mock <IResponseRecorderService>();

            _authStrategy = new Mock <IGetAuthorisationHeaderStrategy>();

            _service = new InvokeOpenApiEndpointService(_apiResponseService.Object,
                                                        _parameterCheckService.Object,
                                                        _createMessageService.Object,
                                                        _responseRecorder.Object);

            _response = new ResponseContentModel(new TimeSpan(),
                                                 HttpStatusCode.OK,
                                                 new DateTime(),
                                                 new object());
            _request         = new Mock <HttpRequestMessage>();
            _endpoint        = new Endpoint();
            _testEnvironment = new TestEnvironment();
            _queryParams     = new Hashtable();
            _pathParams      = new Hashtable();
            _headerParams    = new Hashtable();
            _requestBody     = new object();

            _createMessageService.Setup(s => s.CreateMessage(_endpoint,
                                                             _testEnvironment,
                                                             It.IsAny <IDictionary <string, string> >(),
                                                             It.IsAny <IDictionary <string, string> >(),
                                                             It.IsAny <IDictionary <string, string> >(),
                                                             _authStrategy.Object,
                                                             _requestBody))
            .Returns(Task.FromResult(_request.Object))
            .Verifiable();
            _apiResponseService.Setup(s => s.ReturnContent(_request.Object,
                                                           It.IsAny <Type>(),
                                                           It.IsAny <Type>())).Returns(Task.FromResult(_response));
        }
        public IHttpActionResult GetModule(string module)
        {
            //var model = new ResponseContentModel<List<T>>();

            string token  = Request.Headers.GetValues("Authorization").FirstOrDefault();
            var    result = CommonMethods.AuthenticateWebAPI(token);

            if (result != WebAPIEnums.AuthenticationStatus.OK)
            {
                return(Json(CommonMethods.GetAutheticationError(result)));
            }
            else
            {
                if (module == WebAPIEnums.Module.inventory.ToString())
                {
                    var model = new ResponseContentModel <List <ProductAPIModel> >();
                    IProductRepository productRepo = new ProductRepository();

                    model.rows    = productRepo.GetProductsMobile();
                    model.total   = model.rows.Count.ToString();
                    model.key     = "id";
                    model.control = new Control {
                        page = "1", order = "asc", sort = "", limit = ""
                    };
                    return(Json(model));
                }
                else if (module == WebAPIEnums.Module.location.ToString())
                {
                    var model = new ResponseContentModel <List <LocationAPIModel> >();
                    ILocationRepository locRepo = new LocationRepository();
                    model.rows    = locRepo.GetLocationsMobile();
                    model.total   = model.rows.Count.ToString();
                    model.key     = "id";
                    model.control = new Control {
                        page = "1", order = "asc", sort = "", limit = ""
                    };
                    return(Json(model));
                }
                else if (module == WebAPIEnums.Module.supplier.ToString())
                {
                    var model = new ResponseContentModel <List <SupplierAPIModel> >();
                    IClientRepository clientRepo = new ClientRepository();
                    model.rows    = clientRepo.GetSuppliersMobile();
                    model.total   = model.rows.Count.ToString();
                    model.key     = "id";
                    model.control = new Control {
                        page = "1", order = "asc", sort = "", limit = ""
                    };
                    return(Json(model));
                }
                else if (module == WebAPIEnums.Module.users.ToString())
                {
                    var             model    = new ResponseContentModel <List <UserAPIModel> >();
                    IUserRepository userRepo = new UserRepository();
                    model.rows    = userRepo.GetUsersMobile();
                    model.total   = model.rows.Count.ToString();
                    model.key     = "id";
                    model.control = new Control {
                        page = "1", order = "asc", sort = "", limit = ""
                    };
                    return(Json(model));
                }
            }

            return(Json(CommonMethods.GetAutheticationError(WebAPIEnums.AuthenticationStatus.FAILED)));
        }