public async Task AssignStudent() { var options = new DbContextOptionsBuilder <ChallengeDbContext>() .UseInMemoryDatabase("AssignStudent") .Options; // Insert seed data into the database using one instance of the context await using (var context = new ChallengeDbContext(options)) { await context.Students.AddAsync(new Student { Id = 1, Name = "Jonas" }); await context.Courses.AddAsync(new Course { Id = 1, Name = "Biology" }); await context.SaveChangesAsync(); } // Use a clean instance of the context to run the test await using (var context = new ChallengeDbContext(options)) { var repository = new AssociationRepository(context); var assign = await new AssociationController().AddStudentToCourse(repository, new StudentCourseAssociation { StudentId = 1, CourseId = 1 }) as OkObjectResult; var association = await context.Attends.FirstAsync(); Assert.NotNull(assign); Assert.NotNull(association); Assert.Equal(1, ((Attend)assign.Value).Id); } }
public async Task UnassignTeacher() { var options = new DbContextOptionsBuilder <ChallengeDbContext>() .UseInMemoryDatabase("UnassignTeacher") .Options; // Insert seed data into the database using one instance of the context await using (var context = new ChallengeDbContext(options)) { await context.Teachers.AddAsync(new Teacher { Id = 1, Name = "Jonas" }); await context.Courses.AddAsync(new Course { Id = 1, Name = "Biology" }); await context.Teaches.AddAsync(new Teach { Id = 1, TeacherId = 1, CourseId = 1 }); await context.SaveChangesAsync(); } // Use a clean instance of the context to run the test await using (var context = new ChallengeDbContext(options)) { var repository = new AssociationRepository(context); var assign = await new AssociationController().RemoveTeacherFromCourse(repository, new TeacherCourseAssociation { TeacherId = 1, CourseId = 1 }) as OkResult; var association = await context.Teaches.FindAsync(1); Assert.NotNull(assign); Assert.Null(association); Assert.Equal(200, assign.StatusCode); } }
public EventServiceImpl(EventRepository eventRepository, ConstituentRepository constituentRepository, ReferenceDataRepository referenceDataRepository) { repository = eventRepository; this.referenceDataRepository = referenceDataRepository; this.constituentRepository = constituentRepository; associationRepository = new AssociationRepository(); phoneRepository = new PhoneRepository(); }
public void SetUp() { testDataHelper = new TestDataHelper(); var constituent = ConstituentMother.ConstituentWithName(ConstituentNameMother.JamesFranklin()); savedConstituent = testDataHelper.CreateConstituent(constituent); constituent = ConstituentMother.ConstituentWithName(ConstituentNameMother.AgnesAlba()); savedAssociatedConstituent = testDataHelper.CreateConstituent(constituent); savedAssociation = testDataHelper.CreateAssociation(AsociationMother.JamesFranklinAndParent(savedConstituent)); associationRepository = new AssociationRepository(testDataHelper.session); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ConfigureContainer(); Current.MainWindow = this.container.Get <LoadingPanel>(); Current.MainWindow.Show(); AssociationRepository repo = new AssociationRepository(container.Get <DataService>()); repo.UpdateDatabaseFromAPI(); Current.MainWindow.Hide(); ComponeObjects(); Current.MainWindow.Show(); }
public AssociationServiceImpl(AssociationRepository repository) { this.repository = repository; }