public void CreateReturnsClassInRepository()
        {
            var model = new ClassesCreateViewModel
            {
                DayOfWeek  = DaysOfWeek.Понеделник.ToString(),
                Discipline = Disciplines.Английски_език.ToString(),
                Room       = Room.Стая_1.ToString(),
                TimeOfDay  = "11:00 - 12:30",
                TeacherId  = "teacherId",
                StudentIds = new List <string> {
                    "studentId"
                }
            };

            var options = new DbContextOptionsBuilder <LearningPlusDbContext>()
                          .UseInMemoryDatabase(databaseName: "Create_Classes_Database") // Give a Unique name to the DB
                          .Options;
            var dbContext = new LearningPlusDbContext(options);

            var repository     = new DbRepository <LearningPlusClass>(dbContext);
            var classesService = new ClassesService(null, null, repository, null);

            var createdModel = classesService.Create(model);

            repository.All().CountAsync().GetAwaiter().GetResult().ShouldBe(1);
        }
        public void DeleteByIdReturnsInactiveClass()
        {
            var teacher = new Mock <LearningPlusUser>();

            teacher.Setup(t => t.Id).Returns("teacherId");
            teacher.Setup(t => t.FirstName).Returns("TeacherFirst");
            teacher.Setup(t => t.LastName).Returns("TeacherLast");

            var model = new ClassesCreateViewModel
            {
                DayOfWeek  = DaysOfWeek.Понеделник.ToString(),
                Discipline = Disciplines.Английски_език.ToString(),
                Room       = Room.Стая_1.ToString(),
                TimeOfDay  = "11:00 - 12:30",
                TeacherId  = "teacherId",
                StudentIds = new List <string> {
                    "studentId"
                }
            };

            var options = new DbContextOptionsBuilder <LearningPlusDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_Classes_Database") // Give a Unique name to the DB
                          .Options;
            var dbContext = new LearningPlusDbContext(options);

            dbContext.Users.Add(teacher.Object);
            var repository     = new DbRepository <LearningPlusClass>(dbContext);
            var classesService = new ClassesService(null, null, repository, null);

            var createdModel = classesService.Create(model);
            var id           = createdModel.Id.ToString();
            var deletedClass = classesService.DeleteById(id);

            deletedClass.Active.ShouldBe(false);
        }
        public void GetScheduleClassesReturnsCorrectClasses()
        {
            var student = new Mock <LearningPlusUser>();

            student.Setup(t => t.Id).Returns("studentId");
            student.Setup(t => t.FirstName).Returns("First");
            student.Setup(t => t.LastName).Returns("Last");

            var model = new ClassesCreateViewModel
            {
                DayOfWeek  = DaysOfWeek.Понеделник.ToString(),
                Discipline = Disciplines.Английски_език.ToString(),
                Room       = Room.Стая_1.ToString(),
                TimeOfDay  = "11:00 - 12:30",
                TeacherId  = "teacherId",
                StudentIds = new List <string> {
                    "studentId"
                }
            };

            var options = new DbContextOptionsBuilder <LearningPlusDbContext>()
                          .UseInMemoryDatabase(databaseName: "Schedule_Classes_Database") // Give a Unique name to the DB
                          .Options;
            var dbContext = new LearningPlusDbContext(options);

            dbContext.Users.Add(student.Object);
            var repository     = new DbRepository <LearningPlusClass>(dbContext);
            var classesService = new ClassesService(null, null, repository, null);
            var createdModel   = classesService.Create(model);

            var classes = classesService.GetScheduleClasses();

            classes.Count.ShouldBe(1);
        }
示例#4
0
 public ClassController(ClassesRepository classesRepository, ClassesService classesService, IMapper mapper, FileHelper fileHelper, PaginatedMetaService paginatedMetaService)
 {
     _classesRepository    = classesRepository;
     _classesService       = classesService;
     _mapper               = mapper;
     _fileHelper           = fileHelper;
     _paginatedMetaService = paginatedMetaService;
 }
示例#5
0
        public void GetTeachersShouldReturnCollectionOfTeachers()
        {
            var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>()
                            .UseInMemoryDatabase("test");
            var context = new ApplicationDbContext(dbOptions.Options);

            var rolesService   = new WebSchool.Services.RolesService(context);
            var linksService   = new LinksService(context);
            var usersService   = new UsersService(context, rolesService, linksService);
            var classesService = new ClassesService(context, usersService, rolesService);
            var teacherService = new TeacherService(context, classesService, rolesService);

            var result = teacherService.GetTeachers("id");

            Assert.True(result.Count == 0);
        }
示例#6
0
        public void GetTeacherShouldReturnNullWhenTeacherIsMissing()
        {
            var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>()
                            .UseInMemoryDatabase("test");
            var context = new ApplicationDbContext(dbOptions.Options);

            var rolesService   = new WebSchool.Services.RolesService(context);
            var linksService   = new LinksService(context);
            var usersService   = new UsersService(context, rolesService, linksService);
            var classesService = new ClassesService(context, usersService, rolesService);
            var teacherService = new TeacherService(context, classesService, rolesService);

            var result = teacherService.GetTeacher("id");

            Assert.Null(result);
        }
示例#7
0
 public static void Initialize()
 {
     ClassesService = new ClassesService();
     OriginService  = new OriginService();
     ItemService    = new ItemService();
 }