public async Task CanProject() { var account = CloudStorageAccount.DevelopmentStorageAccount; var repo = TableRepository.Create <Book>(account, $"{nameof(QueryTests)}{nameof(CanProject)}", x => x.Author, x => x.ISBN); // For some reason, this test alone fails due to what looks like a timing issue in finishing creating the table while ((await account.CreateTableServiceClient().GetTableClient(repo.TableName).CreateIfNotExistsAsync()) != null) { await Task.Delay(50); } await LoadBooksAsync(repo); var hasResults = false; await foreach (var info in from book in repo.CreateQuery() where book.Author == "Rick Riordan" && book.Format == BookFormat.Hardback && book.IsPublished select new { book.ISBN, book.Title }) { hasResults = true; Assert.NotNull(info.ISBN); Assert.NotNull(info.Title); } Assert.True(hasResults); }
public async Task CanGetAll() { var account = CloudStorageAccount.DevelopmentStorageAccount; var repo = TableRepository.Create <Book>(account, nameof(CanGetAll), x => x.Author, x => x.ISBN); await LoadBooksAsync(repo); var result = await repo.CreateQuery().AsAsyncEnumerable().ToListAsync(); var all = await repo.EnumerateAsync().ToListAsync(); Assert.Equal(all.Count, result.Count); }
public async Task CanTake() { var account = CloudStorageAccount.DevelopmentStorageAccount; var repo = TableRepository.Create <Book>(account, nameof(CanTake), x => "Book", x => x.ISBN); await LoadBooksAsync(repo); var query = from book in repo.CreateQuery() where book.Format == BookFormat.Hardback && book.IsPublished select new { book.ISBN, book.Title }; var result = await query.Take(2).AsAsyncEnumerable().ToListAsync(); Assert.Equal(2, result.Count); }
public async Task CanFilterByColumn() { var account = CloudStorageAccount.DevelopmentStorageAccount; await LoadBooksAsync(TableRepository.Create <Book>(account, nameof(CanFilterByColumn), x => x.Author, x => x.ISBN)); var repo = TablePartition.Create <Book>(account, nameof(CanFilterByRowKey), "Rick Riordan", x => x.ISBN); // Get specific set of books from one particular publisher/country combination // in this case, 978-[English-speaking country, 1][Disney Editions, 4231] // See https://en.wikipedia.org/wiki/List_of_group-1_ISBN_publisher_codes var query = from book in repo.CreateQuery() where book.Pages >= 1000 && book.Pages <= 1500 select new { book.ISBN, book.Title }; var result = await query.AsAsyncEnumerable().ToListAsync(); Assert.Single(result); }
public async Task RunAsync() { var repo = TableRepository.Create <Product>( CloudStorageAccount.DevelopmentStorageAccount, tableName: "Products", partitionKey: p => p.Category, rowKey: p => p.Id); await repo.PutAsync(new Product("book", "9781473217386") { Title = "Neuromancer", Price = 7.32 }); var docs = DocumentRepository.Create <Product>( CloudStorageAccount.DevelopmentStorageAccount, tableName: "Documents", partitionKey: p => p.Category, rowKey: p => p.Id); await docs.PutAsync(new Product("book", "9781473217386") { Title = "Neuromancer", Price = 7.32 }); var bin = DocumentRepository.Create <Product>( CloudStorageAccount.DevelopmentStorageAccount, tableName: "Documents", partitionKey: p => p.Category, rowKey: p => p.Id, serializer: BsonDocumentSerializer.Default); await docs.PutAsync(new Product("book", "9781473217386") { Title = "Neuromancer", Price = 7.32 }); }
public async Task BooksAsync() { var storageAccount = CloudStorageAccount.DevelopmentStorageAccount; // We lay out the parameter names for clarity only. var repo = TableRepository.Create <Book>(storageAccount, tableName: "Books", partitionKey: p => p.Author, rowKey: p => p.ISBN); //await LoadBooksAsync(repo); // Create a new Book and save it await repo.PutAsync( new Book("9781473217386", "Neuromancer", "William Gibson", BookFormat.Paperback, 320)); await foreach (var book in from b in repo.CreateQuery() where b.Author == "William Gibson" && b.Format == BookFormat.Paperback select new { b.Title }) { Console.WriteLine(book.Title); } }
public async Task CanProjectPartition() { var account = CloudStorageAccount.DevelopmentStorageAccount; // Load with author + isbn as keys await LoadBooksAsync(TableRepository.Create <Book>(account, nameof(CanProjectPartition), x => x.Author, x => x.ISBN)); // Query single author by scoping to partition key var repo = TablePartition.Create <Book>(account, nameof(CanProjectPartition), "Rick Riordan", x => x.ISBN); var hasResults = false; await foreach (var info in from book in repo.CreateQuery() where book.Format == BookFormat.Hardback && book.IsPublished select new { book.ISBN, book.Title }) { hasResults = true; Assert.NotNull(info.ISBN); Assert.NotNull(info.Title); } Assert.True(hasResults); }