예제 #1
0
        public void ListTest()
        {
            var task   = _store.Search("TestProductName-Long");
            var result = task.Result;

            Assert.Single(result);

            task   = _store.Search("TestProductName");
            result = task.Result;

            Assert.True(result.Any());
        }
예제 #2
0
        public void SearchTest()
        {
            var all = _db.Products.ToList();

            _db.RemoveRange(all);
            _db.SaveChanges();

            CreateTest();
            var task   = _store.Search("TestProductName-Long");
            var result = task.Result;

            Assert.AreEqual(result.Count(), 1);

            task   = _store.Search("TestProductName");
            result = task.Result;

            Assert.AreEqual(result.Count(), 2);
        }
        public async Task <List <Product> > Search([FromHeader] string auth, [FromForm] string regex,
                                                   [FromForm] string category)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (category != null)
            {
                return(await ProductStore.Search(regex, category));
            }

            return(await ProductStore.Search(regex));
        }