public async Task DocumentEndToEnd(IDocumentSerializer serializer) { var table = CloudStorageAccount.DevelopmentStorageAccount .CreateTableServiceClient() .GetTableClient(serializer.GetType().Name); await table.DeleteAsync(); await table.CreateAsync(); try { var repo = DocumentRepository.Create <DocumentEntity>(CloudStorageAccount.DevelopmentStorageAccount, table.Name, serializer: serializer); var partitionKey = "P" + Guid.NewGuid().ToString("N"); var rowKey = "R" + Guid.NewGuid().ToString("N"); var entity = await repo.PutAsync(new DocumentEntity { PartitionKey = partitionKey, RowKey = rowKey, Title = "Foo", }); entity.Title = "Bar"; await repo.PutAsync(entity); var saved = await repo.GetAsync(partitionKey, rowKey); Assert.NotNull(saved); Assert.Equal("Bar", saved !.Title); Assert.Equal(DateOnly.FromDateTime(DateTime.Today), saved.Date); var entities = new List <DocumentEntity>(); await foreach (var e in repo.EnumerateAsync(partitionKey)) { entities.Add(e); } Assert.Single(entities); await repo.DeleteAsync(saved); Assert.Null(await repo.GetAsync(partitionKey, rowKey)); await foreach (var _ in repo.EnumerateAsync(partitionKey)) { Assert.False(true, "Did not expect to find any entities"); } } finally { await table.DeleteAsync(); } }
public async Task CanQueryDocument(IDocumentSerializer serializer) { var table = CloudStorageAccount.DevelopmentStorageAccount .CreateTableServiceClient() .GetTableClient(nameof(CanQueryDocument) + serializer.GetType().Name); await table.DeleteAsync(); await table.CreateAsync(); try { var repo = DocumentRepository.Create <DocumentEntity>(CloudStorageAccount.DevelopmentStorageAccount, table.Name, serializer: serializer); var partitionKey = "P5943C610208D4008BEC052272ED07214"; await repo.PutAsync(new DocumentEntity { PartitionKey = partitionKey, RowKey = "Bar", Title = "Bar", }); await repo.PutAsync(new DocumentEntity { PartitionKey = partitionKey, RowKey = "Foo", Title = "Foo", }); var typeName = typeof(DocumentEntity).FullName !.Replace('+', '.'); var entities = await repo.EnumerateAsync(e => e.PartitionKey == partitionKey && e.RowKey.CompareTo("Foo") >= 0 && e.RowKey.CompareTo("Fop") < 0 && e.Version != "1.0" && e.Type == typeName) .ToListAsync(); Assert.Single(entities); } finally { await table.DeleteAsync(); } }
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 CanFilterDocuments() { var account = CloudStorageAccount.DevelopmentStorageAccount; await LoadBooksAsync(DocumentRepository.Create <Book>( account, nameof(CanFilterDocuments), x => x.Author, x => x.ISBN)); var repo = DocumentPartition.Create <Book>(account, nameof(CanFilterDocuments), "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.ISBN.CompareTo("97814231") >= 0 && // book.ISBN.CompareTo("97814232") < 0 // select new { book.ISBN, book.Title }; //var result = await query.AsAsyncEnumerable().ToListAsync(); //Assert.Equal(4, result.Count); }