private async void CreateCourses(CourseRepository courseRepository, int number, Guid department) { for (var i = 0; i < number; i++) { var courseTitle = StringGenerator.GenerateRandomString(15); var newCourse = new Course { Id = new Guid(), Title = courseTitle, Credits = 3, DepartmentId = department }; await courseRepository.AddAsync(newCourse); } }
public void CreateCourseSucceeds() { var courseRepository = new CourseRepository(_factory); var department = new Guid("D7A8F435-66D9-E911-B7F0-989096C0B27B"); var courseTitle = StringGenerator.GenerateRandomString(15); var newCourse = new Course { Id = new Guid(), Title = courseTitle, Credits = 3, DepartmentId = department }; var savedCourse = courseRepository.AddAsync(newCourse); Assert.Equal(courseTitle, savedCourse.Result.Title); Assert.Equal(3, savedCourse.Result.Credits); Assert.Equal(department, savedCourse.Result.DepartmentId); }
public async Task AddAsync_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "AddTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new CourseRepository(context); var newCourse = new Course { Name = "New", LecturerId = 1 }; var prevCount = repository.GetAll().Count(); await repository.AddAsync(newCourse); await context.SaveChangesAsync(); var courses = repository.GetAll(); Assert.That(courses.Count(), Is.EqualTo(prevCount + 1)); } }