Example #1
0
        public void CreateHomework_StudentEntityNotFoundException_Test()
        {
            // Arrange
            var testCreate = new List <Homework>(_testHomeworks);
            var homework   = new Homework {
                Id = 3, LectureId = 1, StudentId = 2, Task = "Test", Mark = 5
            };

            var students = new List <Student>
            {
                new Student
                {
                    Id   = 1,
                    Name = "Test"
                }
            };
            var lectures = new List <Lecture>
            {
                new Lecture
                {
                    Id   = 1,
                    Name = "Test"
                }
            };

            Repository.Setup(x => x.AddAsync(It.IsAny <Homework>()))
            .Callback((Homework homework) => testCreate.Add(homework));
            StudentRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => students.Find(s => s.Id == id));
            LectureRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => lectures.Find(s => s.Id == id));
            // Assert
            Assert.ThrowsAsync <EntityNotFoundException>(async() => await Service.CreateHomework(homework));
        }
        public async Task AddRangeAsync_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "AddTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository  = new LectureRepository(context);
                var newLectures = new List <Lecture>
                {
                    new Lecture
                    {
                        Name = "Test"
                    },
                    new Lecture
                    {
                        Name = "Test"
                    }
                };
                var prevCount = repository.GetAll().Count();
                await repository.AddRangeAsync(newLectures);

                await context.SaveChangesAsync();

                var lectures = repository.GetAll();
                Assert.That(lectures.Count(), Is.EqualTo(prevCount + 2));
            }
        }
Example #3
0
        public void UpdateHomework_NormalConditions_Test()
        {
            // Arrange
            var testUpdate = new List <Homework>
            {
                new Homework
                {
                    Id        = 1,
                    Mark      = 5,
                    Task      = "Test",
                    LectureId = 1,
                    StudentId = 1
                }
            };
            var students = new List <Student>
            {
                new Student
                {
                    Id   = 1,
                    Name = "Test"
                }
            };
            var lectures = new List <Lecture>
            {
                new Lecture
                {
                    Id   = 1,
                    Name = "Test"
                }
            };

            Repository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => testUpdate.Find(c => c.Id == id));
            StudentRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => students.Find(s => s.Id == id));
            LectureRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => lectures.Find(s => s.Id == id));

            Repository.Setup(x => x.Update(It.IsAny <Homework>()))
            .Callback((Homework homework) => testUpdate[testUpdate.FindIndex(x => x.Id == homework.Id)] = homework);

            var updateHomework = new Homework
            {
                Id        = 1,
                Mark      = 5,
                Task      = "update",
                LectureId = 1,
                StudentId = 1
            };

            // Act
            Service.UpdateHomework(updateHomework);
            // Assert
            Repository.Verify(x => x.Update(It.IsAny <Homework>()), Times.Once);
            Assert.That("update", Is.EqualTo(testUpdate.ElementAt(0).Task));
        }
Example #4
0
        public void UpdateHomework_LectureEntityNotFoundException_Test()
        {
            // Arrange
            var testUpdate = new List <Homework>
            {
                new Homework
                {
                    Id        = 1,
                    Mark      = 5,
                    Task      = "Test",
                    LectureId = 1,
                    StudentId = 1
                }
            };
            var students = new List <Student>
            {
                new Student
                {
                    Id   = 1,
                    Name = "Test"
                }
            };
            var lectures = new List <Lecture>
            {
                new Lecture
                {
                    Id   = 1,
                    Name = "Test"
                }
            };

            Repository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => testUpdate.Find(c => c.Id == id));
            StudentRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => students.Find(s => s.Id == id));
            LectureRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => lectures.Find(s => s.Id == id));

            Repository.Setup(x => x.Update(It.IsAny <Homework>()))
            .Callback((Homework homework) => testUpdate[testUpdate.FindIndex(x => x.Id == homework.Id)] = homework);

            var updateHomework = new Homework
            {
                Id        = 1,
                Mark      = 5,
                Task      = "update",
                LectureId = 2,
                StudentId = 1
            };

            // Assert
            Assert.ThrowsAsync <EntityNotFoundException>(async() => await Service.UpdateHomework(updateHomework));
        }
