public async Task Should_Do_Crud_On_Simple_Model_Object(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // Create var expectedAuthor = AuthorFixture.GetFirstAuthor(); await db.Create(expectedAuthor); // Assert Create var actualAuthor = await db.Query <AuthorModel>().Where(a => a.Email == expectedAuthor.Email).SingleOrDefaultAsync(); actualAuthor.Should().NotBeNull(); actualAuthor.Should().BeEquivalentTo(expectedAuthor); // Update expectedAuthor.FirstName = "Bob"; expectedAuthor.LastName = "Jones"; await db.Update(expectedAuthor); // Assert Update actualAuthor = await db.Query <AuthorModel>().Where(a => a.Email == expectedAuthor.Email).SingleOrDefaultAsync(); actualAuthor.Should().NotBeNull(); actualAuthor.Should().BeEquivalentTo(expectedAuthor); // Delete await db.Delete <AuthorModel>(x => x.Id == expectedAuthor.Id); // Assert Delete actualAuthor = await db.Query <AuthorModel>().Where(a => a.Email == expectedAuthor.Email).SingleOrDefaultAsync(); actualAuthor.Should().BeNull(); }
public async Task ShouldCreateBookWithReferenceToItsAuthor(IDbProvider db) { var book = BookFixture.GetFirstBook(); var id = new Guid("F6949DAD-810D-4724-A391-5C01DD9D66E8"); book.Id = id; book.ISBN = 1919; // Execute await db.Create(book); var actualBook = await db.Query <BookModel>().Where(b => b.Id == id).FirstOrDefaultAsync(); Assert.That(actualBook, Is.Not.Null); Assert.That(actualBook.Id, Is.EqualTo(id)); Assert.That(actualBook.Authors.First().Id, Is.EqualTo(AuthorFixture.GetFirstAuthor().Id)); }
public async Task Should_Create_Records_With_ManyToMany_Relationships(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // Setup var publisher = PublisherFixture.GetFirstPublisher(); await db.Create(publisher); var firstBook = BookFixture.GetFirstBook(publisher); var secondBook = BookFixture.GetSecondBook(publisher); await db.Create(firstBook); await db.Create(secondBook); var expectedAuthor = AuthorFixture.GetFirstAuthor(); expectedAuthor.AddBooks(firstBook, secondBook); // Execute await db.Create(expectedAuthor); // Assert var actualAuthor = await db.Query <AuthorModel>() .Where(a => a.Email == expectedAuthor.Email) .SingleAsync(); actualAuthor.Should().NotBeNull(); var moreBooks = await db.Query <BookModel>() .ManyToManyJoin <AuthorModel>() .Where((b, a) => a.Id == actualAuthor.Id) .Select(); actualAuthor.AddBooks(moreBooks.ToArray()); // Excluding publisher info because only its ID is included in the hydration. actualAuthor.Should().BeEquivalentTo(expectedAuthor, options => options.Excluding(a => a.SelectedMemberPath.Contains("Publisher"))); }
public void Should_Create_Records_With_ManyToMany_Relationships_Using_Transactions(IDbProvider db) { Trace.WriteLine(TraceObjectGraphInfo(db)); // Setup var publisher = PublisherFixture.GetFirstPublisher(); var firstBook = BookFixture.GetFirstBook(publisher); var secondBook = BookFixture.GetSecondBook(publisher); var expectedAuthor = AuthorFixture.GetFirstAuthor(); expectedAuthor.AddBooks(firstBook, secondBook); db.RunInTransaction(trans => { trans.Create(publisher); trans.Create(firstBook); trans.Create(secondBook); trans.Create(expectedAuthor); }); // Assert var actualAuthor = db.Query <AuthorModel>() .Where(a => a.Email == expectedAuthor.Email) .Select() .Single(); actualAuthor.Should().NotBeNull(); actualAuthor.AddBooks(db.Query <BookModel>() .ManyToManyJoin <AuthorModel>() .Where((b, a) => a.Id == actualAuthor.Id) .Select().ToArray()); // Excluding publisher info because only its ID is included in the hydration. actualAuthor.ShouldBeEquivalentTo(expectedAuthor, options => options.Excluding(a => a.PropertyPath.Contains("Publisher"))); }