Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor embedded testing to a different class

  • Loading branch information...
commit c6c79645754517ec543e3d460ef1c8879a8c4482 1 parent 04364c4
@fitzchak fitzchak authored
View
1  Raven.Tests/Raven.Tests.csproj
@@ -770,6 +770,7 @@
<Compile Include="Storage\ReduceStaleness.cs" />
<Compile Include="Storage\SimilarIndexNames.cs" />
<Compile Include="Stress\BigDoc.cs" />
+ <Compile Include="Suggestions\SuggestionsLazy.cs" />
<Compile Include="Suggestions\Person.cs" />
<Compile Include="Suggestions\Suggestions.cs" />
<Compile Include="Suggestions\SuggestionsHelper.cs" />
View
244 Raven.Tests/Suggestions/Suggestions.cs
@@ -4,160 +4,113 @@
// </copyright>
//-----------------------------------------------------------------------
using System;
+using System.Linq;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
+using Raven.Client;
using Raven.Client.Document;
using Raven.Client.Linq;
-using Raven.Database.Indexing;
using Raven.Tests.Bugs;
using Xunit;
-using System.Linq;
namespace Raven.Tests.Suggestions
{
public class Suggestions : LocalClientTest, IDisposable
{
- #region IDisposable Members
+ private readonly IDocumentStore documentStore;
- public void Dispose()
+ public Suggestions()
{
-
+ documentStore = NewDocumentStore();
}
- #endregion
-
- protected DocumentStore DocumentStore { get; set; }
+ public void Dispose()
+ {
+ documentStore.Dispose();
+ }
[Fact]
public void ExactMatch()
{
- using (var store = NewDocumentStore())
+ documentStore.DatabaseCommands.PutIndex("Test", new IndexDefinition
+ {
+ Map = "from doc in docs select new { doc.Name }",
+ });
+ using (var s = documentStore.OpenSession())
{
- store.DatabaseCommands.PutIndex("Test", new IndexDefinition
- {
- Map = "from doc in docs select new { doc.Name }",
- });
- using (var s = store.OpenSession())
- {
- s.Store(new User { Name = "Ayende" });
- s.Store(new User { Name = "Oren" });
- s.SaveChanges();
-
- s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
- }
-
- using (var s = store.OpenSession())
- {
- var suggestionQueryResult = s.Advanced.DatabaseCommands.Suggest("Test",
- new SuggestionQuery
- {
- Field = "Name",
- Term = "Oren",
- MaxSuggestions = 10,
- });
-
- Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
- Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
- }
+ s.Store(new User {Name = "Ayende"});
+ s.Store(new User {Name = "Oren"});
+ s.SaveChanges();
+
+ s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
}
- }
- [Fact]
- public void UsingLinq()
- {
- using (var store = NewDocumentStore())
+ using (var s = documentStore.OpenSession())
{
- store.DatabaseCommands.PutIndex("Test", new IndexDefinition
- {
- Map = "from doc in docs select new { doc.Name }",
- });
- using (var s = store.OpenSession())
- {
- s.Store(new User { Name = "Ayende" });
- s.Store(new User { Name = "Oren" });
- s.SaveChanges();
-
- s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
- }
-
- using (var s = store.OpenSession())
- {
- var suggestionQueryResult = s.Query<User>("test")
- .Where(x => x.Name == "Oren")
- .Suggest();
-
- Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
- Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
- }
+ var suggestionQueryResult = s.Advanced.DatabaseCommands.Suggest("Test",
+ new SuggestionQuery
+ {
+ Field = "Name",
+ Term = "Oren",
+ MaxSuggestions = 10,
+ });
+
+ Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
+ Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
}
}
[Fact]
- public void UsingLinq_Lazy()
+ public void UsingLinq()
{
- using(GetNewServer())
- using (var store = new DocumentStore
+ documentStore.DatabaseCommands.PutIndex("Test", new IndexDefinition
+ {
+ Map = "from doc in docs select new { doc.Name }",
+ });
+ using (var s = documentStore.OpenSession())
{
- Url = "http://localhost:8079"
- }.Initialize())
+ s.Store(new User {Name = "Ayende"});
+ s.Store(new User {Name = "Oren"});
+ s.SaveChanges();
+
+ s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
+ }
+
+ using (var s = documentStore.OpenSession())
{
- store.DatabaseCommands.PutIndex("Test", new IndexDefinition
- {
- Map = "from doc in docs select new { doc.Name }",
- });
- using (var s = store.OpenSession())
- {
- s.Store(new User { Name = "Ayende" });
- s.Store(new User { Name = "Oren" });
- s.SaveChanges();
-
- s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
- }
-
- using (var s = store.OpenSession())
- {
- var oldRequests = s.Advanced.NumberOfRequests;
-
- var suggestionQueryResult = s.Query<User>("test")
- .Where(x => x.Name == "Oren")
- .SuggestLazy();
-
- Assert.Equal(oldRequests, s.Advanced.NumberOfRequests);
- Assert.Equal(1, suggestionQueryResult.Value.Suggestions.Length);
- Assert.Equal("oren", suggestionQueryResult.Value.Suggestions[0]);
-
- Assert.Equal(oldRequests + 1, s.Advanced.NumberOfRequests);
- }
+ var suggestionQueryResult = s.Query<User>("test")
+ .Where(x => x.Name == "Oren")
+ .Suggest();
+
+ Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
+ Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
}
}
[Fact]
public void UsingLinq_WithOptions()
{
- using (var store = NewDocumentStore())
+ documentStore.DatabaseCommands.PutIndex("Test", new IndexDefinition
+ {
+ Map = "from doc in docs select new { doc.Name }",
+ });
+ using (var s = documentStore.OpenSession())
{
- store.DatabaseCommands.PutIndex("Test", new IndexDefinition
- {
- Map = "from doc in docs select new { doc.Name }",
- });
- using (var s = store.OpenSession())
- {
- s.Store(new User { Name = "Ayende" });
- s.Store(new User { Name = "Oren" });
- s.SaveChanges();
-
- s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
- }
-
- using (var s = store.OpenSession())
- {
- var suggestionQueryResult = s.Query<User>("test")
- .Where(x => x.Name == "Orin")
- .Suggest(new SuggestionQuery { Accuracy = 0.4f });
-
- Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
- Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
- }
+ s.Store(new User {Name = "Ayende"});
+ s.Store(new User {Name = "Oren"});
+ s.SaveChanges();
+
+ s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
+ }
+
+ using (var s = documentStore.OpenSession())
+ {
+ var suggestionQueryResult = s.Query<User>("test")
+ .Where(x => x.Name == "Orin")
+ .Suggest(new SuggestionQuery {Accuracy = 0.4f});
+
+ Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
+ Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
}
}
@@ -165,37 +118,34 @@ public void UsingLinq_WithOptions()
[Fact]
public void WithTypo()
{
- using (var store = NewDocumentStore())
+ documentStore.DatabaseCommands.PutIndex("Test", new IndexDefinition
+ {
+ Map = "from doc in docs select new { doc.Name }",
+ });
+ using (var s = documentStore.OpenSession())
+ {
+ s.Store(new User {Name = "Ayende"});
+ s.Store(new User {Name = "Oren"});
+ s.SaveChanges();
+
+ s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
+ }
+
+ using (var s = documentStore.OpenSession())
{
- store.DatabaseCommands.PutIndex("Test", new IndexDefinition
- {
- Map = "from doc in docs select new { doc.Name }",
- });
- using (var s = store.OpenSession())
- {
- s.Store(new User { Name = "Ayende" });
- s.Store(new User { Name = "Oren" });
- s.SaveChanges();
-
- s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
- }
-
- using (var s = store.OpenSession())
- {
- var suggestionQueryResult = s.Advanced.DatabaseCommands.Suggest("Test",
- new SuggestionQuery
- {
- Field = "Name",
- Term = "Oern",
- MaxSuggestions = 10,
- Accuracy = 0.2f,
- Distance = StringDistanceTypes.Levenshtein
- });
-
- Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
- Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
- }
+ var suggestionQueryResult = s.Advanced.DatabaseCommands.Suggest("Test",
+ new SuggestionQuery
+ {
+ Field = "Name",
+ Term = "Oern",
+ MaxSuggestions = 10,
+ Accuracy = 0.2f,
+ Distance = StringDistanceTypes.Levenshtein
+ });
+
+ Assert.Equal(1, suggestionQueryResult.Suggestions.Length);
+ Assert.Equal("oren", suggestionQueryResult.Suggestions[0]);
}
}
}
-}
+}
View
53 Raven.Tests/Suggestions/SuggestionsLazy.cs
@@ -0,0 +1,53 @@
+//-----------------------------------------------------------------------
+// <copyright file="SuggestionsLazy.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+using System.Linq;
+using Raven.Abstractions.Indexing;
+using Raven.Client.Document;
+using Raven.Client.Linq;
+using Raven.Tests.Bugs;
+using Xunit;
+
+namespace Raven.Tests.Suggestions
+{
+ public class SuggestionsLazy : LocalClientTest
+ {
+ [Fact]
+ public void UsingLinq()
+ {
+ using(GetNewServer())
+ using (var store = new DocumentStore{Url = "http://localhost:8079"}.Initialize())
+ {
+ store.DatabaseCommands.PutIndex("Test", new IndexDefinition
+ {
+ Map = "from doc in docs select new { doc.Name }",
+ });
+ using (var s = store.OpenSession())
+ {
+ s.Store(new User { Name = "Ayende" });
+ s.Store(new User { Name = "Oren" });
+ s.SaveChanges();
+
+ s.Query<User>("Test").Customize(x => x.WaitForNonStaleResults()).ToList();
+ }
+
+ using (var s = store.OpenSession())
+ {
+ var oldRequests = s.Advanced.NumberOfRequests;
+
+ var suggestionQueryResult = s.Query<User>("test")
+ .Where(x => x.Name == "Oren")
+ .SuggestLazy();
+
+ Assert.Equal(oldRequests, s.Advanced.NumberOfRequests);
+ Assert.Equal(1, suggestionQueryResult.Value.Suggestions.Length);
+ Assert.Equal("oren", suggestionQueryResult.Value.Suggestions[0]);
+
+ Assert.Equal(oldRequests + 1, s.Advanced.NumberOfRequests);
+ }
+ }
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.