public void AddHomeworkToLecture_EntityNotFoundException_Test(int lectureId, string task)
        {
            // Arrange
            var lectures = new List <Lecture>(_testLectures);
            var students = new List <Student>
            {
                new Student
                {
                    Id   = 1,
                    Name = "Test"
                }
            };
            var studentLectures = new List <StudentLecture>
            {
                new StudentLecture
                {
                    LectureId = 1,
                    Student   = students.ElementAt(0),
                    StudentId = 1
                }
            };
            var homeworks = new List <Homework>();

            lectures.ElementAt(0).StudentLectures = studentLectures;

            Repository.Setup(x => x.GetLectureWithStudentsById(It.IsAny <int>()))
            .ReturnsAsync((int id) => lectures.Find(l => l.Id == id));
            HomeworkRepository.Setup(x => x.AddAsync(It.IsAny <Homework>()))
            .Callback((Homework homework) => homeworks.Add(homework));
            // Assert
            Assert.ThrowsAsync <EntityNotFoundException>(async() => await Service.AddHomeworkToLecture(lectureId, task));
        }
Example #2
0
        public void AddHomework(HomeworkViewModel homework)
        {
            Homework           homeworkToDAL = new Homework(homework.startDate, homework.endDate, homework.TeacherID, homework.Requirements);
            HomeworkRepository repository    = new HomeworkRepository();

            repository.AddHomework(homeworkToDAL);
        }
Example #3
0
        public IActionResult Get(string id)
        {
            HomeworkRepository homeworkRepository = new HomeworkRepository(homeworksXmlPath);
            Homework           homework           = homeworkRepository.Get(id);

            return(new ObjectResult(homework));
        }
Example #4
0
        public IActionResult Get()
        {
            HomeworkRepository     homeworkRepository = new HomeworkRepository(homeworksXmlPath);
            IEnumerable <Homework> homeworks          = homeworkRepository.GetAll();

            return(new ObjectResult(homeworks));
        }
Example #5
0
 public AppRepository(CsEvaluatorContext context)
 {
     HomeworkDescriptionRepository = new HomeworkDescriptionRepository(context);
     HomeworkRepository            = new HomeworkRepository(context);
     SubjectsRepository            = new SubjectsRepository(context);
     StudentRepository             = new StudentRepository(context);
 }
        public JsonResult GetHomeworks()
        {
            HomeworkRepository repository = new HomeworkRepository();

            List<Homework> groups = repository.GetAll();

            return new JsonResult { Data = groups, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }
Example #7
0
        public IActionResult Delete(string id)
        {
            HomeworkRepository homeworkRepository = new HomeworkRepository(homeworksXmlPath);

            homeworkRepository.Remove(id);

            return(NoContent());
        }
Example #8
0
        public void oneTimeSetUp()
        {
            var connection = DbConnectionFactory.CreateTransient();

            this.ctx  = new ApplicationDbContext(connection);
            this.repo = new HomeworkRepository(ctx);
            new DatabaseSeeder().CreateDependenciesAndSeed(ctx);//heavy duty
        }
Example #9
0
        public IActionResult GetAllByUserId(string userId)
        {
            Console.WriteLine(userId);
            HomeworkRepository     homeworkRepository = new HomeworkRepository(homeworksXmlPath);
            IEnumerable <Homework> homeworks          = homeworkRepository.GetAllByUserId(userId);

            return(new ObjectResult(homeworks));
        }
Example #10
0
 public HomeworksController(IHomeworkLogic homeworks = null) : base()
 {
     if (homeworks == null)
     {
         var context      = ContextFactory.GetNewContext();
         var homeworkRepo = new HomeworkRepository(context);
         var exerciseRepo = new ExerciseRepository(context);
         homeworks = new HomeworkLogic(homeworkRepo, exerciseRepo);
     }
     this.homeworks = homeworks;
 }
        public ActionResult Delete(CRUDHomeworkViewModel model)
        {

            HomeworkRepository repository = new HomeworkRepository();
            if (model.Id.ToString() != String.Empty)
            {
                repository.Delete(model.Id);
            }


            return RedirectToAction("Index");
        }
        // GET: Events
        public ActionResult Index()
        {

            HomeworkRepository repository = new HomeworkRepository();
            List<Homework> postPublications = repository.GetAll();
            postPublications.Reverse();

            HomeworkListViewModel model = new HomeworkListViewModel();
            model.Homeworks = postPublications;

            return View(model);
        }
        public void Where_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "FindTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository = new HomeworkRepository(context);
                var where = repository.Where(c => c.Id == 1);
                Assert.That(where.Count(), Is.EqualTo(1));
            }
        }
        public ActionResult Show(int id)
        {

            HomeworkRepository repository = new HomeworkRepository();

            Homework homework = repository.GetById(id);

            CRUDHomeworkViewModel model = new CRUDHomeworkViewModel();
            model.Title = homework.Title;
            model.Content = homework.Content;


            return View(model);
        }
        public void GetAll_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "GetTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository = new HomeworkRepository(context);
                var homeworks  = repository.GetAll();
                Assert.That(homeworks.Count(), Is.EqualTo(context.Homeworks.Count()));
            }
        }
        public async Task SingleOrDefault_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "FindTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository = new HomeworkRepository(context);
                var single     = await repository.SingleOrDefaultAsync(c => c.Id == 1);

                Assert.That(single.Id, Is.EqualTo(1));
            }
        }
