public async Task DeleteCourseByIdMarksTheCourseAsDeleted() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CreateCourse_Database2") .Options; BaseServiceTests.Initialize(); string courseId = "delete1"; using (var context = new LMSAppContext(options)) { context.Courses.Add(new Course() { Id = courseId, Name = "delete1", Semester = Semester.Summer, Year = "2010/2011", Major = Major.Mixed, StudentsInCourse = new List <StudentCourse>() }); context.SaveChanges(); } using (var context = new LMSAppContext(options)) { var repository = new DbRepository <Course>(context); var service = new CourseService(repository); await service.DeleteCourseById(courseId); Assert.True(context.Courses.First().IsDeleted); } }
public async Task DeleteLectureciseByIdReturnsNullIfObjectAlreadyDeleted() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CreateLecturecise_Database3") .Options; BaseServiceTests.Initialize(); string lectureciseId = null; using (var context = new LMSAppContext(options)) { context.Lecturecises.Add(new Lecturecise() { CourseId = "1", Type = LectureciseType.Excercise, IsDeleted = true } ); context.SaveChanges(); lectureciseId = context.Lecturecises.Where(l => l.CourseId == "1").First().Id; } using (var context = new LMSAppContext(options)) { var repository = new DbRepository <Lecturecise>(context); var service = new LectureciseService(repository); var courseId = await service.DeleteLectureciseById(lectureciseId); Assert.Null(courseId); } }
public RoleSeeder( LMSAppContext context, UserManager <LMSAppUser> userManager, RoleManager <IdentityRole> roleManager) { this.context = context; this.userManager = userManager; this.rolesManager = roleManager; }
public DatabaseGroupFixture() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CommonGroup_Database") .Options; this.dbContext = new LMSAppContext(options); InitializeGroups().GetAwaiter().GetResult(); }
public DatabaseCourseFixture() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CommonCourse_Database") .Options; this.dbContext = new LMSAppContext(options); InitializeEducators().GetAwaiter().GetResult(); InitializeLecturecises().GetAwaiter().GetResult(); }
public DatabaseEducatorFixture() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CommonEducator_Database") .Options; this.dbContext = new LMSAppContext(options); InitializeEducators().GetAwaiter().GetResult(); ClearOneEducatorToHaveOneUser(); }
public async Task EditCourseByIdChangesCourseAndStoresChanges() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CreateCourse_Database1") .Options; BaseServiceTests.Initialize(); string courseId = "edit2"; using (var context = new LMSAppContext(options)) { context.Courses.Add(new Course() { Id = courseId, Name = "edit2", Semester = Semester.Summer, Year = "2010/2011", Major = Major.Mixed, StudentsInCourse = new List <StudentCourse>() }); context.SaveChanges(); } var newYear = "2011/2012"; var courseModel = new CourseDetailsViewModel() { Id = courseId, Name = "edit2", Semester = Semester.Summer, Year = newYear, Major = Major.Mixed, StudentsInCourse = new List <StudentCourse>() }; using (var context = new LMSAppContext(options)) { var repository = new DbRepository <Course>(context); var service = new CourseService(repository); await service.EditCourseById(courseModel); Assert.Equal(newYear, context.Courses.First().Year); } }
public async Task EditLectureciseChangesAndStoresChanges() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CreateLecturecise_Database2") .Options; BaseServiceTests.Initialize(); string lectureciseId = null; using (var context = new LMSAppContext(options)) { context.Lecturecises.Add(new Lecturecise() { CourseId = "1", Type = LectureciseType.Excercise } ); context.SaveChanges(); lectureciseId = context.Lecturecises.Where(l => l.CourseId == "1").First().Id; } var newCourseId = "2"; var lectureciseModel = new LectureciseDetailsViewModel() { Id = lectureciseId, CourseId = newCourseId, Type = LectureciseType.Excercise }; using (var context = new LMSAppContext(options)) { var repository = new DbRepository <Lecturecise>(context); var service = new LectureciseService(repository); await service.EditLecturecise(lectureciseModel); Assert.Equal(newCourseId, context.Lecturecises.First().CourseId); } }
public async Task CreateAsyncCreatesEntityWithTheGivenValues() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CreateLecturecise_Database1") .Options; BaseServiceTests.Initialize(); using (var dbContext = new LMSAppContext(options)) { var repository = new DbRepository <Lecturecise>(dbContext); var service = new LectureciseService(repository); await service.CreateAsync(new LectureciseCreateBindingModel() { CourseId = "1", Type = LectureciseType.Excercise } ); Assert.Equal("1", dbContext.Lecturecises.FirstOrDefault().CourseId); Assert.Equal(LectureciseType.Excercise, dbContext.Lecturecises.FirstOrDefault().Type); } }
public async Task DeleteByIdMarksTheWeekTimeInstanceAsDeleted() { var options = new DbContextOptionsBuilder <LMSAppContext>() .UseInMemoryDatabase(databaseName: "CreateWeekTime_Database1") .Options; //BaseServiceTests.Initialize(); int weekTimeId; using (var context = new LMSAppContext(options)) { context.WeekTimes.Add(new WeekTime() { DayOfWeek = DayOfWeek.Friday, StartHour = "14h" } ); context.SaveChanges(); var weekTime = await context.WeekTimes.FirstAsync(); weekTimeId = weekTime.Id; } using (var context = new LMSAppContext(options)) { var repository = new DbRepository <WeekTime>(context); var service = new WeekTimeService(repository); await service.DeleteById(weekTimeId); Assert.True(context.WeekTimes.First().IsDeleted); } }