Example #5
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context     = context;
     Departments  = new DepartmentRepository(context);
     Teachers     = new TeacherRepository(context);
     Lectures     = new LectureRepository(context);
     Lessions     = new LessionRepository(context);
     Students     = new StudentRepository(context);
     Specialities = new SpecialityRepository(context);
     Groups       = new GroupRepository(context);
     Points       = new PointRepository(context);
 }
 public CourseService(CourseRepository courseRepository, FeedbackRepository feedbackRepository,
                      CategoryRepository categoryRepository, UserRepository userRepository,
                      ViewRepository viewRepository, StudentCourseRepository studentCourseRepository,
                      LectureRepository lectureRepository)
 {
     this.courseRepository        = courseRepository;
     this.feedbackRepository      = feedbackRepository;
     this.categoryRepository      = categoryRepository;
     this.userRepository          = userRepository;
     this.viewRepository          = viewRepository;
     this.studentCourseRepository = studentCourseRepository;
     this.lectureRepository       = lectureRepository;
 }
        public void GetByIdAsyncTest_ThrowsException([Values(1)] int id)
        {
            // Arrange
            var loggerMock = new Mock <ILogger <LectureRepository> >();
            var repository = new LectureRepository(_contextFactory, loggerMock.Object);

            // Act
            _contextFactory.SimulateSqlException = true;
            async Task TestAction() => await repository.GetByIdAsync(id);

            // Assert
            Assert.ThrowsAsync <DataException>(TestAction);
        }
        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 LectureRepository(context);
                var lectures   = repository.GetAll();
                Assert.That(lectures.Count(), Is.EqualTo(context.Lectures.Count()));
            }
        }
        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 LectureRepository(context);
                var where = repository.Where(c => c.Id == 1);
                Assert.That(where.Count(), Is.EqualTo(1));
            }
        }
        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 LectureRepository(context);
                var lecture    = await repository.GetByIdAsync(id);

                Assert.That(lecture.Id, Is.EqualTo(id));
            }
        }
        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 LectureRepository(context);
                var single     = await repository.SingleOrDefaultAsync(c => c.Id == 1);

                Assert.That(single.Id, Is.EqualTo(1));
            }
        }
Example #12
0
 public UnitOfWork(ELearningDBContext context)
 {
     _context = context;
     Account  = new AccountRepository(_context);
     Comments = new CommentRepository(_context);
     Courses  = new CourseRepository(_context);
     // CourseSubject = new CourseSubjectRepository(_context);
     Documents       = new DocumentRepository(_context);
     Lectures        = new LectureRepository(_context);
     Rating          = new RatingRepository(_context);
     Role            = new RoleRepository(_context);
     StudentSubjects = new StudentSubjectRepository(_context);
     StudentTests    = new StudentTestRepository(_context);
     Subjects        = new SubjectRepository(_context);
     TeacherSubjects = new TeacherSubjectRepository(_context);
 }