Example #17
0
        public IActionResult Put(string id, string title, string description, string deadline, int grade)
        {
            HomeworkRepository homeworkRepository = new HomeworkRepository(homeworksXmlPath);
            Homework           homework           = homeworkRepository.Get(id);

            homework.Title       = title;
            homework.Description = description;
            homework.Deadline    = DateTime.Parse(deadline);
            homework.Grade       = grade;

            homeworkRepository.Modify(homework);

            // TODO: Check if this is the proper response
            return(NoContent());
        }
        public async Task GetByIdAsync_Test(int id)
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "GetTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository = new HomeworkRepository(context);
                var course     = await repository.GetByIdAsync(id);

                Assert.That(course.Id, Is.EqualTo(id));
            }
        }
Example #19
0
        public void TestHomeworkAddOK2()
        {
            var context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString());
            HomeworkRepository homeworkRepo = new HomeworkRepository(context);

            var name = "una tarea";

            homeworkRepo.Add(new Homework {
                Id          = Guid.NewGuid(),
                Description = name,
            });
            homeworkRepo.Save();
            var homeworks = homeworkRepo.GetAll().ToList();

            Assert.AreEqual(homeworks.Count, 1);
        }
Example #20
0
        public void TestHomeworkAddOK()
        {
            var context = ContextFactory.GetMemoryContext("MemoriaTestDB");
            HomeworkRepository homeworkRepo = new HomeworkRepository(context);

            var name = "una tarea";

            homeworkRepo.Add(new Homework {
                Id          = Guid.NewGuid(),
                Description = name,
            });
            homeworkRepo.Save();
            var homeworks = homeworkRepo.GetAll().ToList();

            Assert.AreEqual(homeworks[0].Description, name);
        }
Example #21
0
        public IActionResult Post(string title, string userId, string description, string deadline, int grade)
        {
            HomeworkRepository homeworkRepository = new HomeworkRepository(homeworksXmlPath);
            Homework           homework           = new Homework
            {
                Id          = Guid.NewGuid().ToString(),
                UserId      = userId,
                Title       = title,
                Description = description,
                Deadline    = DateTime.Parse(deadline),
                Grade       = grade
            };

            homeworkRepository.Add(homework);

            return(CreatedAtRoute("GetHomework", new { controller = "Homework", id = homework.Id }, homework));
        }
        public async Task Contains_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "FindTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository  = new HomeworkRepository(context);
                var newHomework = new Homework {
                    Mark = 0, Task = "Test33", LectureId = 10, StudentId = 50
                };
                var contains = await repository.Contains(newHomework);

                Assert.That(contains, Is.EqualTo(false));
            }
        }
        public ActionResult Edit(int? id)
        {

            HomeworkRepository repository = new HomeworkRepository();

            CRUDHomeworkViewModel model = new CRUDHomeworkViewModel();

            if (id.HasValue)
            {
                Homework homework = repository.GetById(id.Value);
                model.Id = homework.Id;
                model.Title = homework.Title;
                model.Content = homework.Content;
                homework.StudentId = user.Id;

            }

            return View(model);
        }
        public ActionResult Create(CRUDHomeworkViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            Homework homework = new Homework();
            // events.Id = model.Id;
            homework.Title = model.Title;
            homework.Content = model.Content;
            homework.StudentId = user.Id;
      


            var repository = new HomeworkRepository();
            repository.Insert(homework);

            return RedirectToAction("Index");
        }
        public async Task RemoveRange_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "RemoveTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository      = new HomeworkRepository(context);
                var removeHomeworks = new List <Homework>();
                removeHomeworks.AddRange(repository.GetAll().ToList());

                repository.RemoveRange(removeHomeworks);
                await context.SaveChangesAsync();

                var homeworks = repository.GetAll();
                Assert.That(homeworks.Count(), Is.EqualTo(0));
            }
        }
