Exemplo n.º 1
0
        public async Task CanUseConvertersToSerializeQueryParameters()
        {
            using (var store = GetDocumentStore(new Options
            {
                ModifyDocumentStore = documentStore =>
                {
                    documentStore.Conventions.Serialization = new NewtonsoftJsonSerializationConventions
                    {
                        CustomizeJsonSerializer = serializer => serializer.Converters.Add(new NumberJsonConverter())
                    };
                }
            }))
            {
                using (var session = store.OpenAsyncSession())
                {
                    var document1 = new TestDocument {
                        Id = "docs/1", MyNumber = new Number("1")
                    };
                    var document2 = new TestDocument {
                        Id = "docs/2", MyNumber = new Number("2")
                    };
                    await session.StoreAsync(document1);

                    await session.StoreAsync(document2);

                    await session.SaveChangesAsync();
                }

                WaitForIndexing(store);

                using (var session = store.OpenAsyncSession())
                {
                    var documents = await session
                                    .Query <TestDocument>()
                                    .Where(d => d.MyNumber == new Number("1"))
                                    .ToListAsync();

                    Assert.Equal(1, documents.Count);
                }
            }
        }
Exemplo n.º 2
0
        public async Task ShouldWork()
        {
            using (var store = GetDocumentStore())
            {
                var databaseName = store.Database;

                await store.ExecuteIndexAsync(new TestDocumentsIndex(), databaseName);

                using (var session = store.OpenAsyncSession(databaseName))
                {
                    var testDoc1 = new TestDocument {
                        Name = "Name1 (English)", Language = new CultureInfo("en-US")
                    };
                    await session.StoreAsync(testDoc1);

                    var testDoc2 = new TestDocument {
                        Name = "Name2 (French)", Language = new CultureInfo("fr-CA")
                    };
                    await session.StoreAsync(testDoc2);

                    await session.SaveChangesAsync();
                }

                Indexes.WaitForIndexing(store);

                using (var session = store.OpenAsyncSession(databaseName))
                {
                    var english     = new CultureInfo("en-US");
                    var englishDocs = await session.Query <TestDocument, TestDocumentsIndex>()
                                      .Where(x => x.Language.Equals(english)).ToListAsync();

                    Assert.Equal(1, englishDocs.Count);

                    var french     = new CultureInfo("fr-CA");
                    var frenchDocs = await session.Query <TestDocument, TestDocumentsIndex>()
                                     .Where(x => x.Language.Equals(french)).ToListAsync();

                    Assert.Equal(1, frenchDocs.Count);
                }
            }
        }
Exemplo n.º 3
0
        public async Task PagingWithAlphaNumericSorting()
        {
            using (var store = GetDocumentStore())
            {
                int nullNameCount = 4;
                using (var session = store.OpenAsyncSession())
                {
                    new GreatIndex().Execute(store);
                    var document1 = new TestDocument {
                        Document = new TestDocument2()
                        {
                            Name = "EGOR"
                        }, SomeRandomDate = new DateTime(2021, 6, 14)
                    };
                    for (int i = 0; i < nullNameCount; i++)
                    {
                        await session.StoreAsync(document1);

                        var document2 = new TestDocument {
                            Document = new TestDocument2()
                            {
                                Name = null
                            }
                        };
                        await session.StoreAsync(document2);
                    }

                    for (int i = 0; i < 2; i++)
                    {
                        var document3 = new TestDocument {
                            Document = new TestDocument2()
                            {
                                Name = $"{i}_EGOR"
                            }
                        };
                        await session.StoreAsync(document3);
                    }
                    await session.SaveChangesAsync();
                }

                Indexes.WaitForIndexing(store);

                WaitForUserToContinueTheTest(store);
                using (var s = store.OpenAsyncSession())
                {
                    var pageSize = 2;
                    var total    = 0;
                    while (total != nullNameCount - pageSize)
                    {
                        var res = await s.Advanced.AsyncRawQuery <TestResult>($@"from index 'GreatIndex' as u
where u.RandomDate < ""2021-11-31""
order by u.DocsName as alphanumeric
select u.DocsName limit {total}, {pageSize}").ToListAsync();

                        foreach (var p in res)
                        {
                            Assert.Null(p.DocsName);
                        }

                        total += pageSize;
                    }

                    Assert.Equal(nullNameCount - pageSize, total);
                }
            }
        }