public JsonResult DeleteHomework(int ID) { HomeworkController obj = new HomeworkController(); var response = obj.Delete(ID); return(Json(response, JsonRequestBehavior.AllowGet)); }
public async Task PutHomework_BadRequest() { var response = await HomeworkController.Put(null); var code = (StatusCodeResult)response.Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, code.StatusCode); }
public async Task PutHomework_ValidCall() { var response = await HomeworkController.Put(ViewModel().Result); var code = ((ObjectResult)response.Result).StatusCode; Assert.AreEqual((int)HttpStatusCode.OK, code); }
public JsonResult GetHomework() { HomeworkController obj = new HomeworkController(); List <tbl_homework> objHomework = obj.GetHomeworks(); var jsonResult = Json(objHomework, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); }
public async Task PutHomework_NotFound() { Mock.Setup(service => service.Find(It.IsAny <Func <Homework, bool> >())) .Returns(PutNotFoundTest()); var response = await HomeworkController.Put(ViewModel().Result); var code = (StatusCodeResult)response.Result; Assert.AreEqual((int)HttpStatusCode.NotFound, code.StatusCode); }
public FileResult DownloadHomework(int id) { HomeworkController obj = new HomeworkController(); List <tbl_homework> ObjFiles = obj.GetHomeworks(); var FileById = (from FC in ObjFiles where FC.id.Equals(id) select new { FC.name, FC.contenttype, FC.data }).FirstOrDefault(); return(File(FileById.data, FileById.contenttype, FileById.name)); }
public void SetUp() { Mock = new Mock <IHomeworkService>(); Mock.Setup(service => service.GetAsync(It.IsAny <int>())) .Returns(GetTest()); Mock.Setup(service => service.CreateAsync(It.IsAny <HomeworkDTO>())) .Returns(ViewModel()); Mock.Setup(service => service.UpdateAsync(It.IsAny <HomeworkDTO>())) .Returns(ViewModel()); Mock.Setup(service => service.Find(It.IsAny <Func <Homework, bool> >())) .Returns(PutFindTest()); Mock.Setup(service => service.DeleteAsync(It.IsAny <int>())) .Returns(ViewModel()); HomeworkController = new HomeworkController(Mock.Object, new MapperPL()); }
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)); }
public void Setup() { var entities = new List <Homework> { new Homework { Id = 1, LectureId = 1, Lecture = new Lecture { Id = 1, CourseId = 1, Name = "Test" }, StudentId = 1, Mark = 5, Task = "Test" }, new Homework { Id = 2, LectureId = 2, Lecture = new Lecture { Id = 2, CourseId = 2, Name = "Test2" }, StudentId = 2, Mark = 5, Task = "Test2" } }; var config = new MapperConfiguration(opts => { opts.AddProfile(new HomeworkProfile()); opts.AddProfile(new AttendanceProfile()); opts.AddProfile(new CourseProfile()); opts.AddProfile(new StudentProfile()); opts.AddProfile(new LecturerProfile()); opts.AddProfile(new LectureProfile()); }); var collection = entities.AsQueryable().BuildMock(); var mapper = config.CreateMapper(); Service = new Mock <IHomeworkService>(); Logger = new Mock <ILogger <HomeworkController> >(); Service.Setup(x => x.GetAllHomeworks()) .Returns(collection.Object); Service.Setup(x => x.GetAllHomeworksWithLecture()) .Returns(collection.Object); Service.Setup(x => x.GetAllHomeworksWithStudent()) .Returns(collection.Object); Service.Setup(x => x.GetAllHomeworksWithLectureAndStudent()) .Returns(collection.Object); Service.Setup(x => x.GetHomeworkById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.GetHomeworkWithLectureById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.GetHomeworkWithStudentById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.GetHomeworkWithLectureAndStudentById(It.IsAny <int>())) .Returns((int id) => Task.Run(() => entities.Find(t => t.Id == id))); Service.Setup(x => x.CreateHomework(It.IsAny <Homework>())) .Callback((Homework homework) => entities.Add(homework)); Service.Setup(x => x.UpdateHomework(It.IsAny <Homework>())) .Callback((Homework homework) => Update(homework, entities)); Service.Setup(x => x.DeleteHomework(It.IsAny <Homework>())) .Callback((Homework homework) => entities.RemoveAt(entities.FindIndex(x => x.Id == homework.Id))); Service.Setup(x => x.GetAverageMark(1, 1)) .Returns(Task.Run(() => (double)entities.ElementAt(0).Mark)); Controller = new HomeworkController(Service.Object, mapper, Logger.Object); }