Ejemplo n.º 1
0
        public async Task GetCourseByIdShouldReturnCorrectCourse()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetCourseByIdShouldReturnCorrectCourse")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(new Course()
                {
                    CourseId = 1,
                    Name     = "DummyCourse",
                    Start    = DateTime.Now,
                    Teacher  = new User {
                        Id = 1, UserName = "******"
                    }
                });

                await context.SaveChangesAsync();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);
                var result        = await courseService.GetCourseByIdAsync(1);

                Assert.IsTrue(result != null && result.Name == "DummyCourse");
            }
        }
Ejemplo n.º 2
0
        public async Task AddAssignmentShouldThrowIfInvalidName()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "AddAssignmentShouldThrowIfInvalidName")
                                 .Options;

            string name      = null;
            var    courseId  = 1;
            var    teacherId = 1;
            var    dateDue   = DateTime.Now;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var course = new Course
                {
                    CourseId  = 1,
                    Name      = "MockCourse",
                    TeacherId = 1
                };
                var teacher = new User
                {
                    Id       = 1,
                    UserName = "******"
                };
                context.Courses.Add(course);
                context.Users.Add(teacher);
                context.SaveChanges();

                var courseService = new CourseService(context);

                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await courseService.AddAssignment(courseId, teacherId, 100, name, dateDue));
            }
        }
Ejemplo n.º 3
0
        public void RetrieveStudentsInCourseShouldThrowIfUserNotFound()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveStudentsInCourseShouldThrowIfUserNotFound")
                                 .Options;


            var course = new Course()
            {
                CourseId = 1,
                Name     = "SQL"
            };

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(course);

                context.SaveChanges();

                var courseService = new CourseService(context);

                var error = Assert.ThrowsExceptionAsync <IncorrectPermissionsException>
                                (async() => await courseService.RetrieveStudentsInCourseAsync(1, 2, 1)).GetAwaiter().GetResult();
                Assert.AreEqual("Invalid Permission", error.Message);
            }
        }
Ejemplo n.º 4
0
        public async Task UpdateRoleThrowExceptionWhenPermissionNotValid()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "UpdateRoleThrowExceptionWhenPermissionNotValid")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev",
                    RoleId   = 2
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                await userService.UpdateRoleAsync(1, 1);
            }
        }
Ejemplo n.º 5
0
        public async Task EnrollStudentShouldThrowIfCourseNotFound()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "EnrollStudentShouldThrowIfCourseNotFound")
                                 .Options;

            var student = new User()
            {
                Id       = 1,
                UserName = "******"
            };

            var course = new Course()
            {
                CourseId  = 1,
                Name      = "SQL",
                TeacherId = 2
            };

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(course);
                context.Users.Add(student);

                context.SaveChanges();

                var courseService = new CourseService(context);

                await Assert.ThrowsExceptionAsync <CourseDoesntExistsException>(async() => await courseService.EnrollStudentToCourseAsync(1, 2));
            }
        }
Ejemplo n.º 6
0
        public async Task GetUserByIdShouldReturnUser()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetUserByIdShouldReturnUser")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev",
                    RoleId   = 2
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                var user        = await userService.GetUserByIdAsync(1);

                Assert.IsTrue(user.UserName == "pesho12");
            }
        }
Ejemplo n.º 7
0
        public async Task EvaluateStudentShouldThrowExceptionIfStudentAlreadyEvaluatedForThisCourse()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "EvaluateStudentShouldThrowExceptionIfStudentAlreadyEvaluatedForThisCourse")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev - Uchitelq",
                    RoleId   = 2
                });

                context.Users.Add(new User()
                {
                    Id       = 2,
                    UserName = "******",
                    FullName = "Gosho Goshev - Studentcheto",
                    RoleId   = 3
                });
                context.Assignments.Add(new Assignment()
                {
                    Id        = 1,
                    Name      = "Grebane s lajica",
                    MaxPoints = 100,
                    CourseId  = 1
                });

                context.Courses.Add(new Course()
                {
                    CourseId  = 1,
                    Name      = "asdv",
                    TeacherId = 1
                });

                context.EnrolledStudents.Add(new EnrolledStudent()
                {
                    StudentId = 2,
                    CourseId  = 1
                });

                context.Grades.Add(new Grade()
                {
                    StudentId     = 2,
                    ReceivedGrade = 43,
                    AssignmentId  = 1
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                await userService.EvaluateStudentAsync(2, 1, 45, 1);
            }
        }
