Skip to content

Commit

Permalink
Updated tests to not use generic OpenSession method
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Feb 13, 2023
1 parent 138b5f2 commit fd3fe42
Show file tree
Hide file tree
Showing 140 changed files with 1,478 additions and 1,741 deletions.
2 changes: 1 addition & 1 deletion docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ You can also directly apply a session logger to any `IQuerySession` or `IDocumen
<!-- snippet: sample_plugging-in-session-logger -->
<a id='snippet-sample_plugging-in-session-logger'></a>
```cs
using var session = store.OpenSession();
using var session = store.LightweightSession();
// Replace the logger for only this one session
session.Logger = new RecordingLogger();
```
Expand Down
8 changes: 4 additions & 4 deletions docs/documents/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CoffeeShop: Shop
public ICollection<Guid> Employees { get; set; } = new List<Guid>();
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs#L840-L850' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_useoptimisticconcurrencyattribute' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs#L833-L843' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_useoptimisticconcurrencyattribute' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or by using Marten's configuration API to do it programmatically:
Expand All @@ -34,7 +34,7 @@ var store = DocumentStore.For(_ =>
_.Schema.For<Issue>().UseOptimisticConcurrency(true);
});
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs#L36-L42' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring-optimistic-concurrency' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs#L35-L41' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring-optimistic-concurrency' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Once optimistic concurrency is turned on for the CoffeeShop document type, a session will now only be able to update a document if the document has been unchanged in the database since it was initially loaded.
Expand All @@ -48,7 +48,7 @@ To demonstrate the failure case, consider the following  acceptance test from M
public void update_with_stale_version_standard()
{
var doc1 = new CoffeeShop();
using (var session = theStore.OpenSession())
using (var session = theStore.LightweightSession())
{
session.Store(doc1);
session.SaveChanges();
Expand Down Expand Up @@ -87,7 +87,7 @@ public void update_with_stale_version_standard()
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs#L128-L172' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_update_with_stale_version_standard' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs#L127-L171' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_update_with_stale_version_standard' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Marten is throwing an AggregateException for the entire batch of chang
Expand Down
10 changes: 5 additions & 5 deletions docs/documents/deletes.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ theSession.StoreObjects(new object[] { user1, issue1, company1 });
theSession.SaveChanges();

// Delete a mix of documents types
using (var session = theStore.OpenSession())
using (var session = theStore.LightweightSession())
{
session.DeleteObjects(new object[] { user1, company1 });

Expand Down Expand Up @@ -186,7 +186,7 @@ public void query_soft_deleted_docs()
var user3 = new User { UserName = "baz" };
var user4 = new User { UserName = "jack" };

using var session = theStore.OpenSession();
using var session = theStore.LightweightSession();
session.Store(user1, user2, user3, user4);
session.SaveChanges();

Expand Down Expand Up @@ -228,7 +228,7 @@ public void query_maybe_soft_deleted_docs()
var user3 = new User { UserName = "baz" };
var user4 = new User { UserName = "jack" };

using var session = theStore.OpenSession();
using var session = theStore.LightweightSession();
session.Store(user1, user2, user3, user4);
session.SaveChanges();

Expand Down Expand Up @@ -266,7 +266,7 @@ public void query_is_soft_deleted_docs()
var user3 = new User { UserName = "baz" };
var user4 = new User { UserName = "jack" };

using var session = theStore.OpenSession();
using var session = theStore.LightweightSession();
session.Store(user1, user2, user3, user4);
session.SaveChanges();

Expand Down Expand Up @@ -304,7 +304,7 @@ public void query_is_soft_deleted_since_docs()
var user3 = new User { UserName = "baz" };
var user4 = new User { UserName = "jack" };

using var session = theStore.OpenSession();
using var session = theStore.LightweightSession();
session.Store(user1, user2, user3, user4);
session.SaveChanges();

Expand Down
2 changes: 1 addition & 1 deletion docs/documents/identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class OverriddenHiloDoc
public int Id { get; set; }
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/Identity/Sequences/hilo_configuration_overrides.cs#L187-L193' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_overriding-hilo-with-attribute' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/Identity/Sequences/hilo_configuration_overrides.cs#L186-L192' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_overriding-hilo-with-attribute' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

You can also use the `MartenRegistry` fluent interface to override the Hilo configuration for a document type as in this example:
Expand Down
4 changes: 2 additions & 2 deletions docs/documents/querying/linq/include.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void include_to_dictionary()
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs#L483-L509' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_dictionary_include' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs#L481-L507' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_dictionary_include' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Include Multiple Document Types
Expand Down Expand Up @@ -111,7 +111,7 @@ public void multiple_includes()
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs#L706-L736' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_multiple_include' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs#L704-L734' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_multiple_include' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Asynchronous Support
Expand Down
4 changes: 2 additions & 2 deletions docs/documents/querying/linq/projections.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void can_do_simple_select_many_against_simple_array()
var product2 = new Product {Tags = new[] {"b", "c", "d"}};
var product3 = new Product {Tags = new[] {"d", "e", "f"}};

using (var session = theStore.OpenSession())
using (var session = theStore.LightweightSession())
{
session.Store(product1, product2, product3);
session.SaveChanges();
Expand Down Expand Up @@ -178,7 +178,7 @@ var results = query.Query<Target>()
.Take(15)
.ToList();
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/Linq/query_with_select_many.cs#L395-L403' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using-select-many' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/Linq/query_with_select_many.cs#L385-L393' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using-select-many' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

A few notes on the `SelectMany()` usage and limitations:
Expand Down
18 changes: 8 additions & 10 deletions docs/documents/querying/linq/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ Combine your Linq queries with raw SQL using the `MatchesSql(sql)` method like s
[Fact]
public void query_with_matches_sql()
{
using (var session = theStore.OpenSession())
{
var u = new User {FirstName = "Eric", LastName = "Smith"};
session.Store(u);
session.SaveChanges();
using var session = theStore.LightweightSession();
var u = new User {FirstName = "Eric", LastName = "Smith"};
session.Store(u);
session.SaveChanges();

var user = session.Query<User>().Where(x => x.MatchesSql("data->> 'FirstName' = ?", "Eric")).Single();
user.LastName.ShouldBe("Smith");
user.Id.ShouldBe(u.Id);
}
var user = session.Query<User>().Where(x => x.MatchesSql("data->> 'FirstName' = ?", "Eric")).Single();
user.LastName.ShouldBe("Smith");
user.Id.ShouldBe(u.Id);
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/query_by_sql.cs#L279-L296' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_query_with_matches_sql' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/query_by_sql.cs#L259-L274' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_query_with_matches_sql' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
2 changes: 1 addition & 1 deletion docs/documents/querying/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ a document body, but in that case you will need to supply the full SQL statement
var sumResults = await session
.QueryAsync<int>("select count(*) from mt_doc_target");
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/query_by_sql.cs#L369-L374' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_query_by_full_sql' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Reading/query_by_sql.cs#L343-L348' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_query_by_full_sql' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

The basic rules for how Marten handles user-supplied queries are:
Expand Down
Loading

0 comments on commit fd3fe42

Please sign in to comment.