Exemplo n.º 1
0
        public async Task PostHomework_ValidCall()
        {
            var response = await HomeworkController.Post(ViewModel().Result);

            var code = ((ObjectResult)response.Result).StatusCode;

            Assert.AreEqual((int)HttpStatusCode.OK, code);
        }
Exemplo n.º 2
0
        public async Task PostHomework_BadRequest()
        {
            var response = await HomeworkController.Post(null);

            var code = (StatusCodeResult)response.Result;

            Assert.AreEqual((int)HttpStatusCode.BadRequest, code.StatusCode);
        }
Exemplo n.º 3
0
        public JsonResult AddHomework(FormCollection collection)
        {
            HomeworkController obj = new HomeworkController();
            var          homework  = collection["Homework"];
            tbl_homework Homework  = JsonConvert.DeserializeObject <tbl_homework>(homework);

            var files = System.Web.HttpContext.Current.Request.Files;

            if (files.Count > 0)
            {
                using (var binaryReader = new BinaryReader(files[0].InputStream))
                {
                    Homework.name        = files[0].FileName;
                    Homework.contenttype = files[0].ContentType;
                    Homework.data        = binaryReader.ReadBytes(files[0].ContentLength);
                }
            }
            var response = obj.Post(Homework);

            return(Json(((tbl_homework)(((System.Net.Http.ObjectContent)(response.Content)).Value)).id, JsonRequestBehavior.AllowGet));
        }