public ActionResult WhatchLog(Guid id) { Facultative facultative = _teacherService.GetFacultative(new Facultative() { Id = id }); return(View(facultative)); }
public void AddFacultative() { RestoreDate(); var FacultativeRepository = new FacultativeRepository(mockContext.Object); Facultative Facultative = new Facultative(); FacultativeRepository.Add(Facultative); Assert.IsNotNull(_Facultatives.Where(s => Facultative.Id == s.Id).FirstOrDefault()); Assert.AreEqual(FacultativeRepository.Get(Facultative.Id).Id, Facultative.Id); }
public void GetFacultativeById() { RestoreDate(); var FacultativeRepository = new FacultativeRepository(mockContext.Object); Facultative Facultative = new Facultative(); FacultativeRepository.Add(Facultative); Assert.IsNotNull(_Facultatives.FirstOrDefault()); Assert.IsNotNull(FacultativeRepository.Get(Facultative.Id)); }
public void TestEditFacultativeController() { RestoreDate(); EditFacultativeController editFacultativeController = new EditFacultativeController(DependencyResolver.Current.GetService <IAccountService>(), DependencyResolver.Current.GetService <ITeacherService>()); editFacultativeController.ControllerContext = ControllerContext("Teacher", "POST").Object; Assert.AreEqual(editFacultativeController.HttpContext.User.IsInRole("Teacher"), true); Assert.AreNotEqual(editFacultativeController.HttpContext.User.IsInRole("Admin"), true); FacultativeViewModel facultativeVM = new FacultativeViewModel() { Name = "Blavla007", Description = "sadsdasdasdasdas", Theme = "asdsadasdasdasasd", Duration = 60, Status = FacultativeStatus.Registration, StartFacultative = DateTime.Now }; SetModelState(editFacultativeController, facultativeVM); Facultative facultative = _facultatives[0]; var result = editFacultativeController.Index(facultativeVM, facultative.Id, "Change"); Assert.AreEqual(facultative.Name, "Blavla007"); Assert.AreEqual(facultative.Description, "sadsdasdasdasdas"); Assert.AreEqual(facultative.Theme, "asdsadasdasdasasd"); Assert.AreEqual(facultative.Duration, 60); Assert.AreEqual(facultative.Status, FacultativeStatus.Registration); facultativeVM = new FacultativeViewModel() { Name = "Bla", Description = "sfs", Theme = "4", Status = FacultativeStatus.Finished }; SetModelState(editFacultativeController, facultativeVM); result = editFacultativeController.Index(facultativeVM, facultative.Id, "Change"); Assert.AreEqual(facultative.Name, "Blavla007"); Assert.AreEqual(facultative.Description, "sadsdasdasdasdas"); Assert.AreEqual(facultative.Theme, "asdsadasdasdasasd"); Assert.AreEqual(facultative.Status, FacultativeStatus.Finished); }
public void DeleteFacultative() { RestoreDate(); var FacultativeRepository = new FacultativeRepository(mockContext.Object); Facultative Facultative = new Facultative(); FacultativeRepository.Add(Facultative); FacultativeRepository.Remove(Facultative); Assert.IsNull(_Facultatives.Where(s => Facultative.Id == s.Id).FirstOrDefault()); }
public void TestAddFacultativeController() { RestoreDate(); AddFacultativeController addFacultativeController = new AddFacultativeController( DependencyResolver.Current.GetService <IAccountService>() , DependencyResolver.Current.GetService <ITeacherService>()); addFacultativeController.ControllerContext = ControllerContext("Teacher", "POST").Object; FacultativeViewModel facultativeVM = new FacultativeViewModel() { Name = "Bladasdsadasda", Description = "sfsasdsadasdasdas", Theme = "4asdasdsadasqewqeqweqweqweq", Status = FacultativeStatus.Registration, Duration = 60, StartFacultative = DateTime.Now }; SetModelState(addFacultativeController, facultativeVM); RedirectToRouteResult result = addFacultativeController.Index(facultativeVM) as RedirectToRouteResult; Facultative facultative = _facultatives.Where(s => s.Name == "Bladasdsadasda").FirstOrDefault(); Assert.AreEqual(facultative.Name, "Bladasdsadasda"); Assert.AreEqual(facultative.Description, "sfsasdsadasdasdas"); Assert.AreEqual(facultative.Theme, "4asdasdsadasqewqeqweqweqweq"); Assert.AreEqual(facultative.Status, FacultativeStatus.Registration); Assert.AreEqual(facultative.Duration, 60); facultativeVM = new FacultativeViewModel() { Name = "a", Description = "sfsasdsadasdasdas", Theme = "4asdasdsadasqewqeqweqweqweq", Status = FacultativeStatus.Registration, Duration = 60, StartFacultative = DateTime.Now }; SetModelState(addFacultativeController, facultativeVM); result = addFacultativeController.Index(facultativeVM) as RedirectToRouteResult; Assert.IsNull(_facultatives.Where(s => s.Name == "a").FirstOrDefault()); }
public ActionResult Index(Guid id, ReportBookViewModel reportBookVM) { Teacher teacher = _teacherService.GetTeacher(_accountService.GetAccount(User.Identity.Name)); Facultative facultative = teacher.MyFacultatives.Where(s => s.Id == id).FirstOrDefault(); if (facultative == null) { RedirectToAction("Index", "Message", new { type = "Error", Message = "Dont find facultative" }); } facultative = _teacherService.GetFacultative(new Facultative() { Id = id }); reportBookVM.Elective = facultative; ReportBook reportBook = _teacherService.CreateReportBook(facultative.Name, facultative); if (Request.HttpMethod == "POST") { if (ModelState.IsValid) { if (reportBook.Reports.Count > 0) { reportBook.Reports.Clear(); } foreach (var item in reportBookVM.Reports) { facultative.Status = FacultativeStatus.Finished; _teacherService.AddReport(reportBook, new Report(facultative.Audience.Where(s => s.Id == item.Id).FirstOrDefault(), item.Mark)); } _teacherService.ChangeStateEntity(facultative); _teacherService.ChangeStateEntity(reportBook); return(RedirectToAction("Index", "TeacherFacultative", new { id = id })); } } _teacherService.ChangeStateEntity(reportBook); return(View(reportBookVM)); }
public void TestAddLogController() { RestoreDate(); AddLogController addLogController = new AddLogController( DependencyResolver.Current.GetService <ITeacherService>() , DependencyResolver.Current.GetService <IAccountService>()); addLogController.ControllerContext = ControllerContext("Teacher", "POST").Object; Facultative facultative = _facultatives.Where(s => s.Name == "FacultativeName1").FirstOrDefault(); facultative.Audience.Add(_students[0]); ReportBookViewModel reportBookViewModel = new ReportBookViewModel { Elective = facultative, Reports = new List <ReportViewModel> { new ReportViewModel { Id = _students[0].Id, Mark = 60 } } }; SetModelState(addLogController, reportBookViewModel); RedirectToRouteResult result = addLogController.Index(facultative.Id, reportBookViewModel) as RedirectToRouteResult; Assert.IsNotNull(facultative.Log); Assert.AreEqual(facultative.Log.Reports.Count, 1); Assert.AreEqual(facultative.Status, FacultativeStatus.Finished); Assert.AreEqual(facultative.Name, facultative.Log.Name); }