protected override void Process(UserBroker payload) { //TODO: get database url from application configs. var databaseUrl = "Server=127.0.0.1;Port=5432;User ID=postgres;Password=admin;Database=YouCourse.Library"; var useCase = new UpdateAuthorUseCase(payload.ToDomain(), NHibernateUnitOfWork.Create(databaseUrl)); useCase.Execute(); }
public void Valid_author_crud() { var appsettings = Config.InitConfiguration(); var unitOfWork = NHibernateUnitOfWork.Create(appsettings.GetSection("Database")["ConnectionSrtring"]); unitOfWork.BeginUnit(); var authors = unitOfWork.GetAuthorRepository(); var id = Guid.NewGuid(); var author = Author.Create(id, "Marcos Harbs", "http://marcos.com/image.jpeg"); authors.AddOrUpdate(author); var authorDb = authors.GetById(id); authorDb.Id.Should().Be(author.Id); unitOfWork.CommitUnit(); unitOfWork.BeginUnit(); authors = unitOfWork.GetAuthorRepository(); author = Author.Create(id, "Marcos Harbs Updated", "http://marcos.com/image.jpeg"); authors.AddOrUpdate(author); authorDb = authors.GetById(id); authorDb.Id.Should().Be(author.Id); authorDb.AuthorName.Name.Should().Be(author.AuthorName.Name); var authorsCount = authors.Count(); authorsCount.Should().Be(1); var allAuthors = authors.GetAll(); var partialAuthors = authors.GetPartial(0, 20); allAuthors.Count.Should().Be(1); partialAuthors.Count.Should().Be(1); allAuthors.ToList()[0].Should().Be(authorDb); partialAuthors.ToList()[0].Should().Be(authorDb); unitOfWork.CommitUnit(); unitOfWork.BeginUnit(); authors = unitOfWork.GetAuthorRepository(); authors.Remove(authorDb); unitOfWork.CommitUnit(); }
public void Valid_course_crud() { var appsettings = Config.InitConfiguration(); var unitOfWork = NHibernateUnitOfWork.Create(appsettings.GetSection("Database")["ConnectionSrtring"]); var authorId = Guid.NewGuid(); var courseId = Guid.NewGuid(); unitOfWork.BeginUnit(); var authors = unitOfWork.GetAuthorRepository(); var courses = unitOfWork.GetCourseRepository(); var author = Author.Create(authorId, "Marcos Harbs", ""); var course = Course.Create(courseId, "Curso de JS", "Curso básico de desenvolvimento javascript", author); var video1 = Video.Create("Video 1", "http://youtube.com/video1"); var video2 = Video.Create("Video 2", "http://youtube.com/video2"); course.AddVideo(video1); course.AddVideo(video2); authors.AddOrUpdate(author); courses.AddOrUpdate(course); var courseDb = courses.GetById(courseId); courseDb.Id.Should().Be(course.Id); courseDb.Videos.Count().Should().Be(course.Videos.Count()); unitOfWork.CommitUnit(); unitOfWork.BeginUnit(); authors = unitOfWork.GetAuthorRepository(); courses = unitOfWork.GetCourseRepository(); course = courses.GetById(courseId); course.RemoveVideos(); course.AddVideo(Video.Create("Video 3", "http://youtube.com/video1")); courses.AddOrUpdate(course); courseDb = courses.GetById(courseId); courseDb.Id.Should().Be(course.Id); courseDb.CourseName.Should().Be(course.CourseName); courseDb.Videos.Count().Should().Be(course.Videos.Count()); var coursesCount = courses.Count(); coursesCount.Should().Be(1); var allCourses = courses.GetAll(); var partialCourses = courses.GetPartial(0, 20); allCourses.Count.Should().Be(1); partialCourses.Count.Should().Be(1); allCourses.ToList()[0].Should().Be(courseDb); partialCourses.ToList()[0].Should().Be(courseDb); unitOfWork.CommitUnit(); unitOfWork.BeginUnit(); authors = unitOfWork.GetAuthorRepository(); courses = unitOfWork.GetCourseRepository(); courses.Remove(courseDb); authors.Remove(author); unitOfWork.CommitUnit(); }