public async Task UpdateAuthorName() { insertedAuthor = context.GetCollection <Author>().AsQueryable().ToList().Find(a => a.authorFullName == authorName); bookRepo = serviceProvider.GetService <IRepository <Book, string> >(); await bookRepo.InsertNewAsync(Book.Create("Test Book", "Test description", (AuthorId)insertedAuthor.Id, authorName)); Policy .Handle <TestException>() .WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))) .Execute(() => { insertedAuthor = context.GetCollection <Author>().AsQueryable().ToList().Find(a => a.authorFullName == authorName); if (!insertedAuthor.Books.Any(a => a.Title == new BookTitle("Test Book"))) { throw new TestException(); } }); var updatedName = new AuthorFullName("Test", "Author 2"); await authorRepo.ModifyAsync (author => author.UpdateAuthorFullName(updatedName), insertedAuthor.Id); insertedAuthor = context.GetCollection <Author>().AsQueryable().ToList().Find(a => a.authorFullName == updatedName); Assert.IsTrue(insertedAuthor.Books.Any(a => a.Title == new BookTitle("Test Book"))); var foundBook = context.GetCollection <Book>().AsQueryable().ToList().Find(a => a.Title == new BookTitle("Test Book")); Assert.AreEqual(foundBook.AuthorName, updatedName); }
public async Task <List <BookId> > GetBookIdsByAuthorFullNameAsync(AuthorFullName oldName) { var query = allBooksQuery; query.Filter = (a => a.AuthorName == oldName); var books = await query.GetResultsAsync(); return(books.Select(a => (BookId)a.Id).ToList()); }
public void Setup() { settings = new MongoDbSettings(MongoDefaultSettings.ConnectionString, "AuthorTests"); serviceProvider = new ServiceCollection() .AddLogging() .AddMongoDbInfrastructure(settings) .BuildServiceProvider(); authorRepo = serviceProvider.GetService <IRepository <Author, string> >(); authorName = new AuthorFullName("Test", "Author"); authorRepo.InsertNewAsync(Author.Create(authorName)).GetAwaiter().GetResult(); context = serviceProvider.GetService <IMongoDbContext>(); }