Example #26
0
        public List <HomeworkViewModel> GetHomeworksByTeacherID(int id)
        {
            HomeworkRepository       repo         = new HomeworkRepository();
            List <Homework>          homeworkList = repo.GetAllHomeworksByTeacherID(id);
            List <HomeworkViewModel> newList      = new List <HomeworkViewModel>();

            foreach (var item in homeworkList)
            {
                HomeworkViewModel newHomework = new HomeworkViewModel()
                {
                    TeacherID    = item.TeacherID,
                    HomeworkID   = item.HomeworkID,
                    startDate    = item.StartDate,
                    endDate      = item.EndDate,
                    Requirements = item.Requirements.ToString(),
                };

                newList.Add(newHomework);
            }
            return(newList);
        }
        public ActionResult Edit(CRUDHomeworkViewModel model)
        {

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            HomeworkRepository repository = new HomeworkRepository();

            Homework homework = new Homework();
            homework.Id = model.Id;


            homework.Title = model.Title;
            homework.Content = model.Content;
            homework.StudentId = user.Id;

            repository.Save(homework);

            return RedirectToAction("Index");
        }
        public async Task AddAsync_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "AddTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository  = new HomeworkRepository(context);
                var newHomework = new Homework {
                    Mark = 5, Task = "Test", LectureId = 1, StudentId = 2
                };
                var prevCount = repository.GetAll().Count();
                await repository.AddAsync(newHomework);

                await context.SaveChangesAsync();

                var homeworks = repository.GetAll();
                Assert.That(homeworks.Count(), Is.EqualTo(prevCount + 1));
            }
        }
        public async Task Update_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "UpdateTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository     = new HomeworkRepository(context);
                var updateHomework = await repository.GetByIdAsync(1);

                updateHomework.Task = "Update";

                repository.Update(updateHomework);
                var result = await repository.GetByIdAsync(1);

                await context.SaveChangesAsync();

                Assert.That(result.Task, Is.EqualTo("Update"));
            }
        }
Example #30
0
        //IGenericRepository IUnitOfWork.Repository => throw new NotImplementedException();

        public UnitOfWork()
        {
            dbContext                  = new DatabaseContext();
            Repository                 = new GenericRepository(dbContext);
            SchoolRepository           = new SchoolRepository(dbContext);
            ExceptionLoggerRepository  = new ExceptionLoggerRepository(dbContext);
            ApiLogRepository           = new ApiLogRepository(dbContext);
            ImageFileTypeRepository    = new ImageFileTypeRepository(dbContext);
            AssessmentRepository       = new AssessmentRepository(dbContext);
            AttendanceRepository       = new AttendanceRepository(dbContext);
            BookRepository             = new BookRepository(dbContext);
            BookTransactionRepository  = new BookTransactionRepository(dbContext);
            EventRepository            = new EventRepository(dbContext);
            HomeworkRepository         = new HomeworkRepository(dbContext);
            ImageFileUrlRepository     = new ImageFileUrlRepository(dbContext);
            ParentRepository           = new ParentRepository(dbContext);
            StandardRepository         = new StandardRepository(dbContext);
            StudentRepository          = new StudentRepository(dbContext);
            SubjectRepository          = new SubjectRepository(dbContext);
            TeacherRepository          = new TeacherRepository(dbContext);
            YearRepository             = new YearRepository(dbContext);
            OperationalStaffRepository = new OperationalStaffRepository(dbContext);
        }