public async Task AddRangeAsync_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "AddTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var newLecturers = new List <Lecturer> { new Lecturer { Name = "Test" }, new Lecturer { Name = "Test" } }; var prevCount = repository.GetAll().Count(); await repository.AddRangeAsync(newLecturers); await context.SaveChangesAsync(); var lecturers = repository.GetAll(); Assert.That(lecturers.Count(), Is.EqualTo(prevCount + 2)); } }
public LmPlatformRepositoriesContainer() { UsersRepository = new UsersRepository(_dataContext); BugsRepository = new BugsRepository(_dataContext); BugLogsRepository = new BugLogsRepository(_dataContext); GroupsRepository = new GroupsRepository(_dataContext); ProjectsRepository = new ProjectsRepository(_dataContext); ProjectUsersRepository = new ProjectUsersRepository(_dataContext); ProjectCommentsRepository = new ProjectCommentsRepository(_dataContext); StudentsRepository = new StudentsRepository(_dataContext); SubjectRepository = new SubjectRepository(_dataContext); TestsRepository = new TestsRepository(_dataContext); TestUnlocksRepository = new TestUnlockRepository(_dataContext); QuestionsRepository = new QuestionsRepository(_dataContext); UsersRepository = new UsersRepository(_dataContext); ModulesRepository = new ModulesRepository(_dataContext); LecturerRepository = new LecturerRepository(_dataContext); MessageRepository = new MessageRepository(_dataContext); MaterialsRepository = new MaterialsRepository(_dataContext); FoldersRepository = new FoldersRepository(_dataContext); SubGroupRepository = new SubGroupRepository(_dataContext); AttachmentRepository = new AttachmentRepository(_dataContext); LecturesRepository = new LecturesRepository(_dataContext); LabsRepository = new LabsRepository(_dataContext); ProjectUsersRepository = new ProjectUsersRepository(_dataContext); PracticalRepository = new PracticalRepository(_dataContext); ConceptRepository = new ConceptRepository(_dataContext); WatchingTimeRepository = new WatchingTimeRepository(_dataContext); TestQuestionPassResultsRepository = new TestQuestionPassResultsRepository(_dataContext); //todo UNUSED ProjectMatrixRequirementsRepository = new ProjectMatrixRequirementsRepository(_dataContext); }
public void CreateCourse_EntityAlreadyExistException_Test() { // Arrange var testCreate = new List <Course>(_testCourses); testCreate.ElementAt(0).LecturerId = 1; var course = testCreate.ElementAt(0); var lecturers = new List <Lecturer> { new Lecturer { Id = 1, Name = "Test" } }; Repository.Setup(x => x.AddAsync(It.IsAny <Course>())) .Callback((Course course) => testCreate.Add(course)); LecturerRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => lecturers.Find(l => l.Id == id)); Repository.Setup(x => x.Contains(It.IsAny <Course>())) .ReturnsAsync((Course course) => testCreate.Contains(course)); // Assert Assert.ThrowsAsync <EntityAlreadyExistException>(async() => await Service.CreateCourse(course)); }
public void CreateCourse_LecturerEntityNotFoundException_Test() { // Arrange var testCreate = new List <Course>(_testCourses); var course = new Course { Id = 3, Name = "test", LecturerId = 5 }; var lecturers = new List <Lecturer> { new Lecturer { Id = 1, Name = "Test" } }; Repository.Setup(x => x.AddAsync(It.IsAny <Course>())) .Callback((Course course) => testCreate.Add(course)); LecturerRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => lecturers.Find(l => l.Id == id)); // Assert Assert.ThrowsAsync <EntityNotFoundException>(async() => await Service.CreateCourse(course)); }
public void CreateCourse_NormalConditions_Test() { // Arrange var testCreate = new List <Course>(_testCourses); var course = new Course { Id = 3, Name = "test", LecturerId = 1 }; var lecturers = new List <Lecturer> { new Lecturer { Id = 1, Name = "Test" } }; Repository.Setup(x => x.AddAsync(It.IsAny <Course>())) .Callback((Course course) => testCreate.Add(course)); LecturerRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => lecturers.Find(l => l.Id == id)); // Act Service.CreateCourse(course); // Assert Repository.Verify(x => x.AddAsync(It.IsAny <Course>()), Times.Once); Assert.That(3, Is.EqualTo(testCreate.Count())); }
public void SetUp() { _transactionScope = new TransactionScope(); _lecturerRepository = new LecturerRepository(); _cathedraRepository = new CathedraRepository(); _facultyRepository = new FacultyRepository(); _personRepository = new PersonRepository(); _faculty = new FacultyItem() { FullName = "Информационный", ShortName = "И", }; _cathedra = new CathedraItem() { FullName = "Информациионных систем и технологий", ShortName = "ИСиТ", FacultyId = _facultyRepository.Create(_faculty) }; _person = new PersonItem() { Birthday = DateTime.Now.AddDays(2).Date, FatherName = "Сидорович", FirstName = "Сидор", LastName = "Сидоров", }; _lecturer = new LecturerItem() { CathedraId = _cathedraRepository.Create(_cathedra), Birthday = _person.Birthday, FatherName = _person.FatherName, FirstName = _person.FirstName, Id = _personRepository.Create(_person), LastName = _person.LastName, }; _personNew = new PersonItem() { Birthday = DateTime.Now.AddDays(3).Date, FatherName = "Петрович", FirstName = "Петр", LastName = "Петров", }; _lecturerNew = new LecturerItem() { CathedraId = _cathedraRepository.Create(_cathedra), Birthday = _personNew.Birthday, FatherName = _personNew.FatherName, FirstName = _personNew.FirstName, Id = _personRepository.Create(_person), LastName = _personNew.LastName }; }
public void GetByIdAsyncTest_ThrowsDataException() { // Arrange var loggerMock = new Mock <ILogger <LecturerRepository> >(); var repository = new LecturerRepository(_contextFactory, loggerMock.Object); // Act _contextFactory.SimulateSqlException = true; async Task TestAction() => await repository.DeleteAsync(new Lecturer { Id = 1 }); // Assert Assert.ThrowsAsync <DataException>(TestAction); }
public async Task Get_All_Lecturers_Test() { LecturerRepository repository = new LecturerRepository(context, logger); var list = await repository.GetAllAsync(); foreach (var lecturer in list) { output.WriteLine("Lecturer: {0}", lecturer.Name); } Assert.True(list.Count() > 0); }
public void GetAll_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "GetTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var lecturers = repository.GetAll(); Assert.That(lecturers.Count(), Is.EqualTo(context.Lecturers.Count())); } }
public void Where_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "FindTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var where = repository.Where(c => c.Id == 1); Assert.That(where.Count(), Is.EqualTo(1)); } }
public async Task Create_Lecturer_Test() { LecturerRepository repository = new LecturerRepository(context, logger); var lecturer = new Lecturer { Name = "Jocelin Malachi Paige" }; var persisted = await repository.CreateAsync(lecturer); Assert.True(persisted); Assert.True(lecturer.Id != null); }
public async Task GetByIdAsync_Test(int id) { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "GetTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var lecturer = await repository.GetByIdAsync(id); Assert.That(lecturer.Id, Is.EqualTo(id)); } }
public async Task SingleOrDefault_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "FindTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var single = await repository.SingleOrDefaultAsync(c => c.Id == 1); Assert.That(single.Id, Is.EqualTo(1)); } }
public async Task Contains_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "FindTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var newLecturer = new Lecturer { Name = "TESTSTSTST" }; var contains = await repository.Contains(newLecturer); Assert.That(contains, Is.EqualTo(false)); } }
public async Task GetByIdAsyncTest(IEnumerable <Lecturer> data, int id, Lecturer?expected) { // Arrange await using (ApplicationContext context = _contextFactory.CreateDbContext()) { await context.Lecturers.AddRangeAsync(data); await context.SaveChangesAsync(); } var loggerMock = new Mock <ILogger <LecturerRepository> >(); var repository = new LecturerRepository(_contextFactory, loggerMock.Object); // Act Lecturer?lecturer = await repository.GetByIdAsync(id); // Assert Assert.That(lecturer, Is.EqualTo(expected)); }
public async Task RemoveRange_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "RemoveTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var removeLecturers = new List <Lecturer>(); removeLecturers.AddRange(repository.GetAll().ToList()); repository.RemoveRange(removeLecturers); await context.SaveChangesAsync(); var lecturers = repository.GetAll(); Assert.That(lecturers.Count(), Is.EqualTo(0)); } }
public void UpdateCourse_NormalConditions_Test() { // Arrange var testUpdate = new List <Course> { new Course { Id = 1, Name = "test", LecturerId = 1 } }; var lecturersCollection = new List <Lecturer> { new Lecturer { Id = 1, Name = "Test" } }; Repository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => testUpdate.Find(c => c.Id == id)); LecturerRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => lecturersCollection.Find(c => c.Id == id)); Repository.Setup(x => x.Update(It.IsAny <Course>())) .Callback((Course course) => testUpdate[testUpdate.FindIndex(x => x.Id == course.Id)] = course); var updateCourse = new Course { Id = 1, Name = "update", LecturerId = 1 }; // Act Service.UpdateCourse(updateCourse); // Assert Repository.Verify(x => x.Update(It.IsAny <Course>()), Times.Once); Assert.That("update", Is.EqualTo(testUpdate.ElementAt(0).Name)); }
public void UpdateCourse_EntityNotFoundException_Test() { // Arrange var testUpdate = new List <Course> { new Course { Id = 1, Name = "test", LecturerId = 1 } }; var lecturersCollection = new List <Lecturer> { new Lecturer { Id = 1, Name = "Test" } }; Repository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => testUpdate.Find(c => c.Id == id)); LecturerRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => lecturersCollection.Find(c => c.Id == id)); Repository.Setup(x => x.Update(It.IsAny <Course>())) .Callback((Course course) => testUpdate[testUpdate.FindIndex(x => x.Id == course.Id)] = course); var updateCourse = new Course { Id = 10, Name = "update", LecturerId = 1 }; // Assert var course = new Course { Id = 10, Name = "Test" }; Assert.ThrowsAsync <EntityNotFoundException>(async() => await Service.UpdateCourse(course)); }
public async Task Update_Test() { var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "UpdateTestDatabase") .Options; using (var context = new ApplicationContext(options)) { context.Database.EnsureCreated(); var repository = new LecturerRepository(context); var updateLecturer = await repository.GetByIdAsync(1); updateLecturer.Name = "Update"; repository.Update(updateLecturer); var result = await repository.GetByIdAsync(1); await context.SaveChangesAsync(); Assert.That(result.Name, Is.EqualTo("Update")); } }
static void Main(string[] args) { INewsRepository newsRep = new NewsRepository(); //List<NewsModel> news = newsRep.GetAllNews().ToList(); //foreach (NewsModel n in news) //{ // Console.WriteLine(n.Id + " " + n.Content + " " + n.DocName); //} ////for (int i = 1; i < 9; i++) ////{ //// NewsModel another = new NewsModel(); //// another.Content = i.ToString(); //// newsRep.AddNews(another); ////} //news = newsRep.GetLastTenNews().ToList(); //foreach (NewsModel n in news) //{ // Console.WriteLine(n.Id + " " + n.Content + " " + n.DocName); //} //newsRep.DeleteNews(10); IUserRepository usRep = new UserRepository(); IStudentRepository stRep = new StudentRepository(); //UserModel user = new UserModel(); //user.BirthDate = "12.12.2000"; //user.Email = "sdsdvsd"; //user.FIO = "AA sAS ASA"; //user.Password = "******"; //user.Sex = "male"; //usRep.AddUser(user); //List<UserModel> users = usRep.GetAllUsers().ToList(); //foreach (UserModel n in users) //{ // Console.WriteLine(n.Id + " " + n.FIO + " " + n.Password); //} //usRep.ChangeStatus("student", 1); //StudentModel stud = new StudentModel(); //stud.Course = 2; //stud.Status = "2nd curse of mag, good dude "; //stud.UserId = 1; //stRep.AddStudent(stud); //List<StudentModel> students = stRep.GetAllStudents().ToList(); //foreach (StudentModel n in students) //{ // Console.WriteLine(n.Id + " " + n.Status + " " + n.Course); //} ILecturerRepository lecRep = new LecturerRepository(); IWallMessageRepository wallRep = new WallMessageRepository(); ITeachingWRepository teachRep = new TeachingWRepository(); //UserModel user = new UserModel(); //user.BirthDate = "10.02.1990"; //user.Email = "qwdqwdq"; //user.FIO = "aa SS AA"; //user.Password = "******"; //user.Sex = "female"; //usRep.AddUser(user); //usRep.ChangeStatus("lecturer", 2); //LecturerModel lect = new LecturerModel(); //lect.Achivements = "asasas"; //lect.Publications = "asasa"; //lect.TeachingInfo = "aaaaaa"; //lect.UserId = 2; //lecRep.AddLecturer(lect); //lecRep.UpdateLecturerAchivements("LOL", 1); //for (int i = 0; i<8;i++) //{ // WallMessageModel msg = new WallMessageModel(); // msg.Content = "Blalalal" + i.ToString(); // msg.LecturerId = 1; // wallRep.AddPost(msg); //} //List<WallMessageModel> msgs = wallRep.GetAllPosts(1).ToList(); //foreach (WallMessageModel n in msgs) //{ // Console.WriteLine(n.Id + " " + n.Content + " " + n.LecturerId); //} }
public void InitialSetup() { Repository = new LecturerRepository(); CleanUp(); }