Skip to content

Commit

Permalink
Added asserts for some of the sample methods in tests. Removed [Fact]…
Browse files Browse the repository at this point in the history
… attribute from the sample methods that are covered in other tests
  • Loading branch information
oskardudycz committed Feb 12, 2019
1 parent d961302 commit 7dfdcb7
Showing 1 changed file with 75 additions and 40 deletions.
115 changes: 75 additions & 40 deletions src/Marten.Testing/Acceptance/full_text_index.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Marten.Schema;
using Marten.Storage;
Expand Down Expand Up @@ -81,8 +82,7 @@ public class BlogPost
// ENDSAMPLE

public class full_text_index : IntegratedFixture
{
[Fact]
{
public void using_whole_document_full_text_index_through_store_options_with_default()
{
// SAMPLE: using_whole_document_full_text_index_through_store_options_with_default
Expand All @@ -96,7 +96,6 @@ public void using_whole_document_full_text_index_through_store_options_with_defa
// ENDSAMPLE
}

[Fact]
public void using_a_single_property_full_text_index_through_store_options_with_default()
{
// SAMPLE: using_a_single_property_full_text_index_through_store_options_with_default
Expand All @@ -110,7 +109,6 @@ public void using_a_single_property_full_text_index_through_store_options_with_d
// ENDSAMPLE
}

[Fact]
public void using_a_single_property_full_text_index_through_store_options_with_custom_settings()
{
// SAMPLE: using_a_single_property_full_text_index_through_store_options_with_custom_settings
Expand All @@ -130,7 +128,6 @@ public void using_a_single_property_full_text_index_through_store_options_with_c
// ENDSAMPLE
}

[Fact]
public void using_multiple_properties_full_text_index_through_store_options_with_default()
{
// SAMPLE: using_multiple_properties_full_text_index_through_store_options_with_default
Expand All @@ -144,7 +141,6 @@ public void using_multiple_properties_full_text_index_through_store_options_with
// ENDSAMPLE
}

[Fact]
public void using_multiple_properties_full_text_index_through_store_options_with_custom_settings()
{
// SAMPLE: using_multiple_properties_full_text_index_through_store_options_with_custom_settings
Expand All @@ -164,7 +160,6 @@ public void using_multiple_properties_full_text_index_through_store_options_with
// ENDSAMPLE
}

[Fact]
public void using_more_than_one_full_text_index_through_store_options_with_different_reg_config()
{
// SAMPLE: using_more_than_one_full_text_index_through_store_options_with_different_reg_config
Expand All @@ -181,16 +176,17 @@ public void using_more_than_one_full_text_index_through_store_options_with_diffe
}

[Fact]
public void example()
public void using_full_text_query_through_query_session()
{
// SAMPLE: using-a-full-text-index
// SAMPLE: using_full_text_query_through_query_session
var store = DocumentStore.For(_ =>
{
_.Connection(ConnectionSource.ConnectionString);
// Create the full text index
_.Schema.For<User>().FullTextIndex();
});
IReadOnlyList<User> result;

using (var session = store.OpenSession())
{
Expand All @@ -201,52 +197,40 @@ public void example()
session.Store(new User { FirstName = "Somebody", LastName = "Somewher", UserName = "somebody" });
session.SaveChanges();

var somebody = session.Search<User>("somebody");
result = session.Search<User>("somebody");
}

store.Dispose();

// ENDSAMPLE
}

[Fact]
public void using_a_full_text_index_with_queryable()
{
// SAMPLE: using_a_full_text_index_with_queryable
var store = DocumentStore.For(_ =>
{
_.Connection(ConnectionSource.ConnectionString);
});

using (var session = store.OpenSession())
{
session.Store(new BlogPost { Id = Guid.NewGuid(), EnglishText = "Lorem ipsum", Category = "Travel" });
session.Store(new BlogPost { Id = Guid.NewGuid(), EnglishText = "Dolor sit", Category = "Travel" });
session.Store(new BlogPost { Id = Guid.NewGuid(), EnglishText = "Amet", Category = "LifeStyle" });
session.SaveChanges();

var somebody = session.Query<BlogPost>()
.Where(blogPost => blogPost.Category == "Travel")
.Where(blogPost => blogPost.Search("Lorem"))
.ToList();
}

store.Dispose();
// ENDSAMPLE
result.Count().ShouldBe(1);
}

[Fact]
public void search_in_query_sample()
{
StoreOptions(_ => _.RegisterDocumentType<BlogPost>());

var expectedId = Guid.NewGuid();

using (var session = theStore.OpenSession())
{
session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" });
session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" });
session.SaveChanges();
}

using (var session = theStore.OpenSession())
{
// SAMPLE: search_in_query_sample
var posts = session.Query<BlogPost>()
.Where(x => x.Search("somefilter"))
.ToList();
// ENDSAMPLE

posts.Count.ShouldBe(1);
posts.Single().Id.ShouldBe(expectedId);
}
}

Expand All @@ -255,26 +239,52 @@ public void plain_text_search_in_query_sample()
{
StoreOptions(_ => _.RegisterDocumentType<BlogPost>());

var expectedId = Guid.NewGuid();

using (var session = theStore.OpenSession())
{
session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" });
session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" });
session.SaveChanges();
}

using (var session = theStore.OpenSession())
{
// SAMPLE: plain_search_in_query_sample
var posts = session.Query<BlogPost>()
.Where(x => x.PlainTextSearch("somefilter"))
.ToList();
// ENDSAMPLE
.ToList();
// ENDSAMPLE

posts.Count.ShouldBe(1);
posts.Single().Id.ShouldBe(expectedId);
}
}

[Fact]
public void phrase_search_in_query_sample()
{
StoreOptions(_ => _.RegisterDocumentType<BlogPost>());

var expectedId = Guid.NewGuid();

using (var session = theStore.OpenSession())
{
session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" });
session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" });
session.SaveChanges();
}

using (var session = theStore.OpenSession())
{
// SAMPLE: phrase_search_in_query_sample
var posts = session.Query<BlogPost>()
.Where(x => x.PhraseSearch("somefilter"))
.ToList();
// ENDSAMPLE
// ENDSAMPLE

posts.Count.ShouldBe(1);
posts.Single().Id.ShouldBe(expectedId);
}
}

Expand All @@ -283,14 +293,27 @@ public void text_search_combined_with_other_query_sample()
{
StoreOptions(_ => _.RegisterDocumentType<BlogPost>());

var expectedId = Guid.NewGuid();

using (var session = theStore.OpenSession())
{
session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter", Category = "LifeStyle" });
session.Store(new BlogPost { Id = Guid.NewGuid(), EnglishText = "somefilter", Category = "Other" });
session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter", Category = "LifeStyle" });
session.SaveChanges();
}

using (var session = theStore.OpenSession())
{
// SAMPLE: text_search_combined_with_other_query_sample
var posts = session.Query<BlogPost>()
.Where(x => x.Category == "LifeStyle")
.Where(x => x.PhraseSearch("somefilter"))
.ToList();
// ENDSAMPLE
// ENDSAMPLE

posts.Count.ShouldBe(1);
posts.Single().Id.ShouldBe(expectedId);
}
}

Expand All @@ -299,13 +322,25 @@ public void text_search_with_non_default_regConfig_sample()
{
StoreOptions(_ => _.RegisterDocumentType<BlogPost>());

var expectedId = Guid.NewGuid();

using (var session = theStore.OpenSession())
{
session.Store(new BlogPost { Id = Guid.NewGuid(), EnglishText = "somefilter" });
session.Store(new BlogPost { Id = expectedId, ItalianText = "somefilter" });
session.SaveChanges();
}

using (var session = theStore.OpenSession())
{
// SAMPLE: text_search_with_non_default_regConfig_sample
var posts = session.Query<BlogPost>()
.Where(x => x.PhraseSearch("somefilter", "italian"))
.ToList();
// ENDSAMPLE
// ENDSAMPLE

posts.Count.ShouldBe(1);
posts.Single().Id.ShouldBe(expectedId);
}
}

Expand Down

0 comments on commit 7dfdcb7

Please sign in to comment.