Example #13
0
        public EntityService()
        {
            weekDayRepository     = new WeekDayRepository();
            roomLectureRepository = new RoomLectureRepository();
            roomRepository        = new RoomRepository();

            lectureRepository         = new LectureRepository();
            parentRepository          = new ParentRepository();
            postponedLessonRepository = new PostponedLessonRepository();
            programRepository         = new ProgramRepository();
            recievedPaymentRepository = new RecievedPaymentRepository();

            studentRepository        = new StudentRepository();
            teacherLectureRepository = new TeacherLectureRepository();
            teacherPaymentRepository = new TeacherPaymentRepository();
            teacherRepository        = new TeacherRepository();
            userRepository           = new UserRepository();
        }
        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 LectureRepository(context);
                var newLecture = new Lecture {
                    Name = "TESTSTSTST"
                };
                var contains = await repository.Contains(newLecture);

                Assert.That(contains, Is.EqualTo(false));
            }
        }
        public async Task GetByIdAsyncTest(IEnumerable <Lecture> data, int id, Lecture?expected)
        {
            // Arrange
            await using (ApplicationContext context = _contextFactory.CreateDbContext())
            {
                await context.Lectures.AddRangeAsync(data);

                await context.SaveChangesAsync();
            }

            var loggerMock = new Mock <ILogger <LectureRepository> >();
            var repository = new LectureRepository(_contextFactory, loggerMock.Object);

            // Act
            Lecture?lecture = await repository.GetByIdAsync(id);

            // Assert
            Assert.That(lecture, Is.EqualTo(expected));
        }
        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 LectureRepository(context);
                var removeLectures = new List <Lecture>();
                removeLectures.AddRange(repository.GetAll().ToList());

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

                var lectures = repository.GetAll();
                Assert.That(lectures.Count(), Is.EqualTo(0));
            }
        }
        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 LectureRepository(context);
                var updateLecture = await repository.GetByIdAsync(1);

                updateLecture.Name = "Update";

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

                await context.SaveChangesAsync();

                Assert.That(result.Name, Is.EqualTo("Update"));
            }
        }
Example #18
0
        public void CreateHomework_EntityAlreadyExistException_Test()
        {
            // Arrange
            var testCreate = new List <Homework>(_testHomeworks);
            var homework   = testCreate.ElementAt(0);

            homework.LectureId = 1;
            homework.StudentId = 1;

            var students = new List <Student>
            {
                new Student
                {
                    Id   = 1,
                    Name = "Test"
                }
            };
            var lectures = new List <Lecture>
            {
                new Lecture
                {
                    Id   = 1,
                    Name = "Test"
                }
            };

            Repository.Setup(x => x.AddAsync(It.IsAny <Homework>()))
            .Callback((Homework homework) => testCreate.Add(homework));
            StudentRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => students.Find(s => s.Id == id));
            LectureRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => lectures.Find(s => s.Id == id));
            Repository.Setup(x => x.Contains(It.IsAny <Homework>()))
            .ReturnsAsync((Homework homework) => testCreate.Contains(homework));
            // Assert
            Assert.ThrowsAsync <EntityAlreadyExistException>(async() => await Service.CreateHomework(homework));
        }
Example #19
0
        public void CreateHomework_NormalConditions_Test()
        {
            // Arrange
            var testCreate = new List <Homework>(_testHomeworks);
            var homework   = new Homework {
                Id = 3, LectureId = 1, StudentId = 1, Task = "Test", Mark = 5
            };

            var students = new List <Student>
            {
                new Student
                {
                    Id   = 1,
                    Name = "Test"
                }
            };
            var lectures = new List <Lecture>
            {
                new Lecture
                {
                    Id   = 1,
                    Name = "Test"
                }
            };

            Repository.Setup(x => x.AddAsync(It.IsAny <Homework>()))
            .Callback((Homework homework) => testCreate.Add(homework));
            StudentRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => students.Find(s => s.Id == id));
            LectureRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync((int id) => lectures.Find(s => s.Id == id));
            // Act
            Service.CreateHomework(homework);
            // Assert
            Repository.Verify(x => x.AddAsync(It.IsAny <Homework>()), Times.Once);
            Assert.That(3, Is.EqualTo(testCreate.Count()));
        }
Example #20
0
 public CoursesController(CourseService courseService, LectureRepository lectureRepository, IMapper mapper)
 {
     this.courseService     = courseService;
     this.lectureRepository = lectureRepository;
     this.mapper            = mapper;
 }
Example #21
0
 public LectureService()
 {
     lectureRepository = new LectureRepository();
 }
Example #22
0
 public LecturesController(LectureRepository lectureRepository, IMapper mapper)
 {
     this.lectureRepository = lectureRepository;
     this.mapper            = mapper;
 }
 public CourseProcessesController(CourseProcessRepository courseProcessRepository, LectureRepository lectureRepository)
 {
     this.courseProcessRepository = courseProcessRepository;
     this.lectureRepository       = lectureRepository;
 }