Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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
            });
        }
Exemple #3
0
        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);
        }