コード例 #1
0
        public static void Scroll_Should_Return_Document_With_ScrollId()
        {
            // arrage
            var options = ElasticClientMock.GetOptions();
            var query   = new ElasticsearchQuery <Person>(options);
            var person  = new Person {
                Id = "1", Name = "Thiago Barradas", Age = 27, CreateDate = new DateTime(2019, 01, 01)
            };
            var scrollOptions = new ScrollOptions {
                Scroll = "10m", ScrollId = "1234567", Size = 1
            };
            var queryToFilter = Query <Person> .Match(i => i.Field("name").Query("Thiago Barradas"));

            query.ElasticClient = ElasticClientMock.GetElasticClientMock(options, null, person, "1234567");

            // act
            var result = query.Scroll(queryToFilter, scrollOptions);

            // assert
            Assert.NotNull(result);
            Assert.Single(result.Items);
            Assert.Equal(1, result.Total);
            Assert.Equal("1234567", result.ScrollId);
            Assert.Equal("1", result.Items.First().Id);
            Assert.Equal("Thiago Barradas", result.Items.First().Name);
            Assert.Equal("Scroll", ElasticClientMock.LastElasticClientAction);
            Assert.Equal("{\"scroll\":\"10m\",\"scroll_id\":\"1234567\"}", ElasticClientMock.LastQueryBody);
        }
コード例 #2
0
        public static void Search_Should_Return_Document()
        {
            // arrage
            var options = ElasticClientMock.GetOptions();
            var query   = new ElasticsearchQuery <Person>(options);
            var person  = new Person {
                Id = "1", Name = "Thiago Barradas", Age = 27, CreateDate = new DateTime(2019, 01, 01)
            };
            var searchOptions = new SearchOptions {
                Page = 1, Size = 1
            };
            var queryToFilter = Query <Person> .Match(i => i.Field("name").Query("Thiago Barradas"));

            query.ElasticClient = ElasticClientMock.GetElasticClientMock(options, null, person, null);

            // act
            var result = query.Search(queryToFilter, searchOptions);

            // assert
            Assert.NotNull(result);
            Assert.Single(result.Items);
            Assert.Equal(1, result.Total);
            Assert.Equal("1", result.Items.First().Id);
            Assert.Equal("Thiago Barradas", result.Items.First().Name);
            Assert.Equal("Search", ElasticClientMock.LastElasticClientAction);
            Assert.Equal("{\"from\":0,\"query\":{\"match\":{\"name\":{\"query\":\"Thiago Barradas\"}}},\"size\":1}", ElasticClientMock.LastQueryBody);
        }
コード例 #3
0
        public static void Bulk_Should_Index_In_Default_Index_With_Period()
        {
            // arrage
            var options = ElasticClientMock.GetOptions();
            var command = new ElasticsearchCommand <Person>(options, Person.GenerateIndexName);

            command.ElasticClient = ElasticClientMock.GetElasticClientMock(options, Person.GenerateIndexName, null, null);

            var persons = new List <Person>
            {
                { new Person {
                      Id = "1", Name = "Thiago Barradas", Age = 27, CreateDate = new DateTime(2019, 01, 01)
                  } },
                { new Person {
                      Id = "2", Name = "Raphael Barradas", Age = 29, CreateDate = new DateTime(2018, 12, 01)
                  } }
            };

            // act
            var result = command.Bulk(persons);

            // assert
            Assert.True(result.IsValid);
            Assert.Equal("Bulk", ElasticClientMock.LastElasticClientAction);
            Assert.Equal(options.DefaultIndexName + "-2019-01", ElasticClientMock.LastProcessedIndexes[0]);
            Assert.Equal(options.DefaultIndexName + "-2018-12", ElasticClientMock.LastProcessedIndexes[1]);
            Assert.Equal(persons[0].Id, ElasticClientMock.LastProcessedPersons[0].Id);
            Assert.Equal(persons[0].Name, ElasticClientMock.LastProcessedPersons[0].Name);
            Assert.Equal(persons[1].Id, ElasticClientMock.LastProcessedPersons[1].Id);
            Assert.Equal(persons[1].Name, ElasticClientMock.LastProcessedPersons[1].Name);
        }
コード例 #4
0
        public static void Get_Should_Return_Zero_Documents()
        {
            // arrage
            var options = ElasticClientMock.GetOptions();
            var query   = new ElasticsearchQuery <Person>(options);

            query.ElasticClient = ElasticClientMock.GetElasticClientMock(options, null, null, null);

            // act
            var result = query.Get("some-id");

            // assert
            Assert.Null(result);
            Assert.Equal("Get", ElasticClientMock.LastElasticClientAction);
        }
コード例 #5
0
        public static void Get_Should_Return_Document()
        {
            // arrage
            var options = ElasticClientMock.GetOptions();
            var query   = new ElasticsearchQuery <Person>(options);
            var person  = new Person {
                Id = "1", Name = "Thiago Barradas", Age = 27, CreateDate = new DateTime(2019, 01, 01)
            };

            query.ElasticClient = ElasticClientMock.GetElasticClientMock(options, null, person, null);

            // act
            var result = query.Get("some-id");

            // assert
            Assert.NotNull(result);
            Assert.Equal("1", result.Id);
            Assert.Equal("Thiago Barradas", result.Name);
            Assert.Equal("Get", ElasticClientMock.LastElasticClientAction);
        }
コード例 #6
0
        public static void Search_Should_Return_Zero_Document()
        {
            // arrage
            var options       = ElasticClientMock.GetOptions();
            var query         = new ElasticsearchQuery <Person>(options);
            var searchOptions = new SearchOptions {
                Page = 1, Size = 1
            };
            var queryToFilter = Query <Person> .Match(i => i.Field("name").Query("Ralph Barradas"));

            query.ElasticClient = ElasticClientMock.GetElasticClientMock(options, null, null, null);

            // act
            var result = query.Search(queryToFilter, searchOptions);

            // assert
            Assert.NotNull(result);
            Assert.Empty(result.Items);
            Assert.Equal(0, result.Total);
            Assert.Equal("{\"from\":0,\"query\":{\"match\":{\"name\":{\"query\":\"Ralph Barradas\"}}},\"size\":1}", ElasticClientMock.LastQueryBody);
        }
コード例 #7
0
        public static void Upsert_Should_Index_In_Default_Index_With_Period()
        {
            // arrage
            var options = ElasticClientMock.GetOptions();
            var command = new ElasticsearchCommand <Person>(options, Person.GenerateIndexName);

            command.ElasticClient = ElasticClientMock.GetElasticClientMock(options, Person.GenerateIndexName, null, null);
            var person = new Person {
                Id = "1", Name = "Thiago Barradas", Age = 27, CreateDate = new DateTime(2019, 01, 01)
            };

            // act
            var result = command.Upsert(person);

            // assert
            Assert.True(result);
            Assert.Equal("Index", ElasticClientMock.LastElasticClientAction);
            Assert.Equal(options.DefaultIndexName + "-2019-01", ElasticClientMock.LastProcessedIndex);
            Assert.Equal(person.Id, ElasticClientMock.LastProcessedPerson.Id);
            Assert.Equal(person.Name, ElasticClientMock.LastProcessedPerson.Name);
        }