Ejemplo n.º 8
0
        public async Task AddCourseShouldThrowIfUserNotTeacher()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "AddCourseShouldThrowIfUserNotTeacher")
                                 .Options;

            var courseName = "SQL";
            var startDate  = DateTime.Now;
            var endDate    = DateTime.Now.AddDays(30);

            using (var context = new AcademySiteContext(contextOptions))
            {
                var teacher = new User()
                {
                    Id       = 1,
                    UserName = "******",
                    RoleId   = 3
                };

                context.Users.Add(teacher);

                context.SaveChanges();

                var courseService = new CourseService(context);

                await Assert.ThrowsExceptionAsync <IncorrectPermissionsException>(async() => await courseService.AddCourseAsync(1, startDate, endDate, courseName));
            }
        }
Ejemplo n.º 9
0
        public async Task AddCourseShouldCorrectlyAddCourse()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "AddCourseShouldCorrectlyAddCourse")
                                 .Options;

            var courseName = "SQL";
            var startDate  = DateTime.Now;
            var endDate    = DateTime.Now.AddDays(30);

            using (var context = new AcademySiteContext(contextOptions))
            {
                var teacher = new User()
                {
                    Id       = 1,
                    UserName = "******",
                    RoleId   = 2
                };

                context.Users.Add(teacher);

                context.SaveChanges();

                var courseService = new CourseService(context);

                await courseService.AddCourseAsync(1, startDate, endDate, courseName);

                Assert.AreEqual(1, context.Courses.Count());
                Assert.IsTrue(context.Courses.Any(co => co.Name == "SQL" && co.TeacherId == 1));
            }
        }
Ejemplo n.º 10
0
        public async Task GetUserByIdShouldThrowExceptionWhenIdNotFound()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetUserByIdShouldThrowExceptionWhenIdNotFound")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev",
                    RoleId   = 2
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                var user        = await userService.GetUserByIdAsync(10);
            }
        }
Ejemplo n.º 11
0
        public async Task EvaluateStudentShouldAddGradeWhenCorrectParametersArePassed()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "EvaluateStudentShouldAddGradeWhenCorrectParametersArePassed")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev - Uchitelq",
                    RoleId   = 2
                });

                context.Users.Add(new User()
                {
                    Id       = 2,
                    UserName = "******",
                    FullName = "Gosho Goshev - Studentcheto",
                    RoleId   = 3
                });
                context.Assignments.Add(new Assignment()
                {
                    Id        = 1,
                    Name      = "Grebane s lajica",
                    MaxPoints = 100,
                    CourseId  = 1
                });

                context.Courses.Add(new Course()
                {
                    CourseId  = 1,
                    Name      = "asdv",
                    TeacherId = 1
                });

                context.EnrolledStudents.Add(new EnrolledStudent()
                {
                    StudentId = 2,
                    CourseId  = 1
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                await userService.EvaluateStudentAsync(2, 1, 45, 1);

                var users = userService.RetrieveUsersAsync(3).Result.ToList();
                Assert.IsTrue(users.Count == 1);
                Assert.IsTrue(users[0].Grades.Any(gr => gr.ReceivedGrade == 45));
            }
        }
Ejemplo n.º 12
0
        public async Task RetrieveCoursesByStudentShouldReturnCorrectCourses()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveCoursesByStudentShouldReturnCorrectCourses")
                                 .Options;

            var courseByStudent = new Course()
            {
                CourseId         = 1,
                Name             = "Grebane s lajica",
                EnrolledStudents = new List <EnrolledStudent>()
            };

            courseByStudent.EnrolledStudents.Add(new EnrolledStudent()
            {
                StudentId = 2, CourseId = 1
            });


            var courseNotByStudent = new Course()
            {
                CourseId = 2,
                Name     = "Pletene na potnici",
                Teacher  = new User
                {
                    UserName = "******",
                    RoleId   = 2
                }
            };

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(courseByStudent);

                context.Courses.Add(courseNotByStudent);

                context.Users.Add(new User()
                {
                    Id       = 2,
                    UserName = "******",
                    FullName = "Gosho Goshev - Studentcheto",
                    RoleId   = 3
                });

                context.SaveChanges();

                var courseService = new CourseService(context);

                var result = await courseService.RetrieveCoursesByStudentAsync(2);

                Assert.IsTrue(result.Count() == 1);
                Assert.IsTrue(result.Any(co => co.Name == "Grebane s lajica"));
            }
        }
Ejemplo n.º 13
0
        public async Task UpdatedRoleShouldThrowExceptionWhenUserIdNegative()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "UpdatedRoleShouldThrowExceptionWhenUserIdNegative")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                var user        = await userService.GetUserByIdAsync(-1);
            }
        }
Ejemplo n.º 14
0
        public async Task RetrieveStudentsInCourseShouldThrowIfCourseNotFound()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveStudentsInCourseShouldThrowIfCourseNotFound")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);
                await Assert.ThrowsExceptionAsync <CourseDoesntExistsException>(async() => await courseService.RetrieveStudentsInCourseAsync(1, 1, 2));
            }
        }
Ejemplo n.º 15
0
        public async Task RetrieveCoursesByStudentThrowWhenIdInvalid()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveCoursesByStudentThrowWhenIdInvalid")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);

                await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await courseService.RetrieveCoursesByStudentAsync(-1));
            }
        }
Ejemplo n.º 16
0
        public async Task GetCourseByIdShouldThrowIfInvalidIdPassed()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetCourseByIdShouldThrowIfInvalidIdPassed")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);

                await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await courseService.GetCourseByIdAsync(-1));
            }
        }
Ejemplo n.º 17
0
        public async Task GetCourseByIdShouldReturnNullIfCourseNotFound()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetCourseByIdShouldReturnNullIfCourseNotFound")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);

                var result = await courseService.GetCourseByIdAsync(1);

                Assert.IsTrue(result == null);
            }
        }
Ejemplo n.º 18
0
        public async Task GetAllCoursesShouldReturnEmptyStringIfNoCourses()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetAllCoursesShouldReturnEmptyStringIfNoCourses")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);

                var result = await courseService.GetAllCoursesAsync();

                Assert.IsTrue(result.Count() == 0);
            }
        }
Ejemplo n.º 19
0
        public void RetrieveStudentsInCourseShouldThrowIfInvalidRoleId()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveStudentsInCourseShouldThrowIfInvalidRoleId")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);

                var expected = Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>
                                   (async() => await courseService.RetrieveStudentsInCourseAsync(1, -1, 1)).GetAwaiter().GetResult();

                Assert.AreEqual("The id of a role can only be a postive number.", expected.Message);
            }
        }
Ejemplo n.º 20
0
        public async Task EvaluateStudentShouldThrowExceptionIfTeacherIdIsInvalid()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "EvaluateStudentShouldThrowExceptionIfTeacherIdIsInvalid")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev",
                    RoleId   = 1
                });

                context.Users.Add(new User()
                {
                    Id       = 2,
                    UserName = "******",
                    FullName = "Gosho Goshev",
                    RoleId   = 3
                });
                context.Assignments.Add(new Assignment()
                {
                    Id        = 1,
                    Name      = "Grebane s lajica",
                    MaxPoints = 100,
                    CourseId  = 1
                });

                context.Courses.Add(new Course()
                {
                    CourseId = 1,
                    Name     = "asdv"
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                await userService.EvaluateStudentAsync(1, 1, 45, 12);
            }
        }
Ejemplo n.º 21
0
        public void AddAssignmentShouldThrowIfInvalidCourse()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveCoursesByStudentThrowWhenIdInvalid")
                                 .Options;

            var name      = "TestHomework";
            var courseId  = 1;
            var teacherId = 1;
            var dateDue   = DateTime.Now;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);

                Assert.ThrowsExceptionAsync <ArgumentException>(async() => await courseService.AddAssignment(courseId, teacherId, 100, name, dateDue));
            }
        }
Ejemplo n.º 22
0
        public async Task RetrieveCoursesByTeacherShouldReturnCorrectCourses()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetrieveCoursesByTeacherShouldReturnCorrectCourses")
                                 .Options;

            var courseByTeacher = new Course()
            {
                CourseId = 1,
                Name     = "SQL",
                Teacher  = new User
                {
                    UserName = "******",
                    RoleId   = 2
                }
            };

            var courseNotByTeacher = new Course()
            {
                CourseId = 2,
                Name     = "SQL2",
                Teacher  = new User
                {
                    UserName = "******",
                    RoleId   = 2
                }
            };

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(courseByTeacher);

                context.Courses.Add(courseNotByTeacher);

                context.SaveChanges();

                var courseService = new CourseService(context);

                var result = await courseService.RetrieveCoursesByTeacherAsync(1);

                Assert.IsTrue(result.Count() == 1);
                Assert.IsTrue(result.Any(co => co.Teacher.UserName == "Pesho"));
            }
        }
Ejemplo n.º 23
0
        public async Task UpdateRoleShouldUpdateRoleWhenAllParametersAreValid()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "UpdateRoleShouldUpdateRoleWhenAllParametersAreValid")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev",
                    RoleId   = 2
                });
                context.Roles.Add(new Microsoft.AspNetCore.Identity.IdentityRole <int>()
                {
                    Name           = "SomeRole",
                    NormalizedName = "SOMEROLE"
                });
                context.SaveChanges();
                context.UserRoles.Add(new Microsoft.AspNetCore.Identity.IdentityUserRole <int>()
                {
                    UserId = 1, RoleId = 1
                });
                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                await userService.UpdateRoleAsync(1, 3);

                var user = await context.Users.FirstOrDefaultAsync(us => us.Id == 1);

                Assert.IsTrue(user.RoleId == 3);
                Assert.IsTrue(context.UserRoles.Where(ur => ur.UserId == user.Id).ToList().Count == 1);
                Assert.IsTrue(context.UserRoles.FirstOrDefault(ur => ur.UserId == user.Id).RoleId == 3);
            }
        }
Ejemplo n.º 24
0
        public async Task GetAllCoursesShouldReturnCorses()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "GetAllCoursesShouldReturnCorses")
                                 .Options;


            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(new Course()
                {
                    Name    = "DummyCourse",
                    Start   = DateTime.Now,
                    Teacher = new User {
                        Id = 1, UserName = "******"
                    }
                });
                context.Courses.Add(new Course()
                {
                    Name    = "DummyCourseTwo",
                    Start   = DateTime.Now,
                    Teacher = new User {
                        Id = 2, UserName = "******"
                    }
                });
                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var courseService = new CourseService(context);
                var result        = await courseService.GetAllCoursesAsync();

                Assert.IsTrue(result.Count() == 2);
                Assert.IsTrue(result.Any(co => co.Name == "DummyCourse") && result.Any(co => co.Name == "DummyCourseTwo"));
            }
        }
Ejemplo n.º 25
0
        public async Task AddAssignmentShouldAddAssignmentIfCorrectParameters()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "AddAssignmentShouldAddAssignmentIfCorrectParameters")
                                 .Options;

            string name      = "Test Assignment";
            var    courseId  = 1;
            var    teacherId = 1;
            var    dateDue   = DateTime.Now;

            using (var context = new AcademySiteContext(contextOptions))
            {
                var course = new Course
                {
                    CourseId  = 1,
                    Name      = "MockCourse",
                    TeacherId = 1
                };
                var teacher = new User
                {
                    Id       = 1,
                    UserName = "******"
                };
                context.Courses.Add(course);
                context.Users.Add(teacher);
                context.SaveChanges();

                var courseService = new CourseService(context);

                var assignemnt = await courseService.AddAssignment(courseId, teacherId, 100, name, dateDue);

                Assert.IsTrue(assignemnt.Name == name);
                Assert.IsTrue(context.Assignments.Any(a => a.Name == name));
                Assert.IsTrue(context.Assignments.Count() == 1);
            }
        }
Ejemplo n.º 26
0
        public async Task EnrollStudentToCourseShouldEnrollIfAllParamsValid()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "EnrollStudentToCourseShouldEnrollIfAllParamsValid")
                                 .Options;

            var student = new User()
            {
                Id       = 1,
                UserName = "******"
            };

            var course = new Course()
            {
                CourseId  = 1,
                Name      = "SQL",
                TeacherId = 2
            };

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Courses.Add(course);
                context.Users.Add(student);

                context.SaveChanges();

                var courseService = new CourseService(context);

                await courseService.EnrollStudentToCourseAsync(1, 1);

                var user = context.Users.Include(us => us.EnrolledStudents).FirstOrDefault(us => us.Id == 1);

                Assert.IsTrue(user.EnrolledStudents.Count == 1);
                Assert.IsTrue(user.EnrolledStudents.Any(es => es.CourseId == 1));
            }
        }
Ejemplo n.º 27
0
        public async Task RetriveUsersShouldReturnUsers()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "RetriveUsersShouldThrowExceptionWhenNoUsersFound")
                                 .Options;

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(new User()
                {
                    Id       = 1,
                    UserName = "******",
                    FullName = "Pesho Peshev",
                    RoleId   = 3
                });

                context.Users.Add(new User()
                {
                    Id       = 2,
                    UserName = "******",
                    FullName = "Gosho Goshev",
                    RoleId   = 3
                });

                context.SaveChanges();
            }

            using (var context = new AcademySiteContext(contextOptions))
            {
                var userService = new UserService(context);
                var users       = await userService.RetrieveUsersAsync(3);

                var usersList = users.ToList();
                Assert.IsTrue(usersList.Count == 2);
            }
        }
Ejemplo n.º 28
0
        public async Task EnrollStudentShouldThrowIfUserAlreadyEnrolled()
        {
            var contextOptions = new DbContextOptionsBuilder <AcademySiteContext>()
                                 .UseInMemoryDatabase(databaseName: "EnrollStudentShouldThrowIfUserAlreadyEnrolled")
                                 .Options;

            var course = new Course()
            {
                CourseId  = 1,
                Name      = "SQL",
                TeacherId = 2
            };

            var student = new User()
            {
                Id               = 1,
                UserName         = "******",
                EnrolledStudents = new List <EnrolledStudent> {
                    new EnrolledStudent()
                    {
                        Course = course
                    }
                }
            };

            using (var context = new AcademySiteContext(contextOptions))
            {
                context.Users.Add(student);

                context.SaveChanges();

                var courseService = new CourseService(context);

                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(async() => await courseService.EnrollStudentToCourseAsync(1, 1));
            }
        }
Ejemplo n.º 29
0
 public GradeService(AcademySiteContext context)
 {
     this.context = context;
 }
Ejemplo n.º 30
0
 public UserService(AcademySiteContext context)
 {
     this.context = context ?? throw new ArgumentNullException(nameof(context));
 }