From 0278bbef945ea6310f001e4361889d22423009e5 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Mon, 21 Oct 2024 10:54:44 -0500 Subject: [PATCH] Eliminating most usages of sync SaveChanges in tests all tests passing after the big changes adjusting code samples in docs Finishing up removing SaveChanges() Yet another round of SaveChanges to SaveChangesAsync Another round of SaveChanges retirement in the tests More elimination of SaveChanges() in test code More sync to async test conversions --- docs/configuration/multitenancy.md | 2 +- docs/configuration/storeoptions.md | 2 +- docs/documents/concurrency.md | 20 +- docs/documents/deletes.md | 60 ++--- docs/documents/hierarchies.md | 22 +- docs/documents/identity.md | 44 +++- docs/documents/multi-tenancy.md | 32 +-- docs/documents/partial-updates-patching.md | 104 ++++---- docs/documents/plv8.md | 66 +++--- docs/documents/querying/batched-queries.md | 8 +- docs/documents/querying/compiled-queries.md | 24 +- .../querying/linq/child-collections.md | 22 +- docs/documents/querying/linq/include.md | 20 +- docs/documents/querying/linq/index.md | 2 +- docs/documents/querying/linq/operators.md | 18 +- docs/documents/querying/linq/projections.md | 20 +- docs/documents/querying/linq/sql.md | 4 +- docs/documents/querying/query-json.md | 6 +- docs/documents/sessions.md | 4 +- docs/documents/storing.md | 2 +- docs/events/appending.md | 4 +- docs/events/index.md | 2 +- .../projections/aggregate-projections.md | 2 +- docs/events/projections/custom.md | 4 +- docs/events/querying.md | 4 +- docs/scenarios/copy-and-transform-stream.md | 4 +- .../Bugs/Bug_1296_sessionlistener_updates.cs | 58 ----- ...ssible_to_use_Serializable_transactions.cs | 14 +- src/CoreTests/SessionOptionsTests.cs | 6 +- src/CoreTests/create_database_Tests.cs | 4 +- src/CoreTests/retry_mechanism.cs | 4 +- src/DaemonTests/StressTester.cs | 183 -------------- ...BigIntergerTests.cs => BigIntegerTests.cs} | 25 +- ...lid_cast_exception_on_doc_with_subclass.cs | 47 ++-- ...3_same_named_class_different_namespaces.cs | 7 +- .../Bugs/Bug_1155_null_duplicate_fields.cs | 41 ++-- ...able_with_duplicated_string_field_Tests.cs | 5 +- ...se_insensitive_custom_sql_queries_Tests.cs | 7 +- ...user_friendly_warning_about_public_type.cs | 10 +- .../Bugs/Bug_2018_fts_string_list.cs | 5 +- .../Bugs/Bug_237_duplicate_indexing_Tests.cs | 7 +- .../Bug_274_cyclic_dependency_found_Tests.cs | 7 +- .../Bugs/Bug_339_async_cache_problem.cs | 4 +- ...k_by_not_first_loading_from_the_session.cs | 12 +- ...ug_635_operations_order_in_same_session.cs | 7 +- .../Bug_654_document_session_delete_Tests.cs | 5 +- .../Bug_673_multiple_version_assertions.cs | 13 +- .../Bugs/Bug_902_generic_type_documents.cs | 7 +- ...64_optimistic_concurrency_with_subclass.cs | 15 +- ...ug_986_duplicated_fields_with_int_array.cs | 7 +- .../Bugs/SelfForeignKeyBugs.cs | 5 +- .../Bugs/SubClassForeignKeyBugs.cs | 11 +- .../Bugs/ability_to_persist_generic_types.cs | 9 +- .../ability_to_persist_nested_types_Tests.cs | 7 +- ...timistic_concurrency_with_update_method.cs | 14 +- .../Concurrency/numeric_revisioning.cs | 122 +++++----- .../Concurrency/optimistic_concurrency.cs | 129 +++++----- .../Deleting/delete_a_single_document.cs | 27 +-- .../delete_many_documents_by_query.cs | 16 +- .../Deleting/deleting_multiple_documents.cs | 13 +- src/DocumentDbTests/Deleting/soft_deletes.cs | 224 +++++++++--------- .../ForeignKeys/foreign_keys.cs | 86 +++---- ...th_include_and_document_hierarchy_Tests.cs | 4 +- .../Bug_1484_store_overloads_Tests.cs | 17 +- .../delete_by_where_for_hierarchy_Tests.cs | 19 +- ...d_to_end_document_hierarchy_usage_Tests.cs | 8 +- ...document_hierarchy_with_interface_tests.cs | 15 +- .../persist_and_load_for_hierarchy_Tests.cs | 34 +-- .../query_through_mixed_population_Tests.cs | 27 ++- ...through_mixed_population_multi_tenanted.cs | 16 +- .../Indexes/UniqueIndexTests.cs | 17 +- .../Indexes/duplicated_field.cs | 24 +- .../Indexes/full_text_index.cs | 40 ++-- .../Metadata/created_timestamp_queries.cs | 13 +- .../Metadata/end_to_end_versioned_docs.cs | 20 +- .../Metadata/fetching_entity_metadata.cs | 12 +- .../Metadata/last_modified_queries.cs | 12 +- .../projecting_metadata_to_documents.cs | 24 +- .../UniqueIndexMultiTenantTests.cs | 31 +-- .../MultiTenancy/conjoined_multi_tenancy.cs | 30 ++- ...njoined_multi_tenancy_with_partitioning.cs | 28 ++- .../batched_querying_acceptance_Tests.cs | 14 +- .../Json/document_session_find_json_Tests.cs | 7 +- .../Reading/Json/streaming_json_results.cs | 2 +- ...sion_load_already_loaded_document_Tests.cs | 4 +- ...n_load_not_yet_persisted_document_Tests.cs | 9 +- src/DocumentDbTests/Reading/query_by_sql.cs | 48 ++-- ...cumentSession_change_set_tracking_Tests.cs | 9 +- .../UnitOfWork_Operation_Ordering_Tests.cs | 78 +++--- ...Work_PendingChanges_Functionality_Tests.cs | 5 +- ...ng_Global_DocumentSessionListener_Tests.cs | 24 +- ...ing_Local_DocumentSessionListener_Tests.cs | 20 +- .../dirty_tracked_sessions.cs | 43 ++-- .../document_session_logs_SaveChanges.cs | 4 +- .../SessionMechanics/ejecting_documents.cs | 51 ++-- .../identity_map_mechanics.cs | 20 +- .../SessionMechanics/updating_by_batch.cs | 10 +- ..._Hilo_table_being_erroneously_recreated.cs | 7 +- .../Sequences/CombGuidIdGenerationTests.cs | 13 +- .../Sequences/CustomKeyGenerationTests.cs | 5 +- .../Sequences/IdentityKeyGenerationTests.cs | 13 +- .../Identity/private_identity_fields.cs | 11 +- .../Writing/Identity/using_int_identity.cs | 15 +- .../Writing/Identity/using_long_identity.cs | 10 +- .../Identity/using_natural_identity_keys.cs | 5 +- .../Writing/Identity/using_string_identity.cs | 14 +- src/DocumentDbTests/Writing/bulk_loading.cs | 14 +- .../Writing/document_inserts.cs | 16 +- .../Writing/document_updates.cs | 11 +- .../Writing/storing_documents.cs | 34 +-- .../Aggregation/CustomProjectionTests.cs | 4 +- ...nt_type_not_found_bad_exception_message.cs | 5 +- ...ing_generic_event_types_because_why_not.cs | 13 +- ...iple_event_stream_creations_one_session.cs | 4 +- ...g_stream_runs_extra_selects_and_deletes.cs | 5 +- ...bstone_events_violate_seq_id_uniqueness.cs | 12 +- .../Bugs/codegen_issue_with_IEvent.cs | 9 +- .../aggregation_with_event_type_hierarchy.cs | 13 +- .../Projections/EventProjectionTests.cs | 35 +-- ...ne_aggregation_by_stream_with_multiples.cs | 12 +- ...inline_aggregation_with_base_view_class.cs | 15 +- ...on_with_custom_projection_configuration.cs | 7 +- ...line_aggregation_with_non_public_setter.cs | 25 +- ...ne_aggregation_with_private_constructor.cs | 5 +- .../inline_aggregation_with_subclass.cs | 9 +- .../inline_transformation_of_events.cs | 12 +- ...d_event_capture_and_fetching_the_stream.cs | 130 +++++----- ...hing_the_stream_with_string_identifiers.cs | 44 ++-- .../quick_appending_events_workflow_specs.cs | 33 +-- .../ScenarioCopyAndReplaceStream.cs | 6 +- .../Utils/MultipleActionCheck.cs | 38 +-- .../aggregateto_linq_operator_tests.cs | 8 +- .../appending_events_workflow_specs.cs | 24 +- src/EventSourcingTests/archiving_events.cs | 5 +- ...ing_on_expected_event_version_on_append.cs | 28 +-- ...rsions_on_existing_streams_after_append.cs | 8 +- .../delete_single_event_stream.cs | 16 +- ...t_capture_and_fetching_the_stream_Tests.cs | 116 ++++----- ...hing_the_stream_with_string_identifiers.cs | 50 ++-- ...tore_with_string_identifiers_for_stream.cs | 12 +- .../fetch_a_single_event_with_metadata.cs | 8 +- .../fetching_stream_state.cs | 4 +- ...et_committed_events_from_listener_Tests.cs | 13 +- .../multi_tenancy_and_event_capture.cs | 38 +-- ...o_prior_registration_of_the_event_types.cs | 8 +- .../querying_event_data_with_linq.cs | 40 ++-- ..._should_enforce_that_it_is_a_new_stream.cs | 35 +-- .../using_the_schema_objects_Tests.cs | 5 +- .../Acceptance/chained_where_clauses.cs | 9 +- src/LinqTests/Acceptance/date_type_usage.cs | 13 +- src/LinqTests/Acceptance/deep_searches.cs | 25 +- .../Acceptance/diagnostic_methods.cs | 13 +- src/LinqTests/Acceptance/enum_usage.cs | 33 +-- .../equals_method_usage_validation.cs | 13 +- .../Acceptance/matches_sql_queries.cs | 9 +- .../Acceptance/nested_boolean_logic.cs | 5 +- .../Acceptance/null_or_not_null_querying.cs | 5 +- src/LinqTests/Acceptance/nullable_types.cs | 29 +-- .../Acceptance/query_with_inheritance.cs | 28 +-- .../Acceptance/select_clause_usage.cs | 50 ++-- src/LinqTests/Acceptance/select_many.cs | 40 ++-- .../Acceptance/statistics_and_paged_list.cs | 8 +- src/LinqTests/Acceptance/string_filtering.cs | 12 +- .../Bugs/Bug_1219_ordering_by_attributes.cs | 7 +- .../Bug_1245_include_plus_full_text_search.cs | 4 +- .../Bug_1256_querying_against_a_uint_type.cs | 7 +- ...25_Any_with_contains_on_IList_of_string.cs | 9 +- .../Bugs/Bug_1703_Equality_Not_Symmetric.cs | 4 +- .../Bug_1875_duplicated_array_field_test.cs | 9 +- .../Bug_1884_multi_tenancy_and_Any_query.cs | 12 +- ...erying_against_UTC_DateTime_with_Npgsql.cs | 9 +- ...276_Query_by_abstract_type_in_hierarchy.cs | 5 +- .../Bug_3031_querying_using_soft_deletes.cs | 35 +-- .../Bugs/Bug_3096_include_where_select.cs | 5 +- ..._365_compiled_query_with_constant_fails.cs | 9 +- ...432_querying_with_UTC_times_with_offset.cs | 25 +- .../Bug_449_IsOneOf_query_with_enum_types.cs | 9 +- .../Bugs/Bug_479_select_datetime_fields.cs | 9 +- .../Bug_484_Contains_on_IList_of_string.cs | 9 +- .../Bugs/Bug_490_hierarchy_and_include.cs | 4 +- .../Bug_503_query_on_null_complex_object.cs | 5 +- .../Bug_561_negation_of_query_on_contains.cs | 16 +- ...g_634_include_against_soft_deleted_docs.cs | 11 +- ...te_tenancy_filters_appended_incorrectly.cs | 5 +- ...out_of_order_when_types_use_inheritance.cs | 7 +- ..._with_includes_and_ICompiledQuery_reuse.cs | 11 +- src/LinqTests/Bugs/query_with_order_by.cs | 16 +- .../count_for_child_collections.cs | 10 +- .../query_against_child_collections.cs | 117 ++++----- ...llectionToArrayJsonConverter_onProperty.cs | 13 +- ...with_global_CollectionStorage_WithArray.cs | 6 +- .../end_to_end_query_with_compiled_include.cs | 13 +- .../Includes/end_to_end_query_with_include.cs | 104 ++++---- .../Internals/BoolNotVisitorTests.cs | 9 +- .../Operators/aggregate_functions.cs | 36 +-- src/LinqTests/Operators/all_operator.cs | 33 +-- src/LinqTests/Operators/any_operator.cs | 22 +- src/LinqTests/Operators/count_operator.cs | 24 +- src/LinqTests/Operators/distinct_operator.cs | 17 +- src/LinqTests/Operators/first_operator.cs | 24 +- src/LinqTests/Operators/is_empty_operator.cs | 5 +- src/LinqTests/Operators/last_operator.cs | 8 +- src/LinqTests/Operators/modulo_operator.cs | 9 +- src/LinqTests/Operators/negation_operator.cs | 9 +- src/LinqTests/Operators/single_operator.cs | 28 +-- ...sing_containment_operator_in_linq_Tests.cs | 25 +- .../Acceptance/noda_time_acceptance.cs | 153 ++++++------ .../Bug_1173_patch_typenamehandling_bug.cs | 19 +- .../Patching/PatchExpressionTests.cs | 30 +-- .../Patching/multi_tenancy.cs | 28 ++- .../Patching/patching_api.cs | 196 +++++++-------- .../Transforms/document_transforms.cs | 18 +- .../Transforms/select_with_transformation.cs | 8 +- src/Marten.PLv8/StoreOptionsExtensions.cs | 3 + src/Marten.Testing/Examples/Deletes.cs | 8 +- src/Marten.Testing/Examples/MultiTenancy.cs | 13 +- .../Examples/OnePointOneNotes.cs | 49 ---- ...tamp_on_all_changes_by_base_class_Tests.cs | 4 +- .../Examples/UnitOfWorkBlogSamples.cs | 5 +- .../Harness/SpecificationExtensions.cs | 2 +- src/Marten/DocumentStore.cs | 5 + src/Marten/Events/IQueryEventStore.cs | 10 + src/Marten/IDocumentSession.cs | 2 + src/Marten/IJsonLoader.cs | 5 + src/Marten/IQuerySession.cs | 18 ++ .../Sessions/QuerySession.Execution.cs | 1 + src/Marten/Internal/Sessions/QuerySession.cs | 3 + .../Internal/Storage/IDocumentStorage.cs | 1 + src/Marten/Linq/MartenLinqQueryProvider.cs | 1 + src/Marten/Linq/MartenLinqQueryable.cs | 1 + .../Linq/QueryHandlers/IQueryHandler.cs | 3 + src/Marten/QueryableExtensions.cs | 1 + .../Services/BatchQuerying/BatchQueryItem.cs | 5 +- .../Bug_1173_patch_typenamehandling_bug.cs | 7 +- .../Patching/PatchExpressionTests.cs | 28 +-- src/PatchingTests/Patching/multi_tenancy.cs | 29 ++- src/PatchingTests/Patching/patching_api.cs | 206 ++++++++-------- ..._an_existing_connection_and_transaction.cs | 16 +- src/samples/EventSourcingIntro/Program.cs | 14 +- 239 files changed, 2642 insertions(+), 2722 deletions(-) delete mode 100644 src/CoreTests/Bugs/Bug_1296_sessionlistener_updates.cs delete mode 100644 src/DaemonTests/StressTester.cs rename src/DocumentDbTests/Bugs/{BigIntergerTests.cs => BigIntegerTests.cs} (79%) delete mode 100644 src/Marten.Testing/Examples/OnePointOneNotes.cs diff --git a/docs/configuration/multitenancy.md b/docs/configuration/multitenancy.md index 0450798e40..023e56f897 100644 --- a/docs/configuration/multitenancy.md +++ b/docs/configuration/multitenancy.md @@ -39,7 +39,7 @@ var store = DocumentStore.For(opts => opts.TenantIdStyle = TenantIdStyle.ForceUpperCase; }); ``` -snippet source | anchor +snippet source | anchor ## Static Database to Tenant Mapping diff --git a/docs/configuration/storeoptions.md b/docs/configuration/storeoptions.md index 57feb7b84e..5abeb9482a 100644 --- a/docs/configuration/storeoptions.md +++ b/docs/configuration/storeoptions.md @@ -15,7 +15,7 @@ public static DocumentStore For(Action configure) return new DocumentStore(options); } ``` -snippet source | anchor +snippet source | anchor The major parts of `StoreOptions` are shown in the class diagram below: diff --git a/docs/documents/concurrency.md b/docs/documents/concurrency.md index 9e51f85f6d..cbd7df991d 100644 --- a/docs/documents/concurrency.md +++ b/docs/documents/concurrency.md @@ -37,7 +37,7 @@ public class CoffeeShop: Shop public ICollection Employees { get; set; } = new List(); } ``` -snippet source | anchor +snippet source | anchor Or by using Marten's configuration API to do it programmatically: @@ -62,13 +62,13 @@ To demonstrate the failure case, consider the following  acceptance test from M ```cs [Fact] -public void update_with_stale_version_standard() +public async Task update_with_stale_version_standard() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } var session1 = theStore.DirtyTrackedSession(); @@ -83,11 +83,11 @@ public void update_with_stale_version_standard() session2Copy.Name = "Dominican Joe's"; // Should go through just fine - session2.SaveChanges(); + await session2.SaveChangesAsync(); - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { - session1.SaveChanges(); + await session1.SaveChangesAsync(); }); ex.Message.ShouldBe($"Optimistic concurrency check failed for {typeof(Shop).FullName} #{doc1.Id}"); @@ -98,13 +98,11 @@ public void update_with_stale_version_standard() session2.Dispose(); } - using (var query = theStore.QuerySession()) - { - query.Load(doc1.Id).Name.ShouldBe("Dominican Joe's"); - } + await using var query = theStore.QuerySession(); + query.Load(doc1.Id).Name.ShouldBe("Dominican Joe's"); } ``` -snippet source | anchor +snippet source | anchor Marten is throwing an `AggregateException` for the entire batch of changes. diff --git a/docs/documents/deletes.md b/docs/documents/deletes.md index 7ac98a31e1..ba39fd56f1 100644 --- a/docs/documents/deletes.md +++ b/docs/documents/deletes.md @@ -54,7 +54,7 @@ Marten also provides the ability to delete any documents of a certain type meeti ```cs theSession.DeleteWhere(x => x.Double == 578); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); ``` snippet source | anchor @@ -79,17 +79,17 @@ var company1 = new Company { Name = "ECorp" }; session.StoreObjects(new object[] { user1, issue1, company1 }); -session.SaveChanges(); +await session.SaveChangesAsync(); // Delete a mix of documents types using (var documentSession = theStore.LightweightSession()) { documentSession.DeleteObjects(new object[] { user1, company1 }); - documentSession.SaveChanges(); + await documentSession.SaveChangesAsync(); } ``` -snippet source | anchor +snippet source | anchor ## Soft Deletes @@ -179,7 +179,7 @@ in this acceptance test from the Marten codebase: ```cs [Fact] -public void query_soft_deleted_docs() +public async Task query_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -188,11 +188,11 @@ public void query_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // Deleting 'bar' and 'baz' session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, deleted docs should be filtered out session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -207,7 +207,7 @@ public void query_soft_deleted_docs() ```cs [Fact] -public void query_soft_deleted_docs() +public async Task query_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -216,11 +216,11 @@ public void query_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // Deleting 'bar' and 'baz' session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, deleted docs should be filtered out session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -249,7 +249,7 @@ as shown in this acceptance tests: ```cs [Fact] -public void query_maybe_soft_deleted_docs() +public async Task query_maybe_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -258,10 +258,10 @@ public void query_maybe_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, all documents are returned session.Query().Where(x => x.MaybeDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -279,7 +279,7 @@ public void query_maybe_soft_deleted_docs() ```cs [Fact] -public void query_maybe_soft_deleted_docs() +public async Task query_maybe_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -288,10 +288,10 @@ public void query_maybe_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, all documents are returned session.Query().Where(x => x.MaybeDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -363,7 +363,7 @@ as shown below: ```cs [Fact] -public void query_is_soft_deleted_docs() +public async Task query_is_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -372,10 +372,10 @@ public void query_is_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.IsDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -393,7 +393,7 @@ public void query_is_soft_deleted_docs() ```cs [Fact] -public void query_is_soft_deleted_docs() +public async Task query_is_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -402,10 +402,10 @@ public void query_is_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.IsDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -431,7 +431,7 @@ and the counterpart `DeletedSince(DateTimeOffset)` as show below: ```cs [Fact] -public void query_is_soft_deleted_since_docs() +public async Task query_is_soft_deleted_since_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -440,14 +440,14 @@ public void query_is_soft_deleted_since_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); var epoch = session.MetadataFor(user3).DeletedAt; session.Delete(user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.DeletedSince(epoch.Value)).Select(x => x.UserName) .ToList().ShouldHaveTheSameElementsAs("jack"); @@ -457,7 +457,7 @@ public void query_is_soft_deleted_since_docs() ```cs [Fact] -public void query_is_soft_deleted_since_docs() +public async Task query_is_soft_deleted_since_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -466,14 +466,14 @@ public void query_is_soft_deleted_since_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); var epoch = session.MetadataFor(user3).DeletedAt; session.Delete(user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.DeletedSince(epoch.Value)).Select(x => x.UserName) .ToList().ShouldHaveTheSameElementsAs("jack"); diff --git a/docs/documents/hierarchies.md b/docs/documents/hierarchies.md index a596d9caf6..8b18a1f07b 100644 --- a/docs/documents/hierarchies.md +++ b/docs/documents/hierarchies.md @@ -33,7 +33,7 @@ using (var session = store.QuerySession()) session.Query().ToList(); } ``` -snippet source | anchor +snippet source | anchor With the configuration above, you can now query by `User` and get `AdminUser` and `SuperUser` documents as part of the results, @@ -153,27 +153,27 @@ Now you can query the "complex" hierarchy in the following ways: ```cs [Fact] -public void get_all_subclasses_of_a_subclass() +public async Task get_all_subclasses_of_a_subclass() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(3); } [Fact] -public void get_all_subclasses_of_a_subclass2() +public async Task get_all_subclasses_of_a_subclass2() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -181,20 +181,20 @@ public void get_all_subclasses_of_a_subclass2() } [Fact] -public void get_all_subclasses_of_a_subclass_with_where() +public async Task get_all_subclasses_of_a_subclass_with_where() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(s => s.Ability == "Invent").ShouldBe(1); } [Fact] -public void get_all_subclasses_of_a_subclass_with_where_with_camel_casing() +public async Task get_all_subclasses_of_a_subclass_with_where_with_camel_casing() { StoreOptions(_ => { @@ -221,13 +221,13 @@ public void get_all_subclasses_of_a_subclass_with_where_with_camel_casing() var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(s => s.Ability == "Invent").ShouldBe(1); } [Fact] -public void get_all_subclasses_of_an_interface() +public async Task get_all_subclasses_of_an_interface() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; @@ -235,7 +235,7 @@ public void get_all_subclasses_of_an_interface() var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy, papy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(3); } diff --git a/docs/documents/identity.md b/docs/documents/identity.md index 21c961bb47..d39eb4f2c0 100644 --- a/docs/documents/identity.md +++ b/docs/documents/identity.md @@ -63,7 +63,7 @@ public class NonStandardDoc public string Name; } ``` -snippet source | anchor +snippet source | anchor The identity property or field can also be configured through `StoreOptions` by using the `Schema` to obtain a document mapping: @@ -73,7 +73,7 @@ The identity property or field can also be configured through `StoreOptions` by ```cs storeOptions.Schema.For().Identity(x => x.Name); ``` -snippet source | anchor +snippet source | anchor ## Guid Identifiers @@ -96,7 +96,7 @@ options.Policies.ForAllDocuments(m => } }); ``` -snippet source | anchor +snippet source | anchor It is also possible use the SequentialGuid id generation algorithm for a specific document type. @@ -106,7 +106,7 @@ It is also possible use the SequentialGuid id generation algorithm for a specifi ```cs options.Schema.For().IdStrategy(new CombGuidIdGeneration()); ``` -snippet source | anchor +snippet source | anchor ## Sequential Identifiers with Hilo @@ -225,7 +225,7 @@ public class DocumentWithStringId public string Id { get; set; } } ``` -snippet source | anchor +snippet source | anchor You can use the "identity key" option for identity generation that would create string values of the pattern `[type alias]/[sequence]` where the type alias is typically the document class name in all lower case and the sequence is a _HiLo_ sequence number. @@ -243,7 +243,7 @@ var store = DocumentStore.For(opts => .DocumentAlias("doc"); }); ``` -snippet source | anchor +snippet source | anchor ## Custom Identity Strategies @@ -267,7 +267,7 @@ public class CustomIdGeneration : IIdGeneration } ``` -snippet source | anchor +snippet source | anchor The `Build()` method should return the actual `IdGenerator` for the document type, where `T` is the type of the Id field. @@ -287,7 +287,7 @@ options.Policies.ForAllDocuments(m => } }); ``` -snippet source | anchor +snippet source | anchor It is also possible define a custom id generation algorithm for a specific document type. @@ -297,7 +297,7 @@ It is also possible define a custom id generation algorithm for a specific docum ```cs options.Schema.For().IdStrategy(new CustomIdGeneration()); ``` -snippet source | anchor +snippet source | anchor ## Strong Typed Identifiers @@ -459,6 +459,26 @@ public async Task load_many() } ``` snippet source | anchor + +```cs +[Fact] +public async Task load_many() +{ + var issue1 = new Issue3{Name = Guid.NewGuid().ToString()}; + var Issue3 = new Issue3{Name = Guid.NewGuid().ToString()}; + var issue3 = new Issue3{Name = Guid.NewGuid().ToString()}; + theSession.Store(issue1, Issue3, issue3); + + await theSession.SaveChangesAsync(); + + var results = await theSession.Query() + .Where(x => x.Id.IsOneOf(issue1.Id, Issue3.Id, issue3.Id)) + .ToListAsync(); + + results.Count.ShouldBe(3); +} +``` +snippet source | anchor ::: warning @@ -532,7 +552,7 @@ public class LimitedDoc public LowerLimit Lower { get; set; } } ``` -snippet source | anchor +snippet source | anchor ```cs [ValueObject] @@ -570,7 +590,7 @@ And the `UpperLimit` and `LowerLimit` value types can be registered with Marten opts.RegisterValueType(typeof(UpperLimit)); opts.RegisterValueType(typeof(LowerLimit)); ``` -snippet source | anchor +snippet source | anchor ```cs // opts is a StoreOptions just like you'd have in @@ -608,7 +628,7 @@ public async Task store_several_and_order_by() ordered.ShouldHaveTheSameElementsAs(doc1.Id, doc4.Id, doc3.Id, doc2.Id); } ``` -snippet source | anchor +snippet source | anchor ```cs [Fact] diff --git a/docs/documents/multi-tenancy.md b/docs/documents/multi-tenancy.md index 9dc8ab7711..d6befb8edb 100644 --- a/docs/documents/multi-tenancy.md +++ b/docs/documents/multi-tenancy.md @@ -18,7 +18,7 @@ using (var session = theStore.LightweightSession("tenant1")) { session.Store(new User { Id = "u1", UserName = "Bill", Roles = new[] { "admin" } }); session.Store(new User { Id = "u2", UserName = "Lindsey", Roles = new string[0] }); - session.SaveChanges(); + await session.SaveChangesAsync(); } ``` snippet source | anchor @@ -29,7 +29,7 @@ using (var session = theStore.LightweightSession("tenant1")) { session.Store(new User { Id = "u1", UserName = "Bill", Roles = new[] { "admin" } }); session.Store(new User { Id = "u2", UserName = "Lindsey", Roles = new string[0] }); - session.SaveChanges(); + await session.SaveChangesAsync(); } ``` snippet source | anchor @@ -40,10 +40,10 @@ using (var session = store.LightweightSession("tenant1")) { session.Store(new User { UserName = "Bill" }); session.Store(new User { UserName = "Lindsey" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } ``` -snippet source | anchor +snippet source | anchor As with storing, the load operations respect tenancy of the session. @@ -61,7 +61,7 @@ using (var query = store.QuerySession("tenant1")) .ShouldHaveTheSameElementsAs("Bill", "Lindsey"); } ``` -snippet source | anchor +snippet source | anchor Lastly, unlike reading operations, `IDocumentSession.Store` offers an overload to explicitly pass in a tenant identifier, bypassing any tenancy associated with the session. Similar overload for tenancy exists for `IDocumentStore.BulkInsert`. @@ -140,7 +140,7 @@ using (var session = store.QuerySession()) session.Query().Count(x => x.TenantIsOneOf("Red")).ShouldBe(11); } ``` -snippet source | anchor +snippet source | anchor ```cs using var store = DocumentStore.For(opts => @@ -208,7 +208,7 @@ using (var session = store.QuerySession()) session.Query().Count(x => x.TenantIsOneOf("Red")).ShouldBe(11); } ``` -snippet source | anchor +snippet source | anchor In some cases, You may want to disable using the default tenant for storing documents, set `StoreOptions.DefaultTenantUsageEnabled` to `false`. With this option disabled, Tenant (non-default tenant) should be passed via method argument or `SessionOptions` when creating a session using document store. Marten will throw an exception `DefaultTenantUsageDisabledException` if a session is created using default tenant. @@ -230,7 +230,7 @@ using (var query = store.QuerySession("tenant1")) .ShouldHaveTheSameElementsAs("Bill", "Lindsey"); } ``` -snippet source | anchor +snippet source | anchor Marten will automatically filter the LINQ query for the current tenant _if the current document type is tenanted_. However, if @@ -244,14 +244,14 @@ filter: var actual = await query.Query().Where(x => x.TenantIsOneOf("Green", "Red") && x.Flag) .OrderBy(x => x.Id).Select(x => x.Id).ToListAsync(); ``` -snippet source | anchor +snippet source | anchor ```cs // query data for a selected list of tenants var actual = await query.Query().Where(x => x.TenantIsOneOf("Green", "Red") && x.Flag) .OrderBy(x => x.Id).Select(x => x.Id).ToListAsync(); ``` -snippet source | anchor +snippet source | anchor Or the `AnyTenant()` filter: @@ -263,14 +263,14 @@ Or the `AnyTenant()` filter: var actual = query.Query().Where(x => x.AnyTenant() && x.Flag) .OrderBy(x => x.Id).Select(x => x.Id).ToArray(); ``` -snippet source | anchor +snippet source | anchor ```cs // query data across all tenants var actual = query.Query().Where(x => x.AnyTenant() && x.Flag) .OrderBy(x => x.Id).Select(x => x.Id).ToArray(); ``` -snippet source | anchor +snippet source | anchor ## Configuring Tenancy @@ -330,7 +330,7 @@ storeOptions.Policies.AllDocumentsAreMultiTenantedWithPartitioning(x => x.ByExternallyManagedRangePartitions(); }); ``` -snippet source | anchor +snippet source | anchor To enable partitioning for a specific document type, use this option: @@ -348,7 +348,7 @@ var store = DocumentStore.For(opts => }); }); ``` -snippet source | anchor +snippet source | anchor And lastly, if you need to use a mix of tenanted and global document types, but still want to use a consistent @@ -376,7 +376,7 @@ var store = DocumentStore.For(opts => }); }); ``` -snippet source | anchor +snippet source | anchor ### Tenancy Through Policies @@ -390,7 +390,7 @@ storeOptions.Policies.AllDocumentsAreMultiTenanted(); // Shorthand for // storeOptions.Policies.ForAllDocuments(_ => _.TenancyStyle = TenancyStyle.Conjoined); ``` -snippet source | anchor +snippet source | anchor ### Tenancy At Document Level & Policy Overrides diff --git a/docs/documents/partial-updates-patching.md b/docs/documents/partial-updates-patching.md index da84173f51..9c8509dffa 100644 --- a/docs/documents/partial-updates-patching.md +++ b/docs/documents/partial-updates-patching.md @@ -37,7 +37,7 @@ To apply a patch to all documents matching a given criteria, use the following s // Change every Target document where the Color is Blue theSession.Patch(x => x.Color == Colors.Blue).Set(x => x.Number, 2); ``` -snippet source | anchor +snippet source | anchor ## Set a single Property/Field @@ -49,16 +49,16 @@ shown below: ```cs [Fact] -public void set_an_immediate_property_by_id() +public async Task set_an_immediate_property_by_id() { var target = Target.Random(true); target.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Set(x => x.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -66,7 +66,7 @@ public void set_an_immediate_property_by_id() } } ``` -snippet source | anchor +snippet source | anchor ### Set a new Property/Field @@ -79,14 +79,14 @@ To initialize a new property on existing documents: const string where = "(data ->> 'UpdatedAt') is null"; theSession.Query(where).Count.ShouldBe(3); theSession.Patch(new WhereFragment(where)).Set("UpdatedAt", DateTime.UtcNow); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { query.Query(where).Count.ShouldBe(0); } ``` -snippet source | anchor +snippet source | anchor ## Duplicate an existing Property/Field @@ -99,10 +99,10 @@ To copy an existing value to a new location: var target = Target.Random(); target.AnotherString = null; theSession.Store(target); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Duplicate(t => t.String, t => t.AnotherString); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -110,7 +110,7 @@ using (var query = theStore.QuerySession()) result.AnotherString.ShouldBe(target.String); } ``` -snippet source | anchor +snippet source | anchor The same value can be copied to multiple new locations: @@ -123,7 +123,7 @@ theSession.Patch(target.Id).Duplicate(t => t.String, t => t.Inner.String, t => t.Inner.AnotherString); ``` -snippet source | anchor +snippet source | anchor The new locations need not exist in the persisted document, null or absent parents will be initialized @@ -136,16 +136,16 @@ To increment a persisted value in the persisted document, use this operation: ```cs [Fact] -public void increment_for_int() +public async Task increment_for_int() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -153,7 +153,7 @@ public void increment_for_int() } } ``` -snippet source | anchor +snippet source | anchor By default, the `Patch.Increment()` operation will add 1 to the existing value. You can optionally override the increment: @@ -162,16 +162,16 @@ By default, the `Patch.Increment()` operation will add 1 to the existing value. ```cs [Fact] -public void increment_for_int_with_explicit_increment() +public async Task increment_for_int_with_explicit_increment() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number, 3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -179,7 +179,7 @@ public void increment_for_int_with_explicit_increment() } } ``` -snippet source | anchor +snippet source | anchor ## Append Element to a Child Collection @@ -194,7 +194,7 @@ The `Patch.Append()` operation adds a new item to the end of a child collection: ```cs [Fact] -public void append_complex_element() +public async Task append_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -202,10 +202,10 @@ public void append_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -216,7 +216,7 @@ public void append_complex_element() } } ``` -snippet source | anchor +snippet source | anchor The `Patch.AppendIfNotExists()` operation will treat the child collection as a set rather than a list and only append the element if it does not already exist within the collection @@ -233,7 +233,7 @@ being 0 so that a new item would be inserted at the beginning of the child colle ```cs [Fact] -public void insert_first_complex_element() +public async Task insert_first_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -241,10 +241,10 @@ public void insert_first_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -255,7 +255,7 @@ public void insert_first_complex_element() } } ``` -snippet source | anchor +snippet source | anchor The `Patch.InsertIfNotExists()` operation will only insert the element if the element at the designated index does not already exist. @@ -268,7 +268,7 @@ The `Patch.Remove()` operation removes the given item from a child collection: ```cs [Fact] -public void remove_primitive_element() +public async Task remove_primitive_element() { var random = new Random(); var target = Target.Random(); @@ -280,10 +280,10 @@ public void remove_primitive_element() var child = target.NumberArray[random.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -294,7 +294,7 @@ public void remove_primitive_element() } } ``` -snippet source | anchor +snippet source | anchor Removing complex items can also be accomplished, matching is performed on all fields: @@ -303,7 +303,7 @@ Removing complex items can also be accomplished, matching is performed on all fi ```cs [Fact] -public void remove_complex_element() +public async Task remove_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -312,10 +312,10 @@ public void remove_complex_element() var child = target.Children[random.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -326,7 +326,7 @@ public void remove_complex_element() } } ``` -snippet source | anchor +snippet source | anchor To remove reoccurring values from a collection specify `RemoveAction.RemoveAll`: @@ -335,7 +335,7 @@ To remove reoccurring values from a collection specify `RemoveAction.RemoveAll`: ```cs [Fact] -public void remove_repeated_primitive_elements() +public async Task remove_repeated_primitive_elements() { var random = new Random(); var target = Target.Random(); @@ -354,10 +354,10 @@ public void remove_repeated_primitive_elements() } theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child, RemoveAction.RemoveAll); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -368,7 +368,7 @@ public void remove_repeated_primitive_elements() } } ``` -snippet source | anchor +snippet source | anchor ## Rename a Property/Field @@ -381,17 +381,17 @@ old name to the new name. ```cs [Fact] -public void rename_deep_prop() +public async Task rename_deep_prop() { var target = Target.Random(true); target.Inner.String = "Foo"; target.Inner.AnotherString = "Bar"; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Rename("String", x => x.Inner.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -401,7 +401,7 @@ public void rename_deep_prop() } } ``` -snippet source | anchor +snippet source | anchor Renaming can be used on nested values. @@ -418,7 +418,7 @@ To delete a redundant property no longer available on the class use the string o ```cs theSession.Patch(target.Id).Delete("String"); ``` -snippet source | anchor +snippet source | anchor To delete a redundant property nested on a child class specify a location lambda: @@ -428,7 +428,7 @@ To delete a redundant property nested on a child class specify a location lambda ```cs theSession.Patch(target.Id).Delete("String", t => t.Inner); ``` -snippet source | anchor +snippet source | anchor A current property may be erased simply with a lambda: @@ -438,7 +438,7 @@ A current property may be erased simply with a lambda: ```cs theSession.Patch(target.Id).Delete(t => t.Inner); ``` -snippet source | anchor +snippet source | anchor Many documents may be patched using a where expressions: @@ -449,14 +449,14 @@ Many documents may be patched using a where expressions: const string where = "(data ->> 'String') is not null"; theSession.Query(where).Count.ShouldBe(15); theSession.Patch(new WhereFragment(where)).Delete("String"); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { query.Query(where).Count(t => t.String != null).ShouldBe(0); } ``` -snippet source | anchor +snippet source | anchor ## Multi-field patching/chaining patch operations @@ -465,18 +465,18 @@ using (var query = theStore.QuerySession()) ```cs [Fact] -public void able_to_chain_patch_operations() +public async Task able_to_chain_patch_operations() { var target = Target.Random(true); target.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id) .Set(x => x.Number, 10) .Increment(x => x.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -484,5 +484,5 @@ public void able_to_chain_patch_operations() } } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/plv8.md b/docs/documents/plv8.md index 58decd1064..4a7f45e857 100644 --- a/docs/documents/plv8.md +++ b/docs/documents/plv8.md @@ -89,16 +89,16 @@ shown below: ```cs [Fact] -public void set_an_immediate_property_by_id() +public async Task set_an_immediate_property_by_id() { var target = Target.Random(true); target.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Set(x => x.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -119,7 +119,7 @@ To initialize a new property on existing documents: const string where = "(data ->> 'UpdatedAt') is null"; theSession.Query(where).Count.ShouldBe(3); theSession.Patch(new WhereFragment(where)).Set("UpdatedAt", DateTime.UtcNow); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -139,10 +139,10 @@ To copy an existing value to a new location: var target = Target.Random(); target.AnotherString = null; theSession.Store(target); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Duplicate(t => t.String, t => t.AnotherString); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -176,16 +176,16 @@ To increment a persisted value in the persisted document, use this operation: ```cs [Fact] -public void increment_for_int() +public async Task increment_for_int() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -202,16 +202,16 @@ By default, the `Patch.Increment()` operation will add 1 to the existing value. ```cs [Fact] -public void increment_for_int_with_explicit_increment() +public async Task increment_for_int_with_explicit_increment() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number, 3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -234,7 +234,7 @@ The `Patch.Append()` operation adds a new item to the end of a child collection: ```cs [Fact] -public void append_complex_element() +public async Task append_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -242,10 +242,10 @@ public void append_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -273,7 +273,7 @@ being 0 so that a new item would be inserted at the beginning of the child colle ```cs [Fact] -public void insert_first_complex_element() +public async Task insert_first_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -281,10 +281,10 @@ public void insert_first_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -308,7 +308,7 @@ The `Patch.Remove()` operation removes the given item from a child collection: ```cs [Fact] -public void remove_primitive_element() +public async Task remove_primitive_element() { var target = Target.Random(); target.NumberArray = new[] { Random.Shared.Next(0, 10), Random.Shared.Next(0, 10), Random.Shared.Next(0, 10) }; @@ -319,10 +319,10 @@ public void remove_primitive_element() var child = target.NumberArray[Random.Shared.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -342,7 +342,7 @@ Removing complex items can also be accomplished, matching is performed on all fi ```cs [Fact] -public void remove_complex_element() +public async Task remove_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -351,10 +351,10 @@ public void remove_complex_element() var child = target.Children[random.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -374,7 +374,7 @@ To remove reoccurring values from a collection specify `RemoveAction.RemoveAll`: ```cs [Fact] -public void remove_repeated_primitive_elements() +public async Task remove_repeated_primitive_elements() { var random = new Random(); var target = Target.Random(); @@ -393,10 +393,10 @@ public void remove_repeated_primitive_elements() } theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child, RemoveAction.RemoveAll); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -420,17 +420,17 @@ old name to the new name. ```cs [Fact] -public void rename_deep_prop() +public async Task rename_deep_prop() { var target = Target.Random(true); target.Inner.String = "Foo"; target.Inner.AnotherString = "Bar"; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Rename("String", x => x.Inner.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -488,7 +488,7 @@ Many documents may be patched using a where expressions: const string where = "(data ->> 'String') is not null"; theSession.Query(where).Count.ShouldBe(15); theSession.Patch(new WhereFragment(where)).Delete("String"); -theSession.SaveChanges(); +await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -589,13 +589,13 @@ of Linq queries. If you only care about the transformed JSON, you use this synta ```cs [Fact] -public void can_select_a_string_field_in_compiled_query() +public async Task can_select_a_string_field_in_compiled_query() { var user = new User { FirstName = "Eric", LastName = "Berry" }; using var session = theStore.LightweightSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var name = session.Query().Select(x => x.FirstName) .Single(); diff --git a/docs/documents/querying/batched-queries.md b/docs/documents/querying/batched-queries.md index 4fe7002768..b759ff5c65 100644 --- a/docs/documents/querying/batched-queries.md +++ b/docs/documents/querying/batched-queries.md @@ -52,7 +52,7 @@ await batch.Execute(); var internalUser = await firstInternal; Debug.WriteLine($"The first internal user is {internalUser.FirstName} {internalUser.LastName}"); ``` -snippet source | anchor +snippet source | anchor ## Combining Compiled Queries and Batch Queries @@ -74,7 +74,7 @@ public class FindByFirstName: ICompiledQuery } } ``` -snippet source | anchor +snippet source | anchor To use that compiled query class in a batch query, you simply use the `IBatchedQuery.Query(ICompiledQuery)` syntax shown below: @@ -92,7 +92,7 @@ await batch.Execute(); (await justin).Id.ShouldBe(user1.Id); (await tamba).Id.ShouldBe(user2.Id); ``` -snippet source | anchor +snippet source | anchor ## Running Synchronously @@ -112,7 +112,7 @@ batch.ExecuteSynchronously(); justin.Result.Id.ShouldBe(user1.Id); tamba.Result.Id.ShouldBe(user2.Id); ``` -snippet source | anchor +snippet source | anchor The mechanics of running synchronously are identical except for calling `IBatchedQuery.ExecuteSynchronously()`. diff --git a/docs/documents/querying/compiled-queries.md b/docs/documents/querying/compiled-queries.md index 4327db05f0..1dcc7ac00c 100644 --- a/docs/documents/querying/compiled-queries.md +++ b/docs/documents/querying/compiled-queries.md @@ -52,7 +52,7 @@ public class FindByFirstName: ICompiledQuery } } ``` -snippet source | anchor +snippet source | anchor ::: tip @@ -73,7 +73,7 @@ var justin = session.Query(new FindByFirstName { FirstName = "Justin" }); var tamba = await session.QueryAsync(new FindByFirstName { FirstName = "Tamba" }); ``` -snippet source | anchor +snippet source | anchor Or to use it as part of a batched query, this syntax: @@ -91,7 +91,7 @@ await batch.Execute(); (await justin).Id.ShouldBe(user1.Id); (await tamba).Id.ShouldBe(user2.Id); ``` -snippet source | anchor +snippet source | anchor ## How Does It Work? @@ -242,14 +242,14 @@ on the query: ```cs [Fact] -public void simple_compiled_include_for_a_single_document() +public async Task simple_compiled_include_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var issueQuery = new IssueByTitleWithAssignee { Title = issue.Title }; @@ -274,7 +274,7 @@ public class IssueByTitleWithAssignee: ICompiledQuery } } ``` -snippet source | anchor +snippet source | anchor In this example, the query has an `Included` property which will receive the included Assignee / `User`. The 'resulting' included property can only be @@ -306,7 +306,7 @@ public class IssueWithUsers: ICompiledListQuery } [Fact] -public void compiled_include_to_list() +public async Task compiled_include_to_list() { var user1 = new User(); var user2 = new User(); @@ -318,7 +318,7 @@ public void compiled_include_to_list() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = theStore.QuerySession(); var compiledQuery = new IssueWithUsers(); @@ -333,7 +333,7 @@ public void compiled_include_to_list() compiledQuery.Users.Any(x => x.Id == user2.Id); } ``` -snippet source | anchor +snippet source | anchor Note that you could either have the list instantiated or at least make sure the property has a setter as well as a getter (we've got your back). @@ -356,7 +356,7 @@ public class IssueWithUsersById: ICompiledListQuery } [Fact] -public void compiled_include_to_dictionary() +public async Task compiled_include_to_dictionary() { var user1 = new User(); var user2 = new User(); @@ -368,7 +368,7 @@ public void compiled_include_to_dictionary() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = theStore.QuerySession(); var compiledQuery = new IssueWithUsersById(); @@ -382,7 +382,7 @@ public void compiled_include_to_dictionary() compiledQuery.UsersById.ContainsKey(user2.Id).ShouldBeTrue(); } ``` -snippet source | anchor +snippet source | anchor ## Querying for Paginated Results diff --git a/docs/documents/querying/linq/child-collections.md b/docs/documents/querying/linq/child-collections.md index b105fac13b..09ee04924c 100644 --- a/docs/documents/querying/linq/child-collections.md +++ b/docs/documents/querying/linq/child-collections.md @@ -69,7 +69,7 @@ var results = theSession .Where(x => x.Children.Any(_ => _.Number == 6 && _.Double == -1)) .ToArray(); ``` -snippet source | anchor +snippet source | anchor Finally, you can query for child collections that do **not** contain a value: @@ -86,7 +86,7 @@ theSession.Query().Count(x => !x.Strings.Contains("c")) theSession.Query().Count(x => !x.Strings.Contains("c")) .ShouldBe(2); ``` -snippet source | anchor +snippet source | anchor ## Querying within Value IEnumerables @@ -96,7 +96,7 @@ As of now, Marten allows you to do "contains" searches within Arrays, Lists & IL ```cs -public void query_against_string_array() +public async Task query_against_string_array() { var doc1 = new DocWithArrays { Strings = new[] { "a", "b", "c" } }; var doc2 = new DocWithArrays { Strings = new[] { "c", "d", "e" } }; @@ -106,13 +106,13 @@ public void query_against_string_array() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Strings.Contains("c")).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } ``` -snippet source | anchor +snippet source | anchor Marten also allows you to query over IEnumerables using the Any method for equality (similar to Contains): @@ -121,7 +121,7 @@ Marten also allows you to query over IEnumerables using the Any method for equal ```cs [Fact] -public void query_against_number_list_with_any() +public async Task query_against_number_list_with_any() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -130,7 +130,7 @@ public void query_against_number_list_with_any() theSession.Store(doc1, doc2, doc3, doc4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -142,7 +142,7 @@ public void query_against_number_list_with_any() .Count(x => x.Numbers.Any()).ShouldBe(3); } ``` -snippet source | anchor +snippet source | anchor As of 1.2, you can also query against the `Count()` or `Length` of a child collection with the normal comparison @@ -152,7 +152,7 @@ operators (`==`, `>`, `>=`, etc.): ```cs [Fact] -public void query_against_number_list_with_count_method() +public async Task query_against_number_list_with_count_method() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -162,7 +162,7 @@ public void query_against_number_list_with_count_method() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -170,7 +170,7 @@ public void query_against_number_list_with_count_method() .Single(x => x.Numbers.Count() == 4).Id.ShouldBe(doc3.Id); } ``` -snippet source | anchor +snippet source | anchor ## IsOneOf diff --git a/docs/documents/querying/linq/include.md b/docs/documents/querying/linq/include.md index 392f1131ac..c1708267f0 100644 --- a/docs/documents/querying/linq/include.md +++ b/docs/documents/querying/linq/include.md @@ -13,14 +13,14 @@ Marten supports the ability to run include queries that make a single database c ```cs [Fact] -public void simple_include_for_a_single_document() +public async Task simple_include_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); query.Logger = new TestOutputMartenLogger(_output); @@ -54,7 +54,7 @@ Instead of a List, you could also use a Dictionary with a key type corresponding ```cs [Fact] -public void include_to_dictionary() +public async Task include_to_dictionary() { var user1 = new User(); var user2 = new User(); @@ -66,7 +66,7 @@ public void include_to_dictionary() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary(); @@ -121,7 +121,7 @@ Marten also allows you to chain multiple `Include()` calls: ```cs [Fact] -public void multiple_includes() +public async Task multiple_includes() { var assignee = new User{FirstName = "Assignee"}; var reporter = new User{FirstName = "Reporter"}; @@ -131,7 +131,7 @@ public void multiple_includes() using var session = theStore.IdentitySession(); session.Store(assignee, reporter); session.Store(issue1); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User assignee2 = null; @@ -160,14 +160,14 @@ By default, documents are included based on a value that maps to the related doc ```cs [Fact] -public void include_using_custom_map() +public async Task include_using_custom_map() { var classroom = new Classroom(Id: Guid.NewGuid(), RoomCode: "Classroom-1A"); var user = new SchoolUser(Id: Guid.NewGuid(), Name: "Student #1", HomeRoom: "Classroom-1A"); using var session = theStore.IdentitySession(); session.Store(classroom, user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); Classroom? included = null; @@ -191,7 +191,7 @@ By joining on a value other than the document id, this opens up the possibility ```cs [Fact] -public void include_to_dictionary_list() +public async Task include_to_dictionary_list() { var class1 = new Classroom(Id: Guid.NewGuid(), RoomCode: "Classroom-1A"); var class2 = new Classroom(Id: Guid.NewGuid(), RoomCode: "Classroom-2B"); @@ -203,7 +203,7 @@ public void include_to_dictionary_list() using var session = theStore.IdentitySession(); session.Store(class1, class2); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary>(); diff --git a/docs/documents/querying/linq/index.md b/docs/documents/querying/linq/index.md index 64e575c0d9..68577f2989 100644 --- a/docs/documents/querying/linq/index.md +++ b/docs/documents/querying/linq/index.md @@ -16,7 +16,7 @@ implements the traditional [IQueryable](https://msdn.microsoft.com/en-us/library /// IMartenQueryable Query(); ``` -snippet source | anchor +snippet source | anchor To query for all documents of a type - not that you would do this very often outside of testing - use the `Query()` method like this: diff --git a/docs/documents/querying/linq/operators.md b/docs/documents/querying/linq/operators.md index 3e41902edb..273c7094e8 100644 --- a/docs/documents/querying/linq/operators.md +++ b/docs/documents/querying/linq/operators.md @@ -230,7 +230,7 @@ New in Marten 1.2 is support for the Linq `Distinct()` operator: ```cs [Fact] -public void get_distinct_string() +public async Task get_distinct_string() { theSession.Store(new Target {String = "one"}); theSession.Store(new Target {String = "one"}); @@ -239,14 +239,14 @@ public void get_distinct_string() theSession.Store(new Target {String = "three"}); theSession.Store(new Target {String = "three"}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var queryable = theSession.Query().Select(x => x.String).Distinct(); queryable.ToList().Count.ShouldBe(3); } ``` -snippet source | anchor +snippet source | anchor Do note that the `Distinct()` keyword can be used with `Select()` transforms as well: @@ -255,7 +255,7 @@ Do note that the `Distinct()` keyword can be used with `Select()` transforms as ```cs [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] -public void get_distinct_numbers() +public async Task get_distinct_numbers() { theSession.Store(new Target {Number = 1, Decimal = 1.0M}); theSession.Store(new Target {Number = 1, Decimal = 2.0M}); @@ -264,7 +264,7 @@ public void get_distinct_numbers() theSession.Store(new Target {Number = 2, Decimal = 2.0M}); theSession.Store(new Target {Number = 2, Decimal = 1.0M}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var queryable = theSession.Query().Select(x => new { @@ -275,7 +275,7 @@ public void get_distinct_numbers() queryable.ToList().Count.ShouldBe(4); } ``` -snippet source | anchor +snippet source | anchor ## Modulo Queries @@ -286,7 +286,7 @@ Marten has the ability to use the modulo operator in Linq queries: ```cs [Fact] -public void use_modulo() +public async Task use_modulo() { theSession.Store(new Target{Color = Colors.Blue, Number = 1}); theSession.Store(new Target{Color = Colors.Blue, Number = 2}); @@ -295,12 +295,12 @@ public void use_modulo() theSession.Store(new Target{Color = Colors.Blue, Number = 5}); theSession.Store(new Target{Color = Colors.Green, Number = 6}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number % 2 == 0 && x.Color < Colors.Green).ToArray() .Select(x => x.Number) .ShouldHaveTheSameElementsAs(2, 4); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/querying/linq/projections.md b/docs/documents/querying/linq/projections.md index c8ad48279d..1dec63834b 100644 --- a/docs/documents/querying/linq/projections.md +++ b/docs/documents/querying/linq/projections.md @@ -8,14 +8,14 @@ When you wish to retrieve an IEnumerable of a certain document property for exam ```cs [Fact] -public void use_select_in_query_for_one_field() +public async Task use_select_in_query_for_one_field() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => x.FirstName) .ShouldHaveTheSameElementsAs("Bill", "Hank", "Sam", "Tom"); @@ -30,14 +30,14 @@ When you wish to retrieve certain properties and transform them into another typ ```cs [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] -public void use_select_with_multiple_fields_to_other_type() +public async Task use_select_with_multiple_fields_to_other_type() { theSession.Store(new User { FirstName = "Hank", LastName = "Aaron" }); theSession.Store(new User { FirstName = "Bill", LastName = "Laimbeer" }); theSession.Store(new User { FirstName = "Sam", LastName = "Mitchell" }); theSession.Store(new User { FirstName = "Tom", LastName = "Chambers" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var users = theSession.Query().Select(x => new User2 { First = x.FirstName, Last = x.LastName }).ToList(); @@ -59,14 +59,14 @@ When you wish to retrieve certain properties and transform them into an anonymou ```cs [Fact] -public void use_select_to_transform_to_an_anonymous_type() +public async Task use_select_to_transform_to_an_anonymous_type() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => new { Name = x.FirstName }) .ToArray() @@ -107,14 +107,14 @@ After calling Select, you'd be able to chain other linq methods such as `First() ```cs [Fact] -public void use_select_to_another_type_with_first() +public async Task use_select_to_another_type_with_first() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => new UserName { Name = x.FirstName }) .FirstOrDefault() @@ -138,7 +138,7 @@ Marten has the ability to use the `SelectMany()` operator to issue queries again ```cs [Fact] -public void can_do_simple_select_many_against_simple_array() +public async Task can_do_simple_select_many_against_simple_array() { var product1 = new Product {Tags = new[] {"a", "b", "c"}}; var product2 = new Product {Tags = new[] {"b", "c", "d"}}; @@ -147,7 +147,7 @@ public void can_do_simple_select_many_against_simple_array() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/docs/documents/querying/linq/sql.md b/docs/documents/querying/linq/sql.md index e01be06a16..ce7c0e7129 100644 --- a/docs/documents/querying/linq/sql.md +++ b/docs/documents/querying/linq/sql.md @@ -6,12 +6,12 @@ Combine your Linq queries with raw SQL using the `MatchesSql(sql)` method like s ```cs [Fact] -public void query_with_matches_sql() +public async Task query_with_matches_sql() { using var session = theStore.LightweightSession(); var u = new User { FirstName = "Eric", LastName = "Smith" }; session.Store(u); - session.SaveChanges(); + await session.SaveChangesAsync(); var user = session.Query().Where(x => x.MatchesSql("data->> 'FirstName' = ?", "Eric")).Single(); user.LastName.ShouldBe("Smith"); diff --git a/docs/documents/querying/query-json.md b/docs/documents/querying/query-json.md index 64b03ae56b..e6cac46471 100644 --- a/docs/documents/querying/query-json.md +++ b/docs/documents/querying/query-json.md @@ -6,18 +6,18 @@ Marten stores documents as JSON, and sometimes it might be valuable to access th ```cs [Fact] -public void when_find_then_a_json_should_be_returned() +public async Task when_find_then_a_json_should_be_returned() { var issue = new Issue { Title = "Issue 2" }; theSession.Store(issue); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var json = theSession.Json.FindById(issue.Id); json.ShouldBe($"{{\"Id\": \"{issue.Id}\", \"Tags\": null, \"BugId\": null, \"Title\": \"Issue 2\", \"Number\": 0, \"Status\": null, \"AssigneeId\": null, \"ReporterId\": null}}"); } ``` -snippet source | anchor +snippet source | anchor There is also an asynchronous version: diff --git a/docs/documents/sessions.md b/docs/documents/sessions.md index bb09e20d87..769624b992 100644 --- a/docs/documents/sessions.md +++ b/docs/documents/sessions.md @@ -175,7 +175,7 @@ using (var session = theStore.IdentitySession()) // Now that 2nd document is no longer in the identity map session.Load(target2.Id).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -185,7 +185,7 @@ using (var session = theStore.QuerySession()) session.Load(target2.Id).ShouldBeNull(); } ``` -snippet source | anchor +snippet source | anchor ## Ejecting all pending changes from a Session diff --git a/docs/documents/storing.md b/docs/documents/storing.md index 4f38b9ca94..347a392b59 100644 --- a/docs/documents/storing.md +++ b/docs/documents/storing.md @@ -78,7 +78,7 @@ While `IDocumentSession.Store` will perform either insertion or update depending using (var session = theStore.LightweightSession()) { session.Insert(target); - session.SaveChanges(); + await session.SaveChangesAsync(); } ``` snippet source | anchor diff --git a/docs/events/appending.md b/docs/events/appending.md index d6eb1f040e..f452a9a02a 100644 --- a/docs/events/appending.md +++ b/docs/events/appending.md @@ -136,7 +136,7 @@ var departed = new MembersDeparted { Members = new[] { "Thom" } }; session.Events.Append(id, joined, departed); -session.SaveChanges(); +await session.SaveChangesAsync(); ``` snippet source | anchor @@ -171,7 +171,7 @@ builder.Services.AddMarten(opts => opts.Events.UseMandatoryStreamTypeDeclaration = true; }); ``` -snippet source | anchor +snippet source | anchor This causes a couple side effects that **force stricter usage of Marten**: diff --git a/docs/events/index.md b/docs/events/index.md index 0c5c52dfff..55266d7ca0 100644 --- a/docs/events/index.md +++ b/docs/events/index.md @@ -47,7 +47,7 @@ var store2 = DocumentStore.For(_ => _.Events.AddEventType(typeof(MonsterSlayed)); }); ``` -snippet source | anchor +snippet source | anchor ## Stream or Aggregate Types diff --git a/docs/events/projections/aggregate-projections.md b/docs/events/projections/aggregate-projections.md index 37b8b888aa..72e0ba96be 100644 --- a/docs/events/projections/aggregate-projections.md +++ b/docs/events/projections/aggregate-projections.md @@ -170,7 +170,7 @@ public class Payment } } ``` -snippet source | anchor +snippet source | anchor Just note that for single stream aggregations, your strong typed identifier types will need to wrap either a `Guid` or diff --git a/docs/events/projections/custom.md b/docs/events/projections/custom.md index 3c32a2bd0d..163ffca96b 100644 --- a/docs/events/projections/custom.md +++ b/docs/events/projections/custom.md @@ -71,7 +71,7 @@ public class QuestPatchTestProjection: IProjection } } ``` -snippet source | anchor +snippet source | anchor And the custom projection can be registered in your Marten `DocumentStore` like this: @@ -90,5 +90,5 @@ var store = DocumentStore.For(opts => opts.Projections.Add(new QuestPatchTestProjection(), ProjectionLifecycle.Async); }); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/events/querying.md b/docs/events/querying.md index eac0420e96..204a1240ea 100644 --- a/docs/events/querying.md +++ b/docs/events/querying.md @@ -271,12 +271,12 @@ We urge caution about this functionality because it requires a search against th ```cs [Fact] -public void can_query_against_event_type() +public async Task can_query_against_event_type() { theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryRawEventDataOnly().Count().ShouldBe(2); theSession.Events.QueryRawEventDataOnly().ToArray().SelectMany(x => x.Members).Distinct() diff --git a/docs/scenarios/copy-and-transform-stream.md b/docs/scenarios/copy-and-transform-stream.md index 7723fdb23e..93e1bff9e1 100644 --- a/docs/scenarios/copy-and-transform-stream.md +++ b/docs/scenarios/copy-and-transform-stream.md @@ -20,7 +20,7 @@ var slayed2 = new MonsterSlayed { Name = "Dragon" }; using (var session = theStore.LightweightSession()) { session.Events.StartStream(started.Name,started, joined, slayed1, slayed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } ``` snippet source | anchor @@ -95,7 +95,7 @@ using (var session = theStore.LightweightSession()) }); // Transactionally update the streams. - session.SaveChanges(); + await session.SaveChangesAsync(); } ``` snippet source | anchor diff --git a/src/CoreTests/Bugs/Bug_1296_sessionlistener_updates.cs b/src/CoreTests/Bugs/Bug_1296_sessionlistener_updates.cs deleted file mode 100644 index d4a3975e68..0000000000 --- a/src/CoreTests/Bugs/Bug_1296_sessionlistener_updates.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Linq; -using Marten; -using Marten.Services; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; - -namespace CoreTests.Bugs; - -public class Bug_1296_sessionlistener_updates : BugIntegrationContext -{ - [Fact] - public void bug() - { - var user = new User(); - - using (var session = theStore.LightweightSession()) - { - session.Insert(user); - session.SaveChanges(); - } - - var updates = 0; - - using (var session = theStore.LightweightSession(new SessionOptions - { - Listeners = { new CustomDocumentSessionListener(work => - { - updates = work.UpdatesFor().Count(); - }) } - })) - { - var u = session.Load(user.Id); - u.FirstName = "updated"; - session.Update(u); - session.SaveChanges(); - } - - Assert.Equal(1, updates); - } - - public class CustomDocumentSessionListener: DocumentSessionListenerBase - { - private readonly Action onUpdate; - - public CustomDocumentSessionListener(Action onUpdate) - { - this.onUpdate = onUpdate; - } - - public override void BeforeSaveChanges(IDocumentSession session) - { - onUpdate(session.PendingChanges); - } - } - -} diff --git a/src/CoreTests/Bugs/Bug_616_not_possible_to_use_Serializable_transactions.cs b/src/CoreTests/Bugs/Bug_616_not_possible_to_use_Serializable_transactions.cs index e49f18bfd8..f957efc083 100644 --- a/src/CoreTests/Bugs/Bug_616_not_possible_to_use_Serializable_transactions.cs +++ b/src/CoreTests/Bugs/Bug_616_not_possible_to_use_Serializable_transactions.cs @@ -1,7 +1,9 @@ using System; using System.Data; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace CoreTests.Bugs; @@ -20,11 +22,11 @@ public void Substract(int value) public class Bug_616_not_possible_to_use_Serializable_transactions: IntegrationContext { [Fact] - public void conccurent_write_should_throw_an_exception() + public async Task conccurent_write_should_throw_an_exception() { var accountA = new Bug616Account { Id = Guid.NewGuid(), Amount = 100 }; theSession.Store(accountA); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session1 = theStore.DirtyTrackedSession(IsolationLevel.Serializable)) using (var session2 = theStore.DirtyTrackedSession(IsolationLevel.Serializable)) @@ -35,11 +37,11 @@ public void conccurent_write_should_throw_an_exception() var session2AcountA = session2.Load(accountA.Id); session2AcountA.Substract(350); - session1.SaveChanges(); + await session1.SaveChangesAsync(); - Assert.Throws(() => + await Should.ThrowAsync(async () => { - session2.SaveChanges(); + await session2.SaveChangesAsync(); }); } } @@ -47,4 +49,4 @@ public void conccurent_write_should_throw_an_exception() public Bug_616_not_possible_to_use_Serializable_transactions(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/CoreTests/SessionOptionsTests.cs b/src/CoreTests/SessionOptionsTests.cs index 04d3e38cc5..0b1f9778c3 100644 --- a/src/CoreTests/SessionOptionsTests.cs +++ b/src/CoreTests/SessionOptionsTests.cs @@ -219,7 +219,7 @@ public void can_override_pgcstring_timeout_in_sessionoptions() } [Fact] - public void session_with_custom_connection_reusable_after_saveChanges() + public async Task session_with_custom_connection_reusable_after_saveChanges() { var connectionStringBuilder = new NpgsqlConnectionStringBuilder(ConnectionSource.ConnectionString); @@ -237,8 +237,8 @@ public void session_with_custom_connection_reusable_after_saveChanges() using var session = documentStore.LightweightSession(options); session.Store(testObject); - session.SaveChanges(); - session.Load(testObject.Id).ShouldNotBeNull(); + await session.SaveChangesAsync(); + (await session.LoadAsync(testObject.Id)).ShouldNotBeNull(); } [Fact] diff --git a/src/CoreTests/create_database_Tests.cs b/src/CoreTests/create_database_Tests.cs index 1d2d2ce2eb..6a562f03db 100644 --- a/src/CoreTests/create_database_Tests.cs +++ b/src/CoreTests/create_database_Tests.cs @@ -103,7 +103,7 @@ await Should.ThrowAsync(async () => } [Fact] - public void can_use_existing_database_without_calling_into_create() + public async Task can_use_existing_database_without_calling_into_create() { var user1 = new User { FirstName = "User" }; var dbCreated = false; @@ -128,7 +128,7 @@ public void can_use_existing_database_without_calling_into_create() using var session = store.LightweightSession(); session.Store(user1); - session.SaveChanges(); + await session.SaveChangesAsync(); Assert.False(dbCreated); } diff --git a/src/CoreTests/retry_mechanism.cs b/src/CoreTests/retry_mechanism.cs index 585b49696e..2fec10db27 100644 --- a/src/CoreTests/retry_mechanism.cs +++ b/src/CoreTests/retry_mechanism.cs @@ -33,12 +33,12 @@ public async Task can_successfully_retry() } [Fact] - public void can_successfully_retry_sync() + public async Task can_successfully_retry_sync() { var sometimesFailingOperation1 = new SometimesFailingOperation(); theSession.QueueOperation(sometimesFailingOperation1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Only succeeds on the 3rd try sometimesFailingOperation1.Usage.ShouldBe(2); diff --git a/src/DaemonTests/StressTester.cs b/src/DaemonTests/StressTester.cs deleted file mode 100644 index 0a236bf2e5..0000000000 --- a/src/DaemonTests/StressTester.cs +++ /dev/null @@ -1,183 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Castle.Core.Logging; -using JasperFx.Core; -using Marten; -using Marten.Events.Aggregation; -using Marten.Events.Daemon.Resiliency; -using Marten.Testing.Harness; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Npgsql; -using Shouldly; -using Weasel.Postgresql; -using Xunit; -using Xunit.Abstractions; - -namespace DaemonTests; - -public class StressTester -{ - private readonly ITestOutputHelper _output; - - public StressTester(ITestOutputHelper output) - { - _output = output; - } - - //[Fact] - public async Task try_to_exhaust_connection_count() - { - var logger = new TestOutputMartenLogger(_output); - - using var store = DocumentStore.For(options => - { - options.DatabaseSchemaName = "stress"; - options.Connection(ConnectionSource.ConnectionString); - - - options.Logger(logger); - - options.Projections.AsyncMode = DaemonMode.Solo; - options.Events.AddEventType(typeof(Event1)); - options.Events.AddEventType(typeof(Event2)); - options.Events.AddEventType(typeof(Event3)); - options.Events.AddEventType(typeof(Event4)); - - options.Projections.Add(Marten.Events.Projections.ProjectionLifecycle.Async); - options.Projections.Add(Marten.Events.Projections.ProjectionLifecycle.Async); - }); - - var stopping = new CancellationTokenSource(); - stopping.CancelAfter(5.Minutes()); - - using var timer = new System.Timers.Timer(100); - timer.Elapsed += (e, v) => - { - using var session = store.LightweightSession(); - session.Events.StartStream(new Event1()); - session.SaveChanges(); - - }; - timer.Start(); - - using var daemon = await store.BuildProjectionDaemonAsync(logger:logger); - await daemon.StartAllAsync(); - - long lastCount = 0; - while (!stopping.IsCancellationRequested) - { - await Task.Delay(250, stopping.Token); - await using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString); - await conn.OpenAsync(stopping.Token); - var count = (long)(await conn.CreateCommand("select count(*) from pg_stat_activity;") - .ExecuteScalarAsync(stopping.Token))!; - - if (count != lastCount) - { - _output.WriteLine($">>>>>>>>>>>>>>>>>>>>>>>>>>>> open connections increased to {count} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); - lastCount = count; - } - - _output.WriteLine($">>> {count} open connections"); - - count.ShouldBeLessThan(25); - } - - await Task.Delay(30.Seconds()); - - - } -} - -public class PublishService : BackgroundService -{ - private readonly IDocumentStore _store; - private readonly ILogger _logger; - public PublishService(IDocumentStore store, ILogger logger) - { - _store = store; - _logger = logger; - } - protected override Task ExecuteAsync(CancellationToken stoppingToken) - { - _logger.LogInformation("starting PublishService"); - return Task.Run(() => - { - var timer = new System.Timers.Timer(1000); - timer.Elapsed += (e, v) => - { - _logger.LogInformation("Inserting event"); - using var session = _store.LightweightSession(); - session.Events.StartStream(new Event1()); - session.SaveChanges(); - session.Dispose(); - }; - timer.Start(); - - },stoppingToken); - } -} - -public class Event1 -{ - public Guid Id { get; set; } - public int Number { get; set; } -} - -public class Event2 -{ - public Guid Id { get; set; } - public int Number { get; set; } -} -public class Event3 -{ - public Guid Id { get; set; } - public int Number { get; set; } -} - -public class Event4 -{ - public Guid Id { get; set; } - public int Number { get; set; } -} - -public class View1 -{ - public Guid Id { get; set; } - public bool IsEvent1Applied { get; set; } - public bool IsEvent2Applied { get; set; } -} - -public class View2 -{ - public Guid Id { get; set; } - public bool IsEvent3Applied { get; set; } - public bool IsEvent4Applied { get; set; } -} - -public class View1Projection : SingleStreamProjection -{ - public void Apply(View1 v, Event1 e) - { - v.IsEvent1Applied = true; - } - public void Apply(View1 v, Event2 e) - { - v.IsEvent2Applied = true; - } -} -public class View2Projection : SingleStreamProjection -{ - - public void Apply(View2 v, Event3 e) - { - v.IsEvent3Applied = true; - } - public void Apply(View2 v, Event4 e) - { - v.IsEvent4Applied = true; - } -} diff --git a/src/DocumentDbTests/Bugs/BigIntergerTests.cs b/src/DocumentDbTests/Bugs/BigIntegerTests.cs similarity index 79% rename from src/DocumentDbTests/Bugs/BigIntergerTests.cs rename to src/DocumentDbTests/Bugs/BigIntegerTests.cs index 582d10c3d7..76b52b3b71 100644 --- a/src/DocumentDbTests/Bugs/BigIntergerTests.cs +++ b/src/DocumentDbTests/Bugs/BigIntegerTests.cs @@ -1,4 +1,5 @@ using System.Numerics; +using System.Threading.Tasks; using Marten.Services.Json; using Marten.Testing.Harness; using Shouldly; @@ -11,7 +12,7 @@ public class BigIntegerTests : BugIntegrationContext private static readonly string LargerThanLongValue = "123456789012345678901234567890123456789012345678901234567890"; [Fact] - public void When_Querying_Using_Newtonsoft_Json_Should_Persist_And_Fetch_BigInteger_Values() + public async Task When_Querying_Using_Newtonsoft_Json_Should_Persist_And_Fetch_BigInteger_Values() { StoreOptions(options => { @@ -26,19 +27,19 @@ public void When_Querying_Using_Newtonsoft_Json_Should_Persist_And_Fetch_BigInte var obj = new BigIntegerObject { Id = 1, Value = BigInteger.Parse(LargerThanLongValue) }; session.Store(obj); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) { - var result = session.Load(1); + var result = await session.LoadAsync(1); result.Value.ToString().ShouldBe(LargerThanLongValue); } } [Fact] - public void When_Querying_Using_SystemTextJson_Should_Persist_And_Fetch_BigInteger_Values() + public async Task When_Querying_Using_SystemTextJson_Should_Persist_And_Fetch_BigInteger_Values() { StoreOptions(options => { @@ -53,19 +54,19 @@ public void When_Querying_Using_SystemTextJson_Should_Persist_And_Fetch_BigInteg var obj = new BigIntegerObject { Id = 1, Value = BigInteger.Parse(LargerThanLongValue) }; session.Store(obj); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) { - var result = session.Load(1); + var result = await session.LoadAsync(1); result.Value.ToString().ShouldBe(LargerThanLongValue); } } [Fact] - public void When_Stored_With_Newtonsoft_And_Fetched_With_STJ_Should_Succeed() + public async Task When_Stored_With_Newtonsoft_And_Fetched_With_STJ_Should_Succeed() { StoreOptions(options => { @@ -80,7 +81,7 @@ public void When_Stored_With_Newtonsoft_And_Fetched_With_STJ_Should_Succeed() var obj = new BigIntegerObject { Id = 1, Value = BigInteger.Parse(LargerThanLongValue) }; session.Store(obj); - session.SaveChanges(); + await session.SaveChangesAsync(); } StoreOptions(options => @@ -93,14 +94,14 @@ public void When_Stored_With_Newtonsoft_And_Fetched_With_STJ_Should_Succeed() using (var session = theStore.QuerySession()) { - var result = session.Load(1); + var result = await session.LoadAsync(1); result.Value.ToString().ShouldBe(LargerThanLongValue); } } [Fact] - public void When_Stored_With_STJ_And_Fetched_With_Newtonsoft_Should_Succeed() + public async Task When_Stored_With_STJ_And_Fetched_With_Newtonsoft_Should_Succeed() { StoreOptions(options => { @@ -115,7 +116,7 @@ public void When_Stored_With_STJ_And_Fetched_With_Newtonsoft_Should_Succeed() var obj = new BigIntegerObject { Id = 1, Value = BigInteger.Parse(LargerThanLongValue) }; session.Store(obj); - session.SaveChanges(); + await session.SaveChangesAsync(); } StoreOptions(options => @@ -128,7 +129,7 @@ public void When_Stored_With_STJ_And_Fetched_With_Newtonsoft_Should_Succeed() using (var session = theStore.QuerySession()) { - var result = session.Load(1); + var result = await session.LoadAsync(1); result.Value.ToString().ShouldBe(LargerThanLongValue); } diff --git a/src/DocumentDbTests/Bugs/Bug_1060_invalid_cast_exception_on_doc_with_subclass.cs b/src/DocumentDbTests/Bugs/Bug_1060_invalid_cast_exception_on_doc_with_subclass.cs index 6d5fd7ba46..015e6eb47a 100644 --- a/src/DocumentDbTests/Bugs/Bug_1060_invalid_cast_exception_on_doc_with_subclass.cs +++ b/src/DocumentDbTests/Bugs/Bug_1060_invalid_cast_exception_on_doc_with_subclass.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -10,14 +11,14 @@ namespace DocumentDbTests.Bugs; public class Bug_1060_invalid_cast_exception_on_doc_with_subclass: BugIntegrationContext { [Fact] - public void can_issue_query_on_doc_hierarchy_with_include() + public async Task can_issue_query_on_doc_hierarchy_with_include() { - StoreOptions(_ => + StoreOptions(opts => { - _.Schema.For() + opts.Schema.For() .AddSubClass() .AddSubClass(); - _.Schema.For(); + opts.Schema.For(); }); var user = new User { Id = System.Guid.NewGuid() }; @@ -25,31 +26,29 @@ public void can_issue_query_on_doc_hierarchy_with_include() var issue = new Issue { Id = System.Guid.NewGuid(), ReporterId = user.Id }; var issue2 = new Issue { Id = System.Guid.NewGuid(), ReporterId = admin.Id }; - using (var session = theStore.LightweightSession()) - { - session.Store(user); - session.Store(admin); - session.Store(issue); - session.Store(issue2); - session.SaveChanges(); + await using var session = theStore.LightweightSession(); + session.Store(user); + session.Store(admin); + session.Store(issue); + session.Store(issue2); + await session.SaveChangesAsync(); - var users = new List(); - var admins = new List(); + var users = new List(); + var admins = new List(); - var userIssues = session.Query() - .Include(i => i.ReporterId, users) - .ToList(); + var userIssues = session.Query() + .Include(i => i.ReporterId, users) + .ToList(); - var adminIssues = session.Query() - .Include(i => i.ReporterId, admins) - .ToList(); + var adminIssues = session.Query() + .Include(i => i.ReporterId, admins) + .ToList(); - // validate for parent document (base class) - users.Count(p => p != null).ShouldBe(2); + // validate for parent document (base class) + users.Count(p => p != null).ShouldBe(2); - // validate for subclass document - admins.Count(p => p != null).ShouldBe(1); - } + // validate for subclass document + admins.Count(p => p != null).ShouldBe(1); } } diff --git a/src/DocumentDbTests/Bugs/Bug_113_same_named_class_different_namespaces.cs b/src/DocumentDbTests/Bugs/Bug_113_same_named_class_different_namespaces.cs index 8c85ae3ed7..fc31d137fc 100644 --- a/src/DocumentDbTests/Bugs/Bug_113_same_named_class_different_namespaces.cs +++ b/src/DocumentDbTests/Bugs/Bug_113_same_named_class_different_namespaces.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten.Schema; using Marten.Testing.Harness; using Shouldly; @@ -9,14 +10,14 @@ public class Bug_113_same_named_class_different_namespaces: BugIntegrationContex { #region sample_can_select_from_the_same_table [Fact] - public void can_select_from_the_same_table() + public async Task can_select_from_the_same_table() { using var session = theStore.LightweightSession(); var product1 = new Area1.Product { Name = "Paper", Price = 10 }; session.Store(product1); - session.SaveChanges(); + await session.SaveChangesAsync(); - var product2 = session.Load(product1.Id); + var product2 = await session.LoadAsync(product1.Id); product2.Name.ShouldBe(product1.Name); } diff --git a/src/DocumentDbTests/Bugs/Bug_1155_null_duplicate_fields.cs b/src/DocumentDbTests/Bugs/Bug_1155_null_duplicate_fields.cs index 8df400b576..2e26d65dae 100644 --- a/src/DocumentDbTests/Bugs/Bug_1155_null_duplicate_fields.cs +++ b/src/DocumentDbTests/Bugs/Bug_1155_null_duplicate_fields.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -11,12 +12,12 @@ namespace DocumentDbTests.Bugs; public class Bug_1155_null_duplicate_fields: BugIntegrationContext { [Fact] - public void when_enum_is_null_due_to_nullable_type() + public async Task when_enum_is_null_due_to_nullable_type() { - StoreOptions(_ => + StoreOptions(opts => { - _.Serializer(new JsonNetSerializer { EnumStorage = EnumStorage.AsInteger }); - _.Schema.For().Duplicate(t => t.NullableColor); + opts.Serializer(new JsonNetSerializer { EnumStorage = EnumStorage.AsInteger }); + opts.Schema.For().Duplicate(t => t.NullableColor); }); using (var session = theStore.LightweightSession()) @@ -27,7 +28,7 @@ public void when_enum_is_null_due_to_nullable_type() NullableColor = null }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -40,12 +41,12 @@ public void when_enum_is_null_due_to_nullable_type() } [Fact] - public void when_enum_is_null_due_to_nesting() + public async Task when_enum_is_null_due_to_nesting() { - StoreOptions(_ => + StoreOptions(opts => { - _.Serializer(new JsonNetSerializer { EnumStorage = EnumStorage.AsInteger }); - _.Schema.For().Duplicate(t => t.Inner.Color); + opts.Serializer(new JsonNetSerializer { EnumStorage = EnumStorage.AsInteger }); + opts.Schema.For().Duplicate(t => t.Inner.Color); }); using (var session = theStore.LightweightSession()) @@ -56,7 +57,7 @@ public void when_enum_is_null_due_to_nesting() Inner = null }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -69,7 +70,7 @@ public void when_enum_is_null_due_to_nesting() } [Fact] - public void when_string_enum_is_null_due_to_nullable_type() + public async Task when_string_enum_is_null_due_to_nullable_type() { StoreOptions(_ => { @@ -85,7 +86,7 @@ public void when_string_enum_is_null_due_to_nullable_type() NullableColor = null }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -98,7 +99,7 @@ public void when_string_enum_is_null_due_to_nullable_type() } [Fact] - public void when_string_enum_is_null_due_to_nesting() + public async Task when_string_enum_is_null_due_to_nesting() { StoreOptions(_ => { @@ -114,7 +115,7 @@ public void when_string_enum_is_null_due_to_nesting() Inner = null }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -127,7 +128,7 @@ public void when_string_enum_is_null_due_to_nesting() } [Fact] - public void when_field_is_not_null_due_to_nesting() + public async Task when_field_is_not_null_due_to_nesting() { StoreOptions(_ => _.Schema.For().Duplicate(t => t.Inner.Number)); @@ -139,7 +140,7 @@ public void when_field_is_not_null_due_to_nesting() Inner = new Target { Number = 2 } }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -152,7 +153,7 @@ public void when_field_is_not_null_due_to_nesting() } [Fact] - public void when_field_is_null_due_to_nesting() + public async Task when_field_is_null_due_to_nesting() { StoreOptions(_ => _.Schema.For().Duplicate(t => t.Inner.Number)); @@ -164,7 +165,7 @@ public void when_field_is_null_due_to_nesting() Inner = null }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -177,11 +178,11 @@ public void when_field_is_null_due_to_nesting() } [Fact] - public void when_bulk_inserting_and_field_is_null_due_to_nesting() + public async Task when_bulk_inserting_and_field_is_null_due_to_nesting() { StoreOptions(_ => _.Schema.For().Duplicate(t => t.Inner.Number)); - theStore.BulkInsertDocuments(new[] + await theStore.BulkInsertDocumentsAsync(new[] { new Target { diff --git a/src/DocumentDbTests/Bugs/Bug_127_do_not_recreate_a_table_with_duplicated_string_field_Tests.cs b/src/DocumentDbTests/Bugs/Bug_127_do_not_recreate_a_table_with_duplicated_string_field_Tests.cs index 58e6dd2c0e..6465589336 100644 --- a/src/DocumentDbTests/Bugs/Bug_127_do_not_recreate_a_table_with_duplicated_string_field_Tests.cs +++ b/src/DocumentDbTests/Bugs/Bug_127_do_not_recreate_a_table_with_duplicated_string_field_Tests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Schema; using Marten.Testing.Harness; using Shouldly; @@ -12,7 +13,7 @@ namespace DocumentDbTests.Bugs; public class Bug_127_do_not_recreate_a_table_with_duplicated_string_field_Tests : BugIntegrationContext { [Fact] - public void does_not_recreate_the_table() + public async Task does_not_recreate_the_table() { var store1 = SeparateStore(_ => { @@ -27,7 +28,7 @@ public void does_not_recreate_the_table() session1.Store(new Team { Name = "Spurs" }); session1.Store(new Team { Name = "Thunder" }); - session1.SaveChanges(); + await session1.SaveChangesAsync(); session1.Query().Count().ShouldBe(3); } diff --git a/src/DocumentDbTests/Bugs/Bug_130_enable_case_insensitive_custom_sql_queries_Tests.cs b/src/DocumentDbTests/Bugs/Bug_130_enable_case_insensitive_custom_sql_queries_Tests.cs index 2042e4859b..ce7636ba88 100644 --- a/src/DocumentDbTests/Bugs/Bug_130_enable_case_insensitive_custom_sql_queries_Tests.cs +++ b/src/DocumentDbTests/Bugs/Bug_130_enable_case_insensitive_custom_sql_queries_Tests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -10,12 +11,12 @@ namespace DocumentDbTests.Bugs; public class Bug_130_enable_case_insensitive_custom_sql_queries_Tests: BugIntegrationContext { [Fact] - public void query() + public async Task query() { var entity = new Target(); theSession.Store(entity); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query($"SELECT data FROM {SchemaName}.mt_doc_target").Single().Id.ShouldBe(entity.Id); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_1563_user_friendly_warning_about_public_type.cs b/src/DocumentDbTests/Bugs/Bug_1563_user_friendly_warning_about_public_type.cs index 5878b32a22..1998924d6b 100644 --- a/src/DocumentDbTests/Bugs/Bug_1563_user_friendly_warning_about_public_type.cs +++ b/src/DocumentDbTests/Bugs/Bug_1563_user_friendly_warning_about_public_type.cs @@ -1,7 +1,9 @@ using System; +using System.Threading.Tasks; using JasperFx.Core.Reflection; using Marten.Schema; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace DocumentDbTests.Bugs; @@ -15,18 +17,18 @@ internal class InternalDoc } [Fact] - public void good_error_on_non_public_type() + public async Task good_error_on_non_public_type() { var expectedMessage = $"Requested document type '{typeof(InternalDoc).FullNameInCode()}' must be scoped as 'public'"; - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { var doc = new InternalDoc(); theSession.Store(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); }); - ex.Message.ShouldContain(expectedMessage); + ex.Message.ShouldContain(expectedMessage, Case.Insensitive); } } diff --git a/src/DocumentDbTests/Bugs/Bug_2018_fts_string_list.cs b/src/DocumentDbTests/Bugs/Bug_2018_fts_string_list.cs index cc3c104d54..1ce186f9fd 100644 --- a/src/DocumentDbTests/Bugs/Bug_2018_fts_string_list.cs +++ b/src/DocumentDbTests/Bugs/Bug_2018_fts_string_list.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Marten.Testing.Harness; using Xunit; @@ -30,7 +31,7 @@ public Bug_2018_fts_string_list() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void can_do_index_with_full_text_search() + public async Task can_do_index_with_full_text_search() { using var session = theStore.LightweightSession(); session.Store(new BugFullTextSearchFields() @@ -45,6 +46,6 @@ public void can_do_index_with_full_text_search() }, }); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Bugs/Bug_237_duplicate_indexing_Tests.cs b/src/DocumentDbTests/Bugs/Bug_237_duplicate_indexing_Tests.cs index 83f62bccd8..8365bfcd10 100644 --- a/src/DocumentDbTests/Bugs/Bug_237_duplicate_indexing_Tests.cs +++ b/src/DocumentDbTests/Bugs/Bug_237_duplicate_indexing_Tests.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ namespace DocumentDbTests.Bugs; public class Bug_237_duplicate_indexing_Tests: BugIntegrationContext { [Fact] - public void save() + public async Task save() { StoreOptions(_ => { @@ -18,7 +19,7 @@ public void save() }); theSession.Store(new Issue()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_274_cyclic_dependency_found_Tests.cs b/src/DocumentDbTests/Bugs/Bug_274_cyclic_dependency_found_Tests.cs index 1b1a722aba..c7708770e3 100644 --- a/src/DocumentDbTests/Bugs/Bug_274_cyclic_dependency_found_Tests.cs +++ b/src/DocumentDbTests/Bugs/Bug_274_cyclic_dependency_found_Tests.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ namespace DocumentDbTests.Bugs; public class Bug_274_cyclic_dependency_found_Tests: BugIntegrationContext { [Fact] - public void save() + public async Task save() { StoreOptions(_ => { @@ -18,7 +19,7 @@ public void save() }); theSession.Store(new Issue()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_339_async_cache_problem.cs b/src/DocumentDbTests/Bugs/Bug_339_async_cache_problem.cs index 52669811d6..9eda2f3db1 100644 --- a/src/DocumentDbTests/Bugs/Bug_339_async_cache_problem.cs +++ b/src/DocumentDbTests/Bugs/Bug_339_async_cache_problem.cs @@ -16,7 +16,7 @@ public async Task pending_with_dirty_checks_async() await using (var session1 = theStore.LightweightSession()) { session1.Store(user1); - session1.SaveChanges(); + await session1.SaveChangesAsync(); } await using (var session2 = theStore.DirtyTrackedSession()) @@ -29,4 +29,4 @@ public async Task pending_with_dirty_checks_async() public Bug_339_async_cache_problem(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_495_concurrent_check_by_not_first_loading_from_the_session.cs b/src/DocumentDbTests/Bugs/Bug_495_concurrent_check_by_not_first_loading_from_the_session.cs index eedfddcd4a..3188bf83f0 100644 --- a/src/DocumentDbTests/Bugs/Bug_495_concurrent_check_by_not_first_loading_from_the_session.cs +++ b/src/DocumentDbTests/Bugs/Bug_495_concurrent_check_by_not_first_loading_from_the_session.cs @@ -1,8 +1,10 @@ using System; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Schema; using Marten.Services; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace DocumentDbTests.Bugs; @@ -17,7 +19,7 @@ public class Foo } [Fact] - public void cannot_overwrite_when_the_second_object_is_not_loaded_through_the_session_first() + public async Task cannot_overwrite_when_the_second_object_is_not_loaded_through_the_session_first() { var id = "foo/" + Guid.NewGuid().ToString("n"); @@ -25,18 +27,18 @@ public void cannot_overwrite_when_the_second_object_is_not_loaded_through_the_se { session.Store(new Foo { Id = id }); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Exception.ShouldBeThrownBy(() => + await Should.ThrowAsync(async () => { using (var session = theStore.LightweightSession()) { session.Store(new Foo { Id = id }); - session.SaveChanges(); + await session.SaveChangesAsync(); } }); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_635_operations_order_in_same_session.cs b/src/DocumentDbTests/Bugs/Bug_635_operations_order_in_same_session.cs index e30198a747..523fceb5f1 100644 --- a/src/DocumentDbTests/Bugs/Bug_635_operations_order_in_same_session.cs +++ b/src/DocumentDbTests/Bugs/Bug_635_operations_order_in_same_session.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -11,7 +12,7 @@ namespace DocumentDbTests.Bugs; public class Bug_635_operations_order_in_same_session: IntegrationContext { [Fact] - public void deletewhere_and_store() + public async Task deletewhere_and_store() { var batchSize = 256; @@ -20,7 +21,7 @@ public void deletewhere_and_store() theSession.Store(i % 2 == 0 ? new User { LastName = "batch-id1" } : new User { LastName = "batch-id2" }); } - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var batch = new List(); var newBatchSize = 2; @@ -37,7 +38,7 @@ public void deletewhere_and_store() //Then store all new documents, in this case they also match the delete criteria replaceSession.Store(batch.ToArray()); - replaceSession.SaveChanges(); + await replaceSession.SaveChangesAsync(); } using (var querySession = theStore.QuerySession()) diff --git a/src/DocumentDbTests/Bugs/Bug_654_document_session_delete_Tests.cs b/src/DocumentDbTests/Bugs/Bug_654_document_session_delete_Tests.cs index 32f85c4c2f..f6ba6c83b1 100644 --- a/src/DocumentDbTests/Bugs/Bug_654_document_session_delete_Tests.cs +++ b/src/DocumentDbTests/Bugs/Bug_654_document_session_delete_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -9,14 +10,14 @@ namespace DocumentDbTests.Bugs; public class Bug_654_document_session_delete_Tests: IntegrationContext { [Fact] - public void upsert_then_delete_should_delete() + public async Task upsert_then_delete_should_delete() { var issue = new Issue { Id = Guid.NewGuid() }; using var session = theStore.IdentitySession(); session.Store(issue); session.Delete(issue.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); var loadedIssue = session.Load(issue.Id); loadedIssue.ShouldBeNull(); diff --git a/src/DocumentDbTests/Bugs/Bug_673_multiple_version_assertions.cs b/src/DocumentDbTests/Bugs/Bug_673_multiple_version_assertions.cs index 239c8258be..2758603fea 100644 --- a/src/DocumentDbTests/Bugs/Bug_673_multiple_version_assertions.cs +++ b/src/DocumentDbTests/Bugs/Bug_673_multiple_version_assertions.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Events; using Marten.Testing.Harness; using Xunit; @@ -8,7 +9,7 @@ namespace DocumentDbTests.Bugs; public class Bug_673_multiple_version_assertions: IntegrationContext { [Fact] - public void replaces_the_max_version_assertion() + public async Task replaces_the_max_version_assertion() { var streamId = Guid.NewGuid(); @@ -16,7 +17,7 @@ public void replaces_the_max_version_assertion() { session.Events.Append(streamId, new WhateverEvent(), new WhateverEvent()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -28,12 +29,12 @@ public void replaces_the_max_version_assertion() // ... do some more stuff expectedVersion += 1; session.Events.Append(streamId, expectedVersion, new WhateverEvent()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void replaces_the_max_version_assertion_for_string_identity() + public async Task replaces_the_max_version_assertion_for_string_identity() { UseStreamIdentity(StreamIdentity.AsString); var streamId = Guid.NewGuid().ToString(); @@ -42,7 +43,7 @@ public void replaces_the_max_version_assertion_for_string_identity() { session.Events.Append(streamId, new WhateverEvent(), new WhateverEvent()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -54,7 +55,7 @@ public void replaces_the_max_version_assertion_for_string_identity() // ... do some more stuff expectedVersion += 1; session.Events.Append(streamId, expectedVersion, new WhateverEvent()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Bugs/Bug_902_generic_type_documents.cs b/src/DocumentDbTests/Bugs/Bug_902_generic_type_documents.cs index d532d31698..ac7546d2fe 100644 --- a/src/DocumentDbTests/Bugs/Bug_902_generic_type_documents.cs +++ b/src/DocumentDbTests/Bugs/Bug_902_generic_type_documents.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Marten.Testing.Harness; using Shouldly; using Xunit; @@ -9,7 +10,7 @@ namespace DocumentDbTests.Bugs; public class Bug_902_generic_type_documents: IntegrationContext { [Fact] - public void can_create_object_name() + public async Task can_create_object_name() { var doc2 = new MartenStoredState> { @@ -19,7 +20,7 @@ public void can_create_object_name() using (var session = theStore.LightweightSession()) { session.Store(doc2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -39,4 +40,4 @@ public class MartenStoredState public Guid Id = Guid.NewGuid(); public T Value { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_964_optimistic_concurrency_with_subclass.cs b/src/DocumentDbTests/Bugs/Bug_964_optimistic_concurrency_with_subclass.cs index 87315608c9..35b84863bc 100644 --- a/src/DocumentDbTests/Bugs/Bug_964_optimistic_concurrency_with_subclass.cs +++ b/src/DocumentDbTests/Bugs/Bug_964_optimistic_concurrency_with_subclass.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Services; using Marten.Testing.Harness; @@ -24,7 +25,7 @@ public Bug_964_optimistic_concurrency_with_subclass() } [Fact] - public void should_not_throw_a_ConcurrencyException() + public async Task should_not_throw_a_ConcurrencyException() { CloudStorageMinio minio1 = new CloudStorageMinio() { @@ -39,19 +40,19 @@ public void should_not_throw_a_ConcurrencyException() using (var session = theStore.LightweightSession()) { session.Insert(minio1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { session.UpdateExpectedVersion(minio1, minio1.Version); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void should_Throw_ConcurrencyException() + public async Task should_Throw_ConcurrencyException() { CloudStorageMinio minio1 = new CloudStorageMinio() { @@ -66,7 +67,7 @@ public void should_Throw_ConcurrencyException() using (var session = theStore.LightweightSession()) { session.Insert(minio1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -91,9 +92,9 @@ public void should_Throw_ConcurrencyException() // It throws ConcurrencyException because there is only one // exception - Exception.ShouldBeThrownBy(() => + await Should.ThrowAsync(async () => { - session.SaveChanges(); + await session.SaveChangesAsync(); }); } } diff --git a/src/DocumentDbTests/Bugs/Bug_986_duplicated_fields_with_int_array.cs b/src/DocumentDbTests/Bugs/Bug_986_duplicated_fields_with_int_array.cs index fec18ca7c6..3d61840b1d 100644 --- a/src/DocumentDbTests/Bugs/Bug_986_duplicated_fields_with_int_array.cs +++ b/src/DocumentDbTests/Bugs/Bug_986_duplicated_fields_with_int_array.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Schema; using Marten.Testing.Harness; using Xunit; @@ -8,14 +9,14 @@ namespace DocumentDbTests.Bugs; public class Bug_986_duplicated_fields_with_int_array: IntegrationContext { [Fact] - public void can_insert_new_docs() + public async Task can_insert_new_docs() { var guyWithIntArray = new GuyWithIntArray { Numbers = new[] { 1, 3, 5, 7 } }; using (var session = theStore.LightweightSession()) { session.Store(guyWithIntArray); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -35,4 +36,4 @@ public class GuyWithIntArray [DuplicateField] public int[] Numbers { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/SelfForeignKeyBugs.cs b/src/DocumentDbTests/Bugs/SelfForeignKeyBugs.cs index 1973140680..eadc3af793 100644 --- a/src/DocumentDbTests/Bugs/SelfForeignKeyBugs.cs +++ b/src/DocumentDbTests/Bugs/SelfForeignKeyBugs.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Testing.Harness; using Xunit; @@ -7,7 +8,7 @@ namespace DocumentDbTests.Bugs; public class SelfForeignKeyBugs(DefaultStoreFixture fixture) : IntegrationContext(fixture) { [Fact] - public void unitofwork_sort_doesnt_break_self_foreign_keys() + public async Task unitofwork_sort_doesnt_break_self_foreign_keys() { StoreOptions(o => { @@ -33,7 +34,7 @@ public void unitofwork_sort_doesnt_break_self_foreign_keys() } } - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Bugs/SubClassForeignKeyBugs.cs b/src/DocumentDbTests/Bugs/SubClassForeignKeyBugs.cs index 12b0581879..994448ab0f 100644 --- a/src/DocumentDbTests/Bugs/SubClassForeignKeyBugs.cs +++ b/src/DocumentDbTests/Bugs/SubClassForeignKeyBugs.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten.Testing.Harness; using Xunit; @@ -40,13 +41,13 @@ public SubClassForeignKeyBugs() } [Fact] - public void ForeignKeyEntitiesToSubClassesShouldBeInsertedFirst() + public async Task ForeignKeyEntitiesToSubClassesShouldBeInsertedFirst() { using (var session = theStore.LightweightSession()) { var department = new Department { Id = 37 }; session.Store(department); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { @@ -57,12 +58,12 @@ public void ForeignKeyEntitiesToSubClassesShouldBeInsertedFirst() var address = new Address { ParentId = 222, Id = 42 }; session.Store(address); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void ForeignKeysOnSubClassesShouldInsertedFirst() + public async Task ForeignKeysOnSubClassesShouldInsertedFirst() { using var session = theStore.LightweightSession(); var department = new Department { Id = 1 }; @@ -71,6 +72,6 @@ public void ForeignKeysOnSubClassesShouldInsertedFirst() var employee = new Employee { Id = 2, DepartmentId = 1 }; session.Store(employee); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Bugs/ability_to_persist_generic_types.cs b/src/DocumentDbTests/Bugs/ability_to_persist_generic_types.cs index 1cd9a7a28b..1e87d8af3c 100644 --- a/src/DocumentDbTests/Bugs/ability_to_persist_generic_types.cs +++ b/src/DocumentDbTests/Bugs/ability_to_persist_generic_types.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Schema; using Marten.Testing.Harness; using Shouldly; @@ -18,14 +19,14 @@ public class TypeB { } public class ability_to_persist_generic_types: BugIntegrationContext { [Fact] - public void can_persist_and_load_generic_types() + public async Task can_persist_and_load_generic_types() { var doc1A = new GenericTypeToPersist(); var doc1B = new GenericTypeToPersist(); theSession.Store(doc1A); theSession.Store(doc1B); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2A = theSession.Load>(doc1A.Id); var doc2B = theSession.Load>(doc2A.Id); @@ -41,12 +42,12 @@ public ability_to_persist_generic_types() public class ability_to_persist_nested_generic_types: BugIntegrationContext { [Fact] - public void can_persist_and_load_generic_types() + public async Task can_persist_and_load_generic_types() { var doc1 = new NestedGenericTypeToPersist(); theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = theSession.Load>(doc1.Id); doc2.ShouldNotBeNull(); diff --git a/src/DocumentDbTests/Bugs/ability_to_persist_nested_types_Tests.cs b/src/DocumentDbTests/Bugs/ability_to_persist_nested_types_Tests.cs index b7851708a5..e585e5d230 100644 --- a/src/DocumentDbTests/Bugs/ability_to_persist_nested_types_Tests.cs +++ b/src/DocumentDbTests/Bugs/ability_to_persist_nested_types_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Harness; using Xunit; @@ -9,12 +10,12 @@ namespace DocumentDbTests.Bugs; public class ability_to_persist_nested_types_Tests: BugIntegrationContext { [Fact] - public void can_persist_and_load_nested_types() + public async Task can_persist_and_load_nested_types() { var doc1 = new MyDocument(); theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = theSession.Load(doc1.Id); doc2.ShouldNotBeNull(); @@ -25,4 +26,4 @@ public class MyDocument public Guid Id = Guid.NewGuid(); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs b/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs index 7a7b0f8dcd..65f47abc90 100644 --- a/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs +++ b/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs @@ -25,13 +25,13 @@ public optimistic_concurrency_with_update_method(OptimisticConcurrencyWithUpdate } [Fact] - public void can_update_with_optimistic_concurrency() + public async Task can_update_with_optimistic_concurrency() { var doc1 = new CoffeeShop(); using (var session1 = theStore.LightweightSession()) { session1.Insert(doc1); - session1.SaveChanges(); + await session1.SaveChangesAsync(); } using (var session2 = theStore.LightweightSession()) @@ -40,7 +40,7 @@ public void can_update_with_optimistic_concurrency() doc2.Name = "Mozart's"; session2.Update(doc2); - session2.SaveChanges(); + await session2.SaveChangesAsync(); } using (var session3 = theStore.QuerySession()) @@ -75,13 +75,13 @@ public async Task can_update_with_optimistic_concurrency_async() } [Fact] - public void update_with_stale_version_throws_exception() + public async Task update_with_stale_version_throws_exception() { var doc1 = new CoffeeShop(); using (var session1 = theStore.LightweightSession()) { session1.Insert(doc1); - session1.SaveChanges(); + await session1.SaveChangesAsync(); } using (var session2 = theStore.LightweightSession()) @@ -94,9 +94,9 @@ public void update_with_stale_version_throws_exception() session2.Update(doc2); - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { - session2.SaveChanges(); + await session2.SaveChangesAsync(); }); ex.Message.ShouldBe($"Optimistic concurrency check failed for {typeof(CoffeeShop).FullName} #{doc1.Id}"); diff --git a/src/DocumentDbTests/Concurrency/numeric_revisioning.cs b/src/DocumentDbTests/Concurrency/numeric_revisioning.cs index af96ef21fe..882a95d863 100644 --- a/src/DocumentDbTests/Concurrency/numeric_revisioning.cs +++ b/src/DocumentDbTests/Concurrency/numeric_revisioning.cs @@ -63,7 +63,7 @@ public void infer_configuration_from_IRevisioned_interface() } [Fact] - public void use_mapped_property_for_numeric_versioning() + public async Task use_mapped_property_for_numeric_versioning() { using var store = SeparateStore(_ => { @@ -79,7 +79,7 @@ public void use_mapped_property_for_numeric_versioning() var doc = new UnconventionallyVersionedDoc{Id = Guid.NewGuid(), Name = "Initial Name"}; session.Insert(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); var loaded = session.Load(doc.Id); loaded.UnconventionalVersion.ShouldBe(1); @@ -87,7 +87,7 @@ public void use_mapped_property_for_numeric_versioning() doc.Name = "New Name"; session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); loaded = session.Load(doc.Id); loaded.UnconventionalVersion.ShouldBe(2); @@ -98,7 +98,7 @@ public async Task happy_path_insert() { var doc = new RevisionedDoc { Name = "Tim" }; theSession.Insert(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var loaded = await theSession.LoadAsync(doc.Id); loaded.Version.ShouldBe(1); @@ -111,7 +111,7 @@ public async Task fetch_document_metadata() { var doc = new RevisionedDoc { Name = "Tim" }; theSession.Insert(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var metadata = await theSession.MetadataForAsync(doc); metadata.CurrentRevision.ShouldBe(1); @@ -140,7 +140,7 @@ public async Task store_with_no_revision_from_start_succeeds_with_revision_1() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (await theSession.MetadataForAsync(doc1)).CurrentRevision.ShouldBe(1); (await theSession.LoadAsync(doc1.Id)).Version.ShouldBe(1); @@ -151,12 +151,12 @@ public async Task store_twice_with_no_version_can_override() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); theSession.Store(new RevisionedDoc{Id = doc1.Id, Name = "Brad"}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (await theSession.LoadAsync(doc1.Id)).Name.ShouldBe("Brad"); } @@ -195,23 +195,23 @@ public async Task optimistic_concurrency_miss_with_try_update_revision() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Tron" }; theSession.UpdateRevision(doc2, doc1.Version + 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // No failure theSession.TryUpdateRevision(doc2, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (await theSession.LoadAsync(doc1.Id)).Name.ShouldBe("Tron"); } @@ -221,28 +221,28 @@ public async Task update_just_overwrites_and_increments_version() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; doc1.Version = 0; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; doc1.Version = 0; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Wrong", Version = 0}; theSession.UpdateRevision(doc2, doc1.Version + 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc2.Name = "Last"; doc2.Version = 0; theSession.Update(doc2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc3 = await theSession.LoadAsync(doc1.Id); doc2.Version = 0; @@ -259,19 +259,19 @@ public async Task update_revision_and_jumping_multiples() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Tron", Version = 2}; theSession.UpdateRevision(doc2, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (await theSession.LoadAsync(doc1.Id)).Name.ShouldBe("Tron"); (await theSession.MetadataForAsync(doc2)).CurrentRevision.ShouldBe(10); @@ -323,11 +323,11 @@ public async Task overwrite_increments_version() /********** START SYNC *******************/ [Fact] - public void happy_path_insert_sync() + public async Task happy_path_insert_sync() { var doc = new RevisionedDoc { Name = "Tim" }; theSession.Insert(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var loaded = theSession.Load(doc.Id); loaded.Version.ShouldBe(1); @@ -336,11 +336,11 @@ public void happy_path_insert_sync() } [Fact] - public void fetch_document_metadata_sync() + public async Task fetch_document_metadata_sync() { var doc = new RevisionedDoc { Name = "Tim" }; theSession.Insert(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var metadata = theSession.MetadataFor(doc); metadata.CurrentRevision.ShouldBe(1); @@ -365,110 +365,110 @@ public void bulk_inserts_sync() } [Fact] - public void store_with_no_revision_from_start_succeeds_with_revision_1_sync() + public async Task store_with_no_revision_from_start_succeeds_with_revision_1_sync() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (theSession.MetadataFor(doc1)).CurrentRevision.ShouldBe(1); (theSession.Load(doc1.Id)).Version.ShouldBe(1); } [Fact] - public void store_twice_with_no_version_can_override_sync() + public async Task store_twice_with_no_version_can_override_sync() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); theSession.Store(new RevisionedDoc{Id = doc1.Id, Name = "Brad"}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (theSession.Load(doc1.Id)).Name.ShouldBe("Brad"); } [Fact] - public void optimistic_concurrency_failure_with_update_revision_sync() + public async Task optimistic_concurrency_failure_with_update_revision_sync() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Wrong" }; theSession.UpdateRevision(doc2, doc1.Version + 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Should.Throw(async () => { theSession.UpdateRevision(doc2, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); }); } [Fact] - public void optimistic_concurrency_miss_with_try_update_revision_sync() + public async Task optimistic_concurrency_miss_with_try_update_revision_sync() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Tron" }; theSession.UpdateRevision(doc2, doc1.Version + 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // No failure theSession.TryUpdateRevision(doc2, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (theSession.Load(doc1.Id)).Name.ShouldBe("Tron"); } [Fact] - public void update_just_overwrites_and_increments_version_sync() + public async Task update_just_overwrites_and_increments_version_sync() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; doc1.Version = 0; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; doc1.Version = 0; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Wrong", Version = 0}; theSession.UpdateRevision(doc2, doc1.Version + 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc2.Name = "Last"; doc2.Version = 0; theSession.Update(doc2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc3 = theSession.Load(doc1.Id); doc2.Version = 0; @@ -479,50 +479,50 @@ public void update_just_overwrites_and_increments_version_sync() } [Fact] - public void update_revision_and_jumping_multiples_sync() + public async Task update_revision_and_jumping_multiples_sync() { var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Tron", Version = 2}; theSession.UpdateRevision(doc2, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); (theSession.Load(doc1.Id)).Name.ShouldBe("Tron"); (theSession.MetadataFor(doc2)).CurrentRevision.ShouldBe(10); } [Fact] - public void overwrite_increments_version_sync() + public async Task overwrite_increments_version_sync() { theSession.Logger = new TestOutputMartenLogger(_output); var doc1 = new RevisionedDoc { Name = "Tim" }; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Bill"; doc1.Version = 0; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); doc1.Name = "Dru"; doc1.Version = 0; theSession.Store(doc1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var doc2 = new RevisionedDoc { Id = doc1.Id, Name = "Wrong", Version = 2}; theSession.UpdateRevision(doc2, doc1.Version + 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session2 = theStore.OpenSession(new SessionOptions { ConcurrencyChecks = ConcurrencyChecks.Disabled }); @@ -533,13 +533,13 @@ public void overwrite_increments_version_sync() doc2.Name = "Last"; doc2.Version = 0; session2.Store(doc2); - session2.SaveChanges(); + await session2.SaveChangesAsync(); var doc3 = session2.Load(doc1.Id); doc3.Name.ShouldBe("Last"); doc3.Version.ShouldBe(5); - (session2.MetadataFor(doc1)).CurrentRevision.ShouldBe(5); + (await session2.MetadataForAsync(doc1)).CurrentRevision.ShouldBe(5); } diff --git a/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs b/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs index 16ec9bebc4..cd4b818e80 100644 --- a/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs +++ b/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs @@ -42,12 +42,12 @@ public void example_configuration() } [Fact] - public void can_insert_with_optimistic_concurrency_95() + public async Task can_insert_with_optimistic_concurrency_95() { using var session = theStore.LightweightSession(); var coffeeShop = new CoffeeShop(); session.Store(coffeeShop); - session.SaveChanges(); + await session.SaveChangesAsync(); SpecificationExtensions.ShouldNotBeNull(session.Load(coffeeShop.Id)); } @@ -64,24 +64,24 @@ public async Task can_insert_with_optimistic_concurrency_95_async() } [Fact] - public void can_store_same_document_multiple_times_with_optimistic_concurrency() + public async Task can_store_same_document_multiple_times_with_optimistic_concurrency() { var doc1 = new CoffeeShop(); using var session = theStore.LightweightSession(); session.Store(doc1); session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } [Fact] - public void can_update_with_optimistic_concurrency_95() + public async Task can_update_with_optimistic_concurrency_95() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -90,7 +90,7 @@ public void can_update_with_optimistic_concurrency_95() doc2.Name = "Mozart's"; session.Store(doc2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -126,13 +126,13 @@ public async Task can_update_with_optimistic_concurrency_95_async() #region sample_update_with_stale_version_standard [Fact] - public void update_with_stale_version_standard() + public async Task update_with_stale_version_standard() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } var session1 = theStore.DirtyTrackedSession(); @@ -147,11 +147,11 @@ public void update_with_stale_version_standard() session2Copy.Name = "Dominican Joe's"; // Should go through just fine - session2.SaveChanges(); + await session2.SaveChangesAsync(); - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { - session1.SaveChanges(); + await session1.SaveChangesAsync(); }); ex.Message.ShouldBe($"Optimistic concurrency check failed for {typeof(Shop).FullName} #{doc1.Id}"); @@ -162,22 +162,20 @@ public void update_with_stale_version_standard() session2.Dispose(); } - using (var query = theStore.QuerySession()) - { - query.Load(doc1.Id).Name.ShouldBe("Dominican Joe's"); - } + await using var query = theStore.QuerySession(); + query.Load(doc1.Id).Name.ShouldBe("Dominican Joe's"); } #endregion [Fact] - public void overwrite_with_stale_version_standard() + public async Task overwrite_with_stale_version_standard() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } #region sample_sample-override-optimistic-concurrency var session1 = theStore.DirtyTrackedSession(new SessionOptions @@ -197,9 +195,9 @@ public void overwrite_with_stale_version_standard() session2Copy.Name = "Dominican Joe's"; // Should go through just fine - session2.SaveChanges(); + await session2.SaveChangesAsync(); - session1.SaveChanges(); + await session1.SaveChangesAsync(); } finally { @@ -207,10 +205,8 @@ public void overwrite_with_stale_version_standard() session2.Dispose(); } - using (var query = theStore.QuerySession()) - { - query.Load(doc1.Id).Name.ShouldBe("Mozart's"); - } + await using var query = theStore.QuerySession(); + query.Load(doc1.Id).Name.ShouldBe("Mozart's"); } [Fact] @@ -257,13 +253,13 @@ public async Task update_with_stale_version_standard_async() } [Fact] - public void update_with_stale_version_standard_sync() + public async Task update_with_stale_version_standard_sync() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } var session1 = theStore.DirtyTrackedSession(); @@ -278,11 +274,11 @@ public void update_with_stale_version_standard_sync() session2Copy.Name = "Dominican Joe's"; // Should go through just fine - session2.SaveChanges(); + await session2.SaveChangesAsync(); - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { - session1.SaveChanges(); + await session1.SaveChangesAsync(); }); ex.Message.ShouldBe($"Optimistic concurrency check failed for {typeof(Shop).FullName} #{doc1.Id}"); @@ -293,20 +289,18 @@ public void update_with_stale_version_standard_sync() session2.Dispose(); } - using (var query = theStore.QuerySession()) - { - query.Load(doc1.Id).Name.ShouldBe("Dominican Joe's"); - } + await using var query = theStore.QuerySession(); + query.Load(doc1.Id).Name.ShouldBe("Dominican Joe's"); } [Fact] - public void can_do_multiple_updates_in_a_row_standard() + public async Task can_do_multiple_updates_in_a_row_standard() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.DirtyTrackedSession()) @@ -314,11 +308,11 @@ public void can_do_multiple_updates_in_a_row_standard() var doc2 = session.Load(doc1.Id); doc2.Name = "Mozart's"; - session.SaveChanges(); + await session.SaveChangesAsync(); doc2.Name = "Cafe Medici"; - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -356,7 +350,7 @@ public async Task can_do_multiple_updates_in_a_row_standard_async() } [Fact] - public void update_multiple_docs_at_a_time_happy_path() + public async Task update_multiple_docs_at_a_time_happy_path() { var doc1 = new CoffeeShop(); var doc2 = new CoffeeShop(); @@ -364,7 +358,7 @@ public void update_multiple_docs_at_a_time_happy_path() using (var session = theStore.LightweightSession()) { session.Store(doc1, doc2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.DirtyTrackedSession()) @@ -375,7 +369,7 @@ public void update_multiple_docs_at_a_time_happy_path() var doc22 = session.Load(doc2.Id); doc22.Name = "Dominican Joe's"; - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -416,7 +410,7 @@ public async Task update_multiple_docs_at_a_time_happy_path_async() } [Fact] - public void update_multiple_docs_at_a_time_sad_path() + public async Task update_multiple_docs_at_a_time_sad_path() { var doc1 = new CoffeeShop(); var doc2 = new CoffeeShop(); @@ -424,7 +418,7 @@ public void update_multiple_docs_at_a_time_sad_path() using (var session = theStore.LightweightSession()) { session.Store(doc1, doc2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.DirtyTrackedSession()) @@ -440,12 +434,12 @@ public void update_multiple_docs_at_a_time_sad_path() other.Load(doc1.Id).Name = "Genuine Joe's"; other.Load(doc2.Id).Name = "Cafe Medici"; - other.SaveChanges(); + await other.SaveChangesAsync(); } - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { - session.SaveChanges(); + await session.SaveChangesAsync(); }); ex.InnerExceptions.OfType().Count().ShouldBe(2); @@ -491,13 +485,13 @@ public async Task update_multiple_docs_at_a_time_sad_path_async() #region sample_store_with_the_right_version [Fact] - public void store_with_the_right_version() + public async Task store_with_the_right_version() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } DocumentMetadata metadata; @@ -511,7 +505,7 @@ public void store_with_the_right_version() doc1.Name = "Mozart's"; session.UpdateExpectedVersion(doc1, metadata.CurrentVersion); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -555,13 +549,13 @@ public async Task store_with_the_right_version_async() } [Fact] - public void store_with_the_right_version_sad_path() + public async Task store_with_the_right_version_sad_path() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -571,9 +565,9 @@ public void store_with_the_right_version_sad_path() // Some random version that won't match session.UpdateExpectedVersion(doc1, Guid.NewGuid()); - Exception.ShouldBeThrownBy(() => + await Should.ThrowAsync(async () => { - session.SaveChanges(); + await session.SaveChangesAsync(); }); } } @@ -629,7 +623,7 @@ public async Task can_update_and_delete_related_documents() } [Fact] - public void can_update_and_delete_related_documents_synchronous() + public async Task can_update_and_delete_related_documents_synchronous() { var emp1 = new CoffeeShopEmployee(); var doc1 = new CoffeeShop(); @@ -639,7 +633,7 @@ public void can_update_and_delete_related_documents_synchronous() { session.Store(emp1); session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.DirtyTrackedSession()) @@ -650,27 +644,27 @@ public void can_update_and_delete_related_documents_synchronous() doc.Employees.Remove(emp.Id); session.Delete(emp); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void Bug_669_can_store_and_update_same_document_with_optimistic_concurrency_and_dirty_tracking() + public async Task Bug_669_can_store_and_update_same_document_with_optimistic_concurrency_and_dirty_tracking() { var doc1 = new CoffeeShop(); using var session = theStore.DirtyTrackedSession(); session.Store(doc1); doc1.Name = "New Name"; - session.SaveChanges(); + await session.SaveChangesAsync(); } [Fact] - public void can_insert_with_optimistic_concurrency() + public async Task can_insert_with_optimistic_concurrency() { using var session = theStore.LightweightSession(); var coffeeShop = new CoffeeShop(); session.Store(coffeeShop); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(coffeeShop.Id).ShouldNotBeNull(); } @@ -687,13 +681,13 @@ public async Task can_insert_with_optimistic_concurrency_94_async() } [Fact] - public void can_update_with_optimistic_concurrency() + public async Task can_update_with_optimistic_concurrency() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -702,7 +696,7 @@ public void can_update_with_optimistic_concurrency() doc2.Name = "Mozart's"; session.Store(doc2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -737,13 +731,13 @@ public async Task can_update_with_optimistic_concurrenc_async() } [Fact] - public void update_with_stale_version() + public async Task update_with_stale_version() { var doc1 = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(doc1); - session.SaveChanges(); + await session.SaveChangesAsync(); } var session1 = theStore.DirtyTrackedSession(); @@ -758,14 +752,13 @@ public void update_with_stale_version() session2Copy.Name = "Dominican Joe's"; // Should go through just fine - session2.SaveChanges(); + await session2.SaveChangesAsync(); - var ex = Exception.ShouldBeThrownBy(() => + var ex = await Should.ThrowAsync(async () => { - session1.SaveChanges(); + await session1.SaveChangesAsync(); }); - ex.Message.ShouldBe($"Optimistic concurrency check failed for {typeof(Shop).FullName} #{doc1.Id}"); } finally diff --git a/src/DocumentDbTests/Deleting/delete_a_single_document.cs b/src/DocumentDbTests/Deleting/delete_a_single_document.cs index afc8656fcf..9990bbd768 100644 --- a/src/DocumentDbTests/Deleting/delete_a_single_document.cs +++ b/src/DocumentDbTests/Deleting/delete_a_single_document.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -14,40 +15,38 @@ public delete_a_single_document(DefaultStoreFixture fixture): base(fixture) [Theory] [SessionTypes] - public void persist_and_delete_a_document_by_entity(DocumentTracking tracking) + public async Task persist_and_delete_a_document_by_entity(DocumentTracking tracking) { using var session = OpenSession(tracking); var user = new User { FirstName = "Mychal", LastName = "Thompson" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using (var session2 = theStore.LightweightSession()) { session2.Delete(user); - session2.SaveChanges(); + await session2.SaveChangesAsync(); } - using (var querySession = theStore.QuerySession()) - { - querySession.Load(user.Id).ShouldBeNull(); - } + await using var querySession = theStore.QuerySession(); + querySession.Load(user.Id).ShouldBeNull(); } [Fact] - public void persist_and_delete_a_document_by_id() + public async Task persist_and_delete_a_document_by_id() { using var session = theStore.LightweightSession(); var user = new User { FirstName = "Mychal", LastName = "Thompson" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using (var session2 = theStore.LightweightSession()) { session2.Delete(user.Id); - session2.SaveChanges(); + await session2.SaveChangesAsync(); } using (var querySession = theStore.QuerySession()) @@ -57,18 +56,18 @@ public void persist_and_delete_a_document_by_id() } [Fact] - public void persist_and_delete_by_id_documents_with_the_same_id() + public async Task persist_and_delete_by_id_documents_with_the_same_id() { var id = Guid.NewGuid(); using (var session = theStore.LightweightSession()) { var user = new User { Id = id, FirstName = "Mychal", LastName = "Thompson" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var target = new Target { Id = id }; session.Store(target); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -76,7 +75,7 @@ public void persist_and_delete_by_id_documents_with_the_same_id() session.Delete(id); session.Delete(id); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/DocumentDbTests/Deleting/delete_many_documents_by_query.cs b/src/DocumentDbTests/Deleting/delete_many_documents_by_query.cs index 0c09b3d96c..bbabdbc496 100644 --- a/src/DocumentDbTests/Deleting/delete_many_documents_by_query.cs +++ b/src/DocumentDbTests/Deleting/delete_many_documents_by_query.cs @@ -15,7 +15,7 @@ public class delete_many_documents_by_query : IntegrationContext private readonly ITestOutputHelper _output; [Fact] - public void can_delete_by_query() + public async Task can_delete_by_query() { var targets = Target.GenerateRandomData(50).ToArray(); for (var i = 0; i < 15; i++) @@ -30,7 +30,7 @@ public void can_delete_by_query() #region sample_DeleteWhere theSession.DeleteWhere(x => x.Double == 578); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #endregion theSession.Query().Count().ShouldBe(50 - initialCount); @@ -61,7 +61,7 @@ public async Task delete_where_with_sub_collection_querying() } [Fact] - public void can_delete_by_query_with_complex_where_clauses() + public async Task can_delete_by_query_with_complex_where_clauses() { var targets = Target.GenerateRandomData(50).ToArray(); for (var i = 0; i < 15; i++) @@ -75,7 +75,7 @@ public void can_delete_by_query_with_complex_where_clauses() theSession.DeleteWhere(x => x.Double == 578 && x.Number == current.Id); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(x => x.Double == 578 && x.Number == current.Id) .ShouldBe(0); @@ -85,7 +85,7 @@ public void can_delete_by_query_with_complex_where_clauses() [Fact] - public void in_a_mix_with_other_commands() + public async Task in_a_mix_with_other_commands() { var targets = Target.GenerateRandomData(50).ToArray(); for (var i = 0; i < 15; i++) @@ -99,7 +99,7 @@ public void in_a_mix_with_other_commands() theSession.Store(new User(), new User(), new User()); theSession.DeleteWhere(x => x.Double == 578); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(50 - initialCount); @@ -116,7 +116,7 @@ public class FailureInLife } [Fact] - public void can_delete_by_query_multiple() + public async Task can_delete_by_query_multiple() { var targets = new[] { new FailureInLife { Id = 1, What = 2 } }; @@ -126,7 +126,7 @@ public void can_delete_by_query_multiple() theSession.DeleteWhere(x => x.Id == id && x.What == what); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(0); diff --git a/src/DocumentDbTests/Deleting/deleting_multiple_documents.cs b/src/DocumentDbTests/Deleting/deleting_multiple_documents.cs index 4702240e1c..02d26d41da 100644 --- a/src/DocumentDbTests/Deleting/deleting_multiple_documents.cs +++ b/src/DocumentDbTests/Deleting/deleting_multiple_documents.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -11,7 +12,7 @@ public class deleting_multiple_documents: IntegrationContext { [Theory] [SessionTypes] - public void multiple_documents(DocumentTracking tracking) + public async Task multiple_documents(DocumentTracking tracking) { using var session = OpenSession(tracking); @@ -27,7 +28,7 @@ public void multiple_documents(DocumentTracking tracking) #endregion - session.SaveChanges(); + await session.SaveChangesAsync(); using (var documentSession = theStore.LightweightSession()) { @@ -38,7 +39,7 @@ public void multiple_documents(DocumentTracking tracking) documentSession.Delete(company2); - documentSession.SaveChanges(); + await documentSession.SaveChangesAsync(); } using (var querySession = theStore.QuerySession()) @@ -52,7 +53,7 @@ public void multiple_documents(DocumentTracking tracking) [Theory] [SessionTypes] - public void delete_multiple_types_of_documents_with_delete_objects(DocumentTracking tracking) + public async Task delete_multiple_types_of_documents_with_delete_objects(DocumentTracking tracking) { using var session = OpenSession(tracking); @@ -65,14 +66,14 @@ public void delete_multiple_types_of_documents_with_delete_objects(DocumentTrack session.StoreObjects(new object[] { user1, issue1, company1 }); - session.SaveChanges(); + await session.SaveChangesAsync(); // Delete a mix of documents types using (var documentSession = theStore.LightweightSession()) { documentSession.DeleteObjects(new object[] { user1, company1 }); - documentSession.SaveChanges(); + await documentSession.SaveChangesAsync(); } #endregion diff --git a/src/DocumentDbTests/Deleting/soft_deletes.cs b/src/DocumentDbTests/Deleting/soft_deletes.cs index 5f8982d808..f7520ed2fa 100644 --- a/src/DocumentDbTests/Deleting/soft_deletes.cs +++ b/src/DocumentDbTests/Deleting/soft_deletes.cs @@ -96,12 +96,12 @@ public async Task can_query_by_the_deleted_column_if_it_exists() } [Fact] - public void initial_state_of_deleted_columns() + public async Task initial_state_of_deleted_columns() { using var session = theStore.LightweightSession(); var user = new User(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user.Id); } @@ -131,29 +131,29 @@ private void assertDocumentIsHardDeleted(IDocumentSession session, object id) } [Fact] - public void soft_delete_a_document_row_state() + public async Task soft_delete_a_document_row_state() { using var session = theStore.LightweightSession(); var user = new User(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsMarkedAsDeleted(session, user.Id); } [Fact] - public void hard_delete_a_document_row_state() + public async Task hard_delete_a_document_row_state() { using var session = theStore.LightweightSession(); var user = new User(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, user.Id); } @@ -180,43 +180,43 @@ public async Task hard_delete_by_linq() } [Fact] - public void hard_delete_a_document_row_state_int() + public async Task hard_delete_a_document_row_state_int() { using var session = theStore.LightweightSession(); var doc = new IntDoc(); session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(doc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, doc.Id); } [Fact] - public void hard_delete_a_document_row_state_long() + public async Task hard_delete_a_document_row_state_long() { using var session = theStore.LightweightSession(); var doc = new LongDoc(); session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(doc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, doc.Id); } [Fact] - public void hard_delete_a_document_row_state_string() + public async Task hard_delete_a_document_row_state_string() { using var session = theStore.LightweightSession(); var doc = new StringDoc{Id = Guid.NewGuid().ToString()}; session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(doc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, doc.Id); } @@ -235,7 +235,7 @@ private static void userIsMarkedAsDeleted(IDocumentSession session, Guid userId) } [Fact] - public void soft_delete_a_document_by_where_row_state() + public async Task soft_delete_a_document_by_where_row_state() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -243,10 +243,10 @@ public void soft_delete_a_document_by_where_row_state() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user1.Id); userIsMarkedAsDeleted(session, user2.Id); @@ -254,7 +254,7 @@ public void soft_delete_a_document_by_where_row_state() } [Fact] - public void un_delete_a_document_by_where_row_state() + public async Task un_delete_a_document_by_where_row_state() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -264,17 +264,17 @@ public void un_delete_a_document_by_where_row_state() session.Logger = new TestOutputMartenLogger(_output); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user1.Id); userIsMarkedAsDeleted(session, user2.Id); userIsMarkedAsDeleted(session, user3.Id); session.UndoDeleteWhere(x => x.UserName == "bar"); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user1.Id); userIsNotMarkedAsDeleted(session, user2.Id); @@ -283,7 +283,7 @@ public void un_delete_a_document_by_where_row_state() #region sample_query_soft_deleted_docs [Fact] - public void query_soft_deleted_docs() + public async Task query_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -292,11 +292,11 @@ public void query_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // Deleting 'bar' and 'baz' session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, deleted docs should be filtered out session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -311,7 +311,7 @@ public void query_soft_deleted_docs() #region sample_query_maybe_soft_deleted_docs [Fact] - public void query_maybe_soft_deleted_docs() + public async Task query_maybe_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -320,10 +320,10 @@ public void query_maybe_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, all documents are returned session.Query().Where(x => x.MaybeDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -341,7 +341,7 @@ public void query_maybe_soft_deleted_docs() #region sample_query_is_soft_deleted_docs [Fact] - public void query_is_soft_deleted_docs() + public async Task query_is_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -350,10 +350,10 @@ public void query_is_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.IsDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -371,7 +371,7 @@ public void query_is_soft_deleted_docs() #region sample_query_soft_deleted_since [Fact] - public void query_is_soft_deleted_since_docs() + public async Task query_is_soft_deleted_since_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -380,14 +380,14 @@ public void query_is_soft_deleted_since_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); var epoch = session.MetadataFor(user3).DeletedAt; session.Delete(user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.DeletedSince(epoch.Value)).Select(x => x.UserName) .ToList().ShouldHaveTheSameElementsAs("jack"); @@ -396,7 +396,7 @@ public void query_is_soft_deleted_since_docs() #endregion [Fact] - public void query_is_soft_deleted_before_docs() + public async Task query_is_soft_deleted_before_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -405,13 +405,13 @@ public void query_is_soft_deleted_before_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user4); - session.SaveChanges(); + await session.SaveChangesAsync(); var epoch = session.MetadataFor(user4).DeletedAt; @@ -420,7 +420,7 @@ public void query_is_soft_deleted_before_docs() } [Fact] - public void top_level_of_hierarchy() + public async Task top_level_of_hierarchy() { @@ -431,10 +431,10 @@ public void top_level_of_hierarchy() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -446,7 +446,7 @@ public void top_level_of_hierarchy() } [Fact] - public void sub_level_of_hierarchy() + public async Task sub_level_of_hierarchy() { var user1 = new SuperUser { UserName = "foo" }; @@ -457,10 +457,10 @@ public void sub_level_of_hierarchy() using var session = theStore.LightweightSession(); session.StoreObjects(new User[] { user1, user2, user3, user4, user5 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -472,7 +472,7 @@ public void sub_level_of_hierarchy() } [Fact] - public void sub_level_of_hierarchy_maybe_deleted() + public async Task sub_level_of_hierarchy_maybe_deleted() { var user1 = new SuperUser { UserName = "foo" }; @@ -483,10 +483,10 @@ public void sub_level_of_hierarchy_maybe_deleted() using var session = theStore.LightweightSession(); session.StoreObjects(new User[] { user1, user2, user3, user4, user5 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.MaybeDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -500,7 +500,7 @@ public void sub_level_of_hierarchy_maybe_deleted() } [Fact] - public void sub_level_of_hierarchy_is_deleted() + public async Task sub_level_of_hierarchy_is_deleted() { var user1 = new SuperUser { UserName = "foo" }; @@ -511,10 +511,10 @@ public void sub_level_of_hierarchy_is_deleted() using var session = theStore.LightweightSession(); session.StoreObjects(new User[] { user1, user2, user3, user4, user5 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.IsDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -528,7 +528,7 @@ public void sub_level_of_hierarchy_is_deleted() } [Fact] - public void soft_deleted_documents_work_with_linq_include() + public async Task soft_deleted_documents_work_with_linq_include() { using var session = theStore.LightweightSession(); @@ -538,9 +538,9 @@ public void soft_deleted_documents_work_with_linq_include() session.Store(file1); var file2 = new File() { UserId = user.Id }; session.Store(file2); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(file2); - session.SaveChanges(); + await session.SaveChangesAsync(); var users = new List(); var files = session.Query().Include(u => u.UserId, users).ToList(); @@ -786,12 +786,12 @@ public async Task can_query_by_the_deleted_column_if_it_exists() } [Fact] - public void initial_state_of_deleted_columns() + public async Task initial_state_of_deleted_columns() { using var session = theStore.LightweightSession(); var user = new User(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user.Id); } @@ -821,29 +821,29 @@ private void assertDocumentIsHardDeleted(IDocumentSession session, object id) } [Fact] - public void soft_delete_a_document_row_state() + public async Task soft_delete_a_document_row_state() { using var session = theStore.LightweightSession(); var user = new User(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsMarkedAsDeleted(session, user.Id); } [Fact] - public void hard_delete_a_document_row_state() + public async Task hard_delete_a_document_row_state() { using var session = theStore.LightweightSession(); var user = new User(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, user.Id); } @@ -870,43 +870,43 @@ public async Task hard_delete_by_linq() } [Fact] - public void hard_delete_a_document_row_state_int() + public async Task hard_delete_a_document_row_state_int() { using var session = theStore.LightweightSession(); var doc = new IntDoc(); session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(doc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, doc.Id); } [Fact] - public void hard_delete_a_document_row_state_long() + public async Task hard_delete_a_document_row_state_long() { using var session = theStore.LightweightSession(); var doc = new LongDoc(); session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(doc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, doc.Id); } [Fact] - public void hard_delete_a_document_row_state_string() + public async Task hard_delete_a_document_row_state_string() { using var session = theStore.LightweightSession(); var doc = new StringDoc{Id = Guid.NewGuid().ToString()}; session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); session.HardDelete(doc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); assertDocumentIsHardDeleted(session, doc.Id); } @@ -925,7 +925,7 @@ private void userIsMarkedAsDeleted(IDocumentSession session, Guid userId) } [Fact] - public void soft_delete_a_document_by_where_row_state() + public async Task soft_delete_a_document_by_where_row_state() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -933,10 +933,10 @@ public void soft_delete_a_document_by_where_row_state() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user1.Id); userIsMarkedAsDeleted(session, user2.Id); @@ -944,7 +944,7 @@ public void soft_delete_a_document_by_where_row_state() } [Fact] - public void un_delete_a_document_by_where_row_state() + public async Task un_delete_a_document_by_where_row_state() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -954,17 +954,17 @@ public void un_delete_a_document_by_where_row_state() session.Logger = new TestOutputMartenLogger(_output); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user1.Id); userIsMarkedAsDeleted(session, user2.Id); userIsMarkedAsDeleted(session, user3.Id); session.UndoDeleteWhere(x => x.UserName == "bar"); - session.SaveChanges(); + await session.SaveChangesAsync(); userIsNotMarkedAsDeleted(session, user1.Id); userIsNotMarkedAsDeleted(session, user2.Id); @@ -973,7 +973,7 @@ public void un_delete_a_document_by_where_row_state() #region sample_query_soft_deleted_docs [Fact] - public void query_soft_deleted_docs() + public async Task query_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -982,11 +982,11 @@ public void query_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // Deleting 'bar' and 'baz' session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, deleted docs should be filtered out session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1001,7 +1001,7 @@ public void query_soft_deleted_docs() #region sample_query_maybe_soft_deleted_docs [Fact] - public void query_maybe_soft_deleted_docs() + public async Task query_maybe_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -1010,10 +1010,10 @@ public void query_maybe_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause, all documents are returned session.Query().Where(x => x.MaybeDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1031,7 +1031,7 @@ public void query_maybe_soft_deleted_docs() #region sample_query_is_soft_deleted_docs [Fact] - public void query_is_soft_deleted_docs() + public async Task query_is_soft_deleted_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -1040,10 +1040,10 @@ public void query_is_soft_deleted_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.IsDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1061,7 +1061,7 @@ public void query_is_soft_deleted_docs() #region sample_query_soft_deleted_since [Fact] - public void query_is_soft_deleted_since_docs() + public async Task query_is_soft_deleted_since_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -1070,14 +1070,14 @@ public void query_is_soft_deleted_since_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); var epoch = session.MetadataFor(user3).DeletedAt; session.Delete(user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.DeletedSince(epoch.Value)).Select(x => x.UserName) .ToList().ShouldHaveTheSameElementsAs("jack"); @@ -1086,7 +1086,7 @@ public void query_is_soft_deleted_since_docs() #endregion [Fact] - public void query_is_soft_deleted_before_docs() + public async Task query_is_soft_deleted_before_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -1095,13 +1095,13 @@ public void query_is_soft_deleted_before_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user4); - session.SaveChanges(); + await session.SaveChangesAsync(); var epoch = session.MetadataFor(user4).DeletedAt; @@ -1110,7 +1110,7 @@ public void query_is_soft_deleted_before_docs() } [Fact] - public void top_level_of_hierarchy() + public async Task top_level_of_hierarchy() { @@ -1121,10 +1121,10 @@ public void top_level_of_hierarchy() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1136,7 +1136,7 @@ public void top_level_of_hierarchy() } [Fact] - public void sub_level_of_hierarchy() + public async Task sub_level_of_hierarchy() { var user1 = new SuperUser { UserName = "foo" }; @@ -1147,10 +1147,10 @@ public void sub_level_of_hierarchy() using var session = theStore.LightweightSession(); session.StoreObjects(new User[] { user1, user2, user3, user4, user5 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1162,7 +1162,7 @@ public void sub_level_of_hierarchy() } [Fact] - public void sub_level_of_hierarchy_maybe_deleted() + public async Task sub_level_of_hierarchy_maybe_deleted() { var user1 = new SuperUser { UserName = "foo" }; @@ -1173,10 +1173,10 @@ public void sub_level_of_hierarchy_maybe_deleted() using var session = theStore.LightweightSession(); session.StoreObjects(new User[] { user1, user2, user3, user4, user5 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.MaybeDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1190,7 +1190,7 @@ public void sub_level_of_hierarchy_maybe_deleted() } [Fact] - public void sub_level_of_hierarchy_is_deleted() + public async Task sub_level_of_hierarchy_is_deleted() { var user1 = new SuperUser { UserName = "foo" }; @@ -1201,10 +1201,10 @@ public void sub_level_of_hierarchy_is_deleted() using var session = theStore.LightweightSession(); session.StoreObjects(new User[] { user1, user2, user3, user4, user5 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.DeleteWhere(x => x.UserName.StartsWith("b")); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.IsDeleted()).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -1218,7 +1218,7 @@ public void sub_level_of_hierarchy_is_deleted() } [Fact] - public void soft_deleted_documents_work_with_linq_include() + public async Task soft_deleted_documents_work_with_linq_include() { using var session = theStore.LightweightSession(); @@ -1228,9 +1228,9 @@ public void soft_deleted_documents_work_with_linq_include() session.Store(file1); var file2 = new File() { UserId = user.Id }; session.Store(file2); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(file2); - session.SaveChanges(); + await session.SaveChangesAsync(); var users = new List(); var files = session.Query().Include(u => u.UserId, users).ToList(); diff --git a/src/DocumentDbTests/ForeignKeys/foreign_keys.cs b/src/DocumentDbTests/ForeignKeys/foreign_keys.cs index bffb84aceb..1fea155799 100644 --- a/src/DocumentDbTests/ForeignKeys/foreign_keys.cs +++ b/src/DocumentDbTests/ForeignKeys/foreign_keys.cs @@ -1,4 +1,6 @@ using System; +using System.Threading.Tasks; +using Marten.Exceptions; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -20,7 +22,7 @@ public void can_insert_document_with_null_value_of_foreign_key() } [Fact] - public void can_insert_document_with_existing_value_of_foreign_key() + public async Task can_insert_document_with_existing_value_of_foreign_key() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Restrict); @@ -28,7 +30,7 @@ public void can_insert_document_with_existing_value_of_foreign_key() using (var session = theStore.LightweightSession()) { session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } var issue = new Issue { AssigneeId = user.Id }; @@ -43,16 +45,16 @@ public void cannot_insert_document_with_non_existing_value_of_foreign_key() var issue = new Issue { AssigneeId = Guid.NewGuid() }; - Should.Throw(() => + Should.Throw(async () => { using var session = theStore.LightweightSession(); session.Insert(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); }); } [Fact] - public void can_update_document_with_existing_value_of_foreign_key_to_other_existing_value() + public async Task can_update_document_with_existing_value_of_foreign_key_to_other_existing_value() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Restrict); @@ -64,7 +66,7 @@ public void can_update_document_with_existing_value_of_foreign_key_to_other_exis { session.Store(user, otherUser); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } issue.AssigneeId = otherUser.Id; @@ -73,7 +75,7 @@ public void can_update_document_with_existing_value_of_foreign_key_to_other_exis } [Fact] - public void can_update_document_with_existing_value_of_foreign_key_to_null() + public async Task can_update_document_with_existing_value_of_foreign_key_to_null() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Restrict); @@ -85,7 +87,7 @@ public void can_update_document_with_existing_value_of_foreign_key_to_null() { session.Store(user, otherUser); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } issue.AssigneeId = null; @@ -94,7 +96,7 @@ public void can_update_document_with_existing_value_of_foreign_key_to_null() } [Fact] - public void cannot_update_document_with_existing_value_of_foreign_key_to_not_existing() + public async Task cannot_update_document_with_existing_value_of_foreign_key_to_not_existing() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Restrict); @@ -106,23 +108,23 @@ public void cannot_update_document_with_existing_value_of_foreign_key_to_not_exi { session.Store(user, otherUser); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } issue.AssigneeId = Guid.NewGuid(); - Should.Throw(() => + await Should.ThrowAsync(async () => { using (var session = theStore.LightweightSession()) { session.Update(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } }); } [Fact] - public void can_delete_document_with_foreign_key() + public async Task can_delete_document_with_foreign_key() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Cascade); @@ -133,13 +135,13 @@ public void can_delete_document_with_foreign_key() { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { session.Delete(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -150,7 +152,7 @@ public void can_delete_document_with_foreign_key() } [Fact] - public void can_delete_document_that_is_referenced_by_foreignkey_with_cascadedeletes_from_other_document() + public async Task can_delete_document_that_is_referenced_by_foreignkey_with_cascadedeletes_from_other_document() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Cascade); @@ -161,13 +163,13 @@ public void can_delete_document_that_is_referenced_by_foreignkey_with_cascadedel { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -178,7 +180,7 @@ public void can_delete_document_that_is_referenced_by_foreignkey_with_cascadedel } [Fact] - public void cannot_delete_document_that_is_referenced_by_foreignkey_without_cascadedeletes_from_other_document() + public async Task cannot_delete_document_that_is_referenced_by_foreignkey_without_cascadedeletes_from_other_document() { ConfigureForeignKeyWithCascadingDeletes(CascadeAction.Restrict); @@ -189,15 +191,15 @@ public void cannot_delete_document_that_is_referenced_by_foreignkey_without_casc { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Should.Throw(() => + Should.Throw(async () => { using (var session = theStore.LightweightSession()) { session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } }); @@ -216,12 +218,12 @@ private void ConfigureForeignKeyWithCascadingDeletes(CascadeAction onDelete) }); } - private void ShouldProperlySave(Issue issue) + private async Task ShouldProperlySave(Issue issue) { using (var session = theStore.LightweightSession()) { session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -233,7 +235,7 @@ private void ShouldProperlySave(Issue issue) } [Fact] - public void persist_and_overwrite_foreign_key() + public async Task persist_and_overwrite_foreign_key() { StoreOptions(_ => { @@ -247,7 +249,7 @@ public void persist_and_overwrite_foreign_key() { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } issue.AssigneeId = user.Id; @@ -255,7 +257,7 @@ public void persist_and_overwrite_foreign_key() using (var session = theStore.LightweightSession()) { session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } issue.AssigneeId = null; @@ -263,12 +265,12 @@ public void persist_and_overwrite_foreign_key() using (var session = theStore.LightweightSession()) { session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void throws_exception_if_trying_to_delete_referenced_user() + public async Task throws_exception_if_trying_to_delete_referenced_user() { StoreOptions(_ => { @@ -285,21 +287,21 @@ public void throws_exception_if_trying_to_delete_referenced_user() { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Exception.ShouldBeThrownBy(() => + await Should.ThrowAsync(async () => { using (var session = theStore.LightweightSession()) { session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } }); } [Fact] - public void persist_without_referenced_user() + public async Task persist_without_referenced_user() { StoreOptions(_ => { @@ -310,12 +312,12 @@ public void persist_without_referenced_user() using (var session = theStore.LightweightSession()) { session.Store(new Issue()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void order_inserts() + public async Task order_inserts() { StoreOptions(_ => { @@ -332,7 +334,7 @@ public void order_inserts() session.Store(issue); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } [Fact] @@ -351,7 +353,7 @@ public void throws_exception_on_cyclic_dependency() } [Fact] - public void id_can_be_a_foreign_key() + public async Task id_can_be_a_foreign_key() { StoreOptions(_ => { @@ -365,7 +367,7 @@ public void id_can_be_a_foreign_key() { session.Store(node1); session.Store(node2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -375,7 +377,7 @@ public void id_can_be_a_foreign_key() node1.ShouldNotBeNull(); node2.ShouldNotBeNull(); session.Delete(node1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -385,7 +387,7 @@ public void id_can_be_a_foreign_key() } [Fact] - public void non_standard_id_can_be_a_foreign_key() + public async Task non_standard_id_can_be_a_foreign_key() { StoreOptions(_ => { @@ -401,7 +403,7 @@ public void non_standard_id_can_be_a_foreign_key() { session.Store(node1); session.Store(node2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -411,7 +413,7 @@ public void non_standard_id_can_be_a_foreign_key() node1.ShouldNotBeNull(); node2.ShouldNotBeNull(); session.Delete(node1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/DocumentDbTests/HierarchicalStorage/Bug_1247_end_to_end_query_with_include_and_document_hierarchy_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/Bug_1247_end_to_end_query_with_include_and_document_hierarchy_Tests.cs index 5d3d03cbca..bbf621f339 100644 --- a/src/DocumentDbTests/HierarchicalStorage/Bug_1247_end_to_end_query_with_include_and_document_hierarchy_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/Bug_1247_end_to_end_query_with_include_and_document_hierarchy_Tests.cs @@ -20,7 +20,7 @@ public Bug_1247_query_with_include_and_document_hierarchy_Tests(ITestOutputHelpe } // [Fact] flaky in CI - public void include_to_list_using_outer_join() + public async Task include_to_list_using_outer_join() { var user1 = new User(); var user2 = new User(); @@ -33,7 +33,7 @@ public void include_to_list_using_outer_join() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3, issue4); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); query.Logger = new TestOutputMartenLogger(_output); diff --git a/src/DocumentDbTests/HierarchicalStorage/Bug_1484_store_overloads_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/Bug_1484_store_overloads_Tests.cs index 68efff5f03..db440f7bcc 100644 --- a/src/DocumentDbTests/HierarchicalStorage/Bug_1484_store_overloads_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/Bug_1484_store_overloads_Tests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Shouldly; @@ -9,41 +10,41 @@ namespace DocumentDbTests.HierarchicalStorage; public class Bug_1484_store_overloads_Tests: end_to_end_document_hierarchy_usage_Tests { [Fact] - public void persist_and_count_single_entity() + public async Task persist_and_count_single_entity() { using var session = theStore.IdentitySession(); session.Store(admin1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count().ShouldBe(1); } [Fact] - public void persist_mutliple_entites_as_params_and_count() + public async Task persist_mutliple_entites_as_params_and_count() { using var session = theStore.IdentitySession(); session.Store(admin1, admin2); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count().ShouldBe(2); } [Fact] - public void persist_mutliple_entites_as_array_and_count() + public async Task persist_mutliple_entites_as_array_and_count() { using var session = theStore.IdentitySession(); session.Store(new[] { admin1, admin2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count().ShouldBe(2); } [Fact] - public void persist_mutliple_entites_as_enumerable_and_count() + public async Task persist_mutliple_entites_as_enumerable_and_count() { using var session = theStore.IdentitySession(); session.Store(new[] { admin1, admin2 }.AsEnumerable()); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count().ShouldBe(2); } diff --git a/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs index 8207621857..80ee8567d8 100644 --- a/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -10,12 +11,12 @@ namespace DocumentDbTests.HierarchicalStorage; public class delete_by_where_for_hierarchy_Tests: end_to_end_document_hierarchy_usage_Tests { [Fact] - public void can_delete_all_subclass() + public async Task can_delete_all_subclass() { - loadData(); + await loadData(); theSession.DeleteWhere(x => true); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(0); theSession.Query().Count().ShouldBe(2); @@ -23,12 +24,12 @@ public void can_delete_all_subclass() } [Fact] - public void can_delete_by_subclass() + public async Task can_delete_by_subclass() { - loadData(); + await loadData(); theSession.DeleteWhere(x => x.FirstName.StartsWith("D")); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(1); theSession.Query().Count().ShouldBe(2); @@ -36,12 +37,12 @@ public void can_delete_by_subclass() } [Fact] - public void can_delete_by_the_hierarchy() + public async Task can_delete_by_the_hierarchy() { - loadData(); + await loadData(); theSession.DeleteWhere(x => x.FirstName.StartsWith("D")); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Should delete one SuperUser and one AdminUser theSession.Query().Count().ShouldBe(1); diff --git a/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_usage_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_usage_Tests.cs index 1643f68a36..cc6f313db1 100644 --- a/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_usage_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_usage_Tests.cs @@ -40,20 +40,20 @@ protected end_to_end_document_hierarchy_usage_Tests() }); } - protected void loadData() + protected async Task loadData() { theSession.Store(user1, user2, admin1, admin2, super1, super2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } - protected IDocumentSession identitySessionWithData() + protected async Task identitySessionWithData() { var session = theStore.IdentitySession(); session.Store(user1, user2, admin1, admin2, super1, super2); - session.SaveChanges(); + await session.SaveChangesAsync(); return session; } } diff --git a/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_with_interface_tests.cs b/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_with_interface_tests.cs index c782dc392f..29b591dea2 100644 --- a/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_with_interface_tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/end_to_end_document_hierarchy_with_interface_tests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Harness; using Shouldly; using Xunit; @@ -23,25 +24,25 @@ public end_to_end_document_hierarchy_with_interface_tests() } [Fact] - public void persists_subclass() + public async Task persists_subclass() { var policy = new LinuxPolicy {Name = Guid.NewGuid().ToString()}; using (var session = theStore.LightweightSession()) { session.Store(policy); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void query_for_only_a_subclass_with_string_where_clause() + public async Task query_for_only_a_subclass_with_string_where_clause() { var policy = new LinuxPolicy {VersionId = Guid.NewGuid(), Name = Guid.NewGuid().ToString()}; using (var session = theStore.LightweightSession()) { session.Store(policy); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -53,13 +54,13 @@ public void query_for_only_a_subclass_with_string_where_clause() [Fact] - public void query_for_only_a_subclass_with_where_clause() + public async Task query_for_only_a_subclass_with_where_clause() { var policy = new LinuxPolicy {VersionId = Guid.NewGuid(), Name = Guid.NewGuid().ToString()}; using (var session = theStore.LightweightSession()) { session.Store(policy); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -68,4 +69,4 @@ public void query_for_only_a_subclass_with_where_clause() .VersionId.ShouldBe(policy.VersionId); } } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/HierarchicalStorage/persist_and_load_for_hierarchy_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/persist_and_load_for_hierarchy_Tests.cs index 80632486fc..9a7f061b97 100644 --- a/src/DocumentDbTests/HierarchicalStorage/persist_and_load_for_hierarchy_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/persist_and_load_for_hierarchy_Tests.cs @@ -10,15 +10,15 @@ namespace DocumentDbTests.HierarchicalStorage; public class persist_and_load_for_hierarchy_Tests: end_to_end_document_hierarchy_usage_Tests { [Fact] - public void persist_and_delete_subclass() + public async Task persist_and_delete_subclass() { using var session = theStore.IdentitySession(); session.Store(admin1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(admin1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(admin1.Id).ShouldBeNull(); session.Load(admin1.Id).ShouldBeNull(); @@ -26,53 +26,53 @@ public void persist_and_delete_subclass() [Fact] - public void persist_and_delete_subclass_2() + public async Task persist_and_delete_subclass_2() { using var session = theStore.IdentitySession(); session.Store(admin1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(admin1.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(admin1.Id).ShouldBeNull(); session.Load(admin1.Id).ShouldBeNull(); } [Fact] - public void persist_and_delete_top() + public async Task persist_and_delete_top() { using var session = theStore.IdentitySession(); session.Store(user1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user1.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(user1.Id).ShouldBeNull(); } [Fact] - public void persist_and_delete_top_2() + public async Task persist_and_delete_top_2() { using var session = theStore.IdentitySession(); session.Store(user1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Delete(user1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(user1.Id).ShouldBeNull(); } [Fact] - public void persist_and_load_subclass() + public async Task persist_and_load_subclass() { using var session = theStore.IdentitySession(); session.Store(admin1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(admin1.Id).ShouldBeTheSameAs(admin1); session.Load(admin1.Id).ShouldBeTheSameAs(admin1); @@ -87,7 +87,7 @@ public async Task persist_and_load_subclass_async() { await using var session = theStore.IdentitySession(); session.Store(admin1); - session.SaveChanges(); + await session.SaveChangesAsync(); (await session.LoadAsync(admin1.Id)).ShouldBeTheSameAs(admin1); (await session.LoadAsync(admin1.Id)).ShouldBeTheSameAs(admin1); @@ -100,11 +100,11 @@ public async Task persist_and_load_subclass_async() } [Fact] - public void persist_and_load_top_level() + public async Task persist_and_load_top_level() { using var session = theStore.IdentitySession(); session.Store(user1); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(user1.Id).ShouldBeTheSameAs(user1); diff --git a/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_Tests.cs index 33da846a63..5d7c647877 100644 --- a/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_Tests.cs @@ -8,11 +8,16 @@ namespace DocumentDbTests.HierarchicalStorage; -public class query_through_mixed_population_Tests: end_to_end_document_hierarchy_usage_Tests +public class query_through_mixed_population_Tests: end_to_end_document_hierarchy_usage_Tests, IAsyncLifetime { - public query_through_mixed_population_Tests() + public Task InitializeAsync() { - loadData(); + return loadData(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } [Fact] @@ -29,9 +34,9 @@ public void clean_by_subclass_only_deletes_the_one_subclass() [Fact] - public void identity_map_usage_from_select() + public async Task identity_map_usage_from_select() { - using var session = identitySessionWithData(); + using var session = await identitySessionWithData(); var users = session.Query().OrderBy(x => x.FirstName).ToArray(); users[0].ShouldBeTheSameAs(admin1); users[1].ShouldBeTheSameAs(super1); @@ -48,9 +53,9 @@ public void load_by_id_keys_from_base_class_clean() } [Fact] - public void load_by_id_keys_from_base_class_resolved_from_identity_map() + public async Task load_by_id_keys_from_base_class_resolved_from_identity_map() { - using var session = identitySessionWithData(); + using var session = await identitySessionWithData(); session.LoadMany(admin1.Id, admin2.Id) .ShouldHaveTheSameElementsAs(admin1, admin2); } @@ -58,7 +63,7 @@ public void load_by_id_keys_from_base_class_resolved_from_identity_map() [Fact] public async Task load_by_id_keys_from_base_class_resolved_from_identity_map_async() { - await using var session = identitySessionWithData(); + await using var session = await identitySessionWithData(); var users = await session.LoadManyAsync(admin1.Id, admin2.Id); users.ShouldHaveTheSameElementsAs(admin1, admin2); } @@ -86,9 +91,9 @@ public async Task load_by_id_with_mixed_results_fresh_async() } [Fact] - public void load_by_id_with_mixed_results_from_identity_map() + public async Task load_by_id_with_mixed_results_from_identity_map() { - using var session = identitySessionWithData(); + using var session = await identitySessionWithData(); session.LoadMany(admin1.Id, super1.Id, user1.Id) .ToArray().ShouldHaveTheSameElementsAs(admin1, super1, user1); } @@ -96,7 +101,7 @@ public void load_by_id_with_mixed_results_from_identity_map() [Fact] public async Task load_by_id_with_mixed_results_from_identity_map_async() { - await using var session = identitySessionWithData(); + await using var session = await identitySessionWithData(); var users = await session.LoadManyAsync(admin1.Id, super1.Id, user1.Id); users.OrderBy(x => x.FirstName).ShouldHaveTheSameElementsAs(admin1, super1, user1); } diff --git a/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_multi_tenanted.cs b/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_multi_tenanted.cs index 1c1506facb..e3aac995b2 100644 --- a/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_multi_tenanted.cs +++ b/src/DocumentDbTests/HierarchicalStorage/query_through_mixed_population_multi_tenanted.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -7,7 +8,7 @@ namespace DocumentDbTests.HierarchicalStorage; -public class query_through_mixed_population_multi_tenanted: OneOffConfigurationsContext +public class query_through_mixed_population_multi_tenanted: OneOffConfigurationsContext, IAsyncLifetime { public query_through_mixed_population_multi_tenanted() @@ -19,14 +20,19 @@ public query_through_mixed_population_multi_tenanted() _.Schema.For().AddSubClass().AddSubClass().Duplicate(x => x.UserName); }); - loadData(); + } - private void loadData() + public async Task InitializeAsync() { - using var session = theStore.LightweightSession("tenant_1"); + await using var session = theStore.LightweightSession("tenant_1"); session.Store(new User(), new AdminUser()); - session.SaveChanges(); + await session.SaveChangesAsync(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } [Fact] diff --git a/src/DocumentDbTests/Indexes/UniqueIndexTests.cs b/src/DocumentDbTests/Indexes/UniqueIndexTests.cs index 8d6865f875..feb4fcbe6c 100644 --- a/src/DocumentDbTests/Indexes/UniqueIndexTests.cs +++ b/src/DocumentDbTests/Indexes/UniqueIndexTests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Events.Projections; using Marten.Exceptions; using Marten.Schema; @@ -63,7 +64,7 @@ public UniqueIndexTests() } [Fact] - public void + public async Task given_two_documents_with_the_same_value_for_unique_field_with_multiple_properties_when_created_then_throws_exception() { //1. Create Events @@ -85,7 +86,7 @@ public void //3. Unique Exception Was thrown try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { @@ -94,7 +95,7 @@ public void } [Fact] - public void + public async Task given_two_documents_with_the_same_value_for_unique_field_with_single_property_when_created_then_throws_exception() { //1. Create Events @@ -111,7 +112,7 @@ public void //3. Unique Exception Was thrown try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { @@ -120,7 +121,7 @@ public void } [Fact] - public void + public async Task given_two_events_with_the_same_value_for_unique_field_with_multiple_properties_when_inline_transformation_is_applied_then_throws_exception() { //1. Create Events @@ -141,7 +142,7 @@ public void //3. Unique Exception Was thrown try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (MartenCommandException exception) { @@ -150,7 +151,7 @@ public void } [Fact] - public void + public async Task given_two_events_with_the_same_value_for_unique_field_with_single_property_when_inline_transformation_is_applied_then_throws_exception() { //1. Create Events @@ -168,7 +169,7 @@ public void //3. Unique Exception Was thrown try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { diff --git a/src/DocumentDbTests/Indexes/duplicated_field.cs b/src/DocumentDbTests/Indexes/duplicated_field.cs index c41d1b0898..4ebe4561a8 100644 --- a/src/DocumentDbTests/Indexes/duplicated_field.cs +++ b/src/DocumentDbTests/Indexes/duplicated_field.cs @@ -28,7 +28,7 @@ public duplicated_field(ITestOutputHelper testOutputHelper) } [Fact] - public void can_insert_document_with_duplicated_field_with_DuplicatedFieldEnumStorage_set_to_string() + public async Task can_insert_document_with_duplicated_field_with_DuplicatedFieldEnumStorage_set_to_string() { StoreOptions(options => { @@ -44,7 +44,7 @@ public void can_insert_document_with_duplicated_field_with_DuplicatedFieldEnumSt using (var session = theStore.LightweightSession()) { session.Insert(document); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -57,7 +57,7 @@ public void can_insert_document_with_duplicated_field_with_DuplicatedFieldEnumSt } [Fact] - public void can_insert_document_with_duplicated_field_with_not_null_constraint() + public async Task can_insert_document_with_duplicated_field_with_not_null_constraint() { StoreOptions(options => { @@ -77,7 +77,7 @@ public void can_insert_document_with_duplicated_field_with_not_null_constraint() using (var session = theStore.LightweightSession()) { session.Insert(document); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -91,7 +91,7 @@ public void can_insert_document_with_duplicated_field_with_not_null_constraint() } [Fact] - public void can_insert_document_with_duplicated_field_with_null_constraint() + public async Task can_insert_document_with_duplicated_field_with_null_constraint() { StoreOptions(options => { @@ -110,7 +110,7 @@ public void can_insert_document_with_duplicated_field_with_null_constraint() using (var session = theStore.LightweightSession()) { session.Insert(document); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -208,7 +208,7 @@ public void can_override_with_MartenRegistry() } [Fact] - public void duplicate_and_search_off_of_deep_accessor_by_number() + public async Task duplicate_and_search_off_of_deep_accessor_by_number() { var targets = Target.GenerateRandomData(10).ToArray(); StoreOptions(_ => @@ -217,7 +217,7 @@ public void duplicate_and_search_off_of_deep_accessor_by_number() }); targets.Each(x => theSession.Store(x)); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var thirdTarget = targets.ElementAt(2); @@ -227,7 +227,7 @@ public void duplicate_and_search_off_of_deep_accessor_by_number() } [Fact] - public void duplicate_and_search_off_of_deep_accessor_by_enum() + public async Task duplicate_and_search_off_of_deep_accessor_by_enum() { var targets = Target.GenerateRandomData(10).ToArray(); StoreOptions(_ => @@ -236,7 +236,7 @@ public void duplicate_and_search_off_of_deep_accessor_by_enum() }); targets.Each(x => theSession.Store(x)); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var thirdTarget = targets.ElementAt(2); @@ -246,7 +246,7 @@ public void duplicate_and_search_off_of_deep_accessor_by_enum() } [Fact] - public void duplicate_and_search_off_of_deep_accessor_by_date() + public async Task duplicate_and_search_off_of_deep_accessor_by_date() { var targets = Target.GenerateRandomData(10).ToArray(); StoreOptions(_ => @@ -255,7 +255,7 @@ public void duplicate_and_search_off_of_deep_accessor_by_date() }); targets.Each(x => theSession.Store(x)); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var thirdTarget = targets.ElementAt(2); diff --git a/src/DocumentDbTests/Indexes/full_text_index.cs b/src/DocumentDbTests/Indexes/full_text_index.cs index e4818bfbb3..40747463e5 100644 --- a/src/DocumentDbTests/Indexes/full_text_index.cs +++ b/src/DocumentDbTests/Indexes/full_text_index.cs @@ -195,7 +195,7 @@ public void using_more_than_one_full_text_index_through_store_options_with_diffe } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void using_full_text_query_through_query_session() + public async Task using_full_text_query_through_query_session() { #region sample_using_full_text_query_through_query_session @@ -217,7 +217,7 @@ public void using_full_text_query_through_query_session() session.Store(new User { FirstName = "Max", LastName = "Miller", UserName = "mmiller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo", UserName = "fzombo" }); session.Store(new User { FirstName = "Somebody", LastName = "Somewher", UserName = "somebody" }); - session.SaveChanges(); + await session.SaveChangesAsync(); result = session.Search("somebody"); } @@ -230,7 +230,7 @@ public void using_full_text_query_through_query_session() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void search_in_query_sample() + public async Task search_in_query_sample() { StoreOptions(_ => _.RegisterDocumentType()); @@ -240,7 +240,7 @@ public void search_in_query_sample() { session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" }); session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -259,7 +259,7 @@ public void search_in_query_sample() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void plain_text_search_in_query_sample() + public async Task plain_text_search_in_query_sample() { StoreOptions(_ => _.RegisterDocumentType()); @@ -269,7 +269,7 @@ public void plain_text_search_in_query_sample() { session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" }); session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -288,7 +288,7 @@ public void plain_text_search_in_query_sample() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void phrase_search_in_query_sample() + public async Task phrase_search_in_query_sample() { StoreOptions(_ => _.RegisterDocumentType()); @@ -298,7 +298,7 @@ public void phrase_search_in_query_sample() { session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" }); session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -317,7 +317,7 @@ public void phrase_search_in_query_sample() } [PgVersionTargetedFact(MinimumVersion = "11.0")] - public void web_search_in_query_sample() + public async Task web_search_in_query_sample() { StoreOptions(_ => _.RegisterDocumentType()); @@ -327,7 +327,7 @@ public void web_search_in_query_sample() { session.Store(new BlogPost { Id = expectedId, EnglishText = "somefilter" }); session.Store(new BlogPost { Id = Guid.NewGuid(), ItalianText = "somefilter" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -346,7 +346,7 @@ public void web_search_in_query_sample() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void text_search_combined_with_other_query_sample() + public async Task text_search_combined_with_other_query_sample() { StoreOptions(_ => _.RegisterDocumentType()); @@ -357,7 +357,7 @@ public void text_search_combined_with_other_query_sample() 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(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -377,7 +377,7 @@ public void text_search_combined_with_other_query_sample() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void text_search_with_non_default_regConfig_sample() + public async Task text_search_with_non_default_regConfig_sample() { StoreOptions(_ => _.RegisterDocumentType()); @@ -387,7 +387,7 @@ public void text_search_with_non_default_regConfig_sample() { session.Store(new BlogPost { Id = Guid.NewGuid(), EnglishText = "somefilter" }); session.Store(new BlogPost { Id = expectedId, ItalianText = "somefilter" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -418,7 +418,7 @@ public void should_search_with_store_options_for_specific_members() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void should_search_with_store_options_with_multipleIndexes() + public async Task should_search_with_store_options_with_multipleIndexes() { const string frenchRegConfig = "french"; const string italianRegConfig = "italian"; @@ -436,7 +436,7 @@ public void should_search_with_store_options_with_multipleIndexes() session.Store(new User { FirstName = "Jeremy", LastName = "Miller", UserName = "jmiller" }); session.Store(new User { FirstName = "Max", LastName = "Miller", UserName = "mmiller" }); session.Store(new User { FirstName = "Somebody", LastName = "Somewher", UserName = "somebody" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var italianResults = session.Search(searchFilter, italianRegConfig); @@ -452,7 +452,7 @@ public void should_search_with_store_options_with_multipleIndexes() } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void should_search_by_tenant_with_tenancy_conjoined() + public async Task should_search_by_tenant_with_tenancy_conjoined() { StoreOptions(_ => { @@ -471,7 +471,7 @@ public void should_search_by_tenant_with_tenancy_conjoined() using var session = theStore.LightweightSession(tenant); session.Store(new User { FirstName = searchFilter, LastName = "Miller", UserName = "lmiller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo", UserName = "fzombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } foreach (var tenant in tenants) @@ -485,7 +485,7 @@ public void should_search_by_tenant_with_tenancy_conjoined() } } - private void SearchShouldBeSuccessfulFor(Action configure) + private async Task SearchShouldBeSuccessfulFor(Action configure) { StoreOptions(configure); @@ -498,7 +498,7 @@ private void SearchShouldBeSuccessfulFor(Action configure) session.Store(new User { FirstName = "Jeremy", LastName = "Miller", UserName = "jmiller" }); session.Store(new User { FirstName = "Max", LastName = "Miller", UserName = "mmiller" }); session.Store(new User { FirstName = "Somebody", LastName = "Somewher", UserName = "somebody" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var results = session.Search(searchFilter); diff --git a/src/DocumentDbTests/Metadata/created_timestamp_queries.cs b/src/DocumentDbTests/Metadata/created_timestamp_queries.cs index f675271b06..98fc7a3cec 100644 --- a/src/DocumentDbTests/Metadata/created_timestamp_queries.cs +++ b/src/DocumentDbTests/Metadata/created_timestamp_queries.cs @@ -4,6 +4,7 @@ using Marten.Testing.Harness; using Shouldly; using System.Linq; +using System.Threading.Tasks; using Marten.Linq.CreatedAt; using Weasel.Postgresql.Tables; using Xunit; @@ -31,7 +32,7 @@ public class Customer [Fact] - public void query_created_before_docs() + public async Task query_created_before_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -40,10 +41,10 @@ public void query_created_before_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); var metadata = session.MetadataFor(user4); metadata.ShouldNotBeNull(); @@ -67,7 +68,7 @@ public void query_created_before_docs() } [Fact] - public void query_created_since_docs() + public async Task query_created_since_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -76,14 +77,14 @@ public void query_created_since_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2); - session.SaveChanges(); + await session.SaveChangesAsync(); var metadata = session.MetadataFor(user2); metadata.ShouldNotBeNull(); var epoch = metadata.CreatedAt; session.Store(user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query() diff --git a/src/DocumentDbTests/Metadata/end_to_end_versioned_docs.cs b/src/DocumentDbTests/Metadata/end_to_end_versioned_docs.cs index dc6232c8da..24dc2a0b55 100644 --- a/src/DocumentDbTests/Metadata/end_to_end_versioned_docs.cs +++ b/src/DocumentDbTests/Metadata/end_to_end_versioned_docs.cs @@ -12,7 +12,7 @@ namespace DocumentDbTests.Metadata; public class end_to_end_versioned_docs: IntegrationContext { [Fact] - public void save_initial_version_of_the_doc_and_see_the_initial_version_assigned() + public async Task save_initial_version_of_the_doc_and_see_the_initial_version_assigned() { var doc = new AttVersionedDoc(); @@ -21,7 +21,7 @@ public void save_initial_version_of_the_doc_and_see_the_initial_version_assigned session.VersionFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); session.VersionFor(doc).ShouldNotBeNull(); doc.Version.ShouldNotBe(Guid.Empty); @@ -46,7 +46,7 @@ public async Task save_initial_version_of_the_doc_and_see_the_initial_version_as } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void overwrite_behavior() + public async Task overwrite_behavior() { var originalVerion = Guid.Empty; var doc = new AttVersionedDoc(); @@ -56,7 +56,7 @@ public void overwrite_behavior() session.VersionFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); originalVerion = doc.Version; } @@ -81,11 +81,11 @@ public void overwrite_behavior() session2.Store(doc2); // save via session1 - session1.SaveChanges(); + await session1.SaveChangesAsync(); doc1.Version.ShouldNotBe(originalVerion); // overwrite successfully w/ session2 - session2.SaveChanges(); + await session2.SaveChangesAsync(); doc2.Version.ShouldNotBe(originalVerion); doc2.Version.ShouldNotBe(doc1.Version); } @@ -97,7 +97,7 @@ public void overwrite_behavior() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void overwrite_behavior_with_props() + public async Task overwrite_behavior_with_props() { var originalVerion = Guid.Empty; var doc = new PropVersionedDoc(); @@ -107,7 +107,7 @@ public void overwrite_behavior_with_props() session.VersionFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); originalVerion = doc.Version; } @@ -132,11 +132,11 @@ public void overwrite_behavior_with_props() session2.Store(doc2); // save via session1 - session1.SaveChanges(); + await session1.SaveChangesAsync(); doc1.Version.ShouldNotBe(originalVerion); // overwrite successfully w/ session2 - session2.SaveChanges(); + await session2.SaveChangesAsync(); doc2.Version.ShouldNotBe(originalVerion); doc2.Version.ShouldNotBe(doc1.Version); } diff --git a/src/DocumentDbTests/Metadata/fetching_entity_metadata.cs b/src/DocumentDbTests/Metadata/fetching_entity_metadata.cs index 80339b4a12..f795735398 100644 --- a/src/DocumentDbTests/Metadata/fetching_entity_metadata.cs +++ b/src/DocumentDbTests/Metadata/fetching_entity_metadata.cs @@ -21,14 +21,14 @@ public void total_miss_returns_null() #region sample_resolving_metadata [Fact] - public void hit_returns_values() + public async Task hit_returns_values() { var shop = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(shop); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -81,14 +81,14 @@ public async Task hit_returns_values_async() } [Fact] - public void created_timestamp_metadata_returns_default() + public async Task created_timestamp_metadata_returns_default() { var shop = new CoffeeShop(); using (var session = theStore.LightweightSession()) { session.Store(shop); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -118,7 +118,7 @@ public async Task created_timestamp_metadata_returns_default_async() } [Fact] - public void created_timestamp_metadata_returns_timestamp() + public async Task created_timestamp_metadata_returns_timestamp() { StoreOptions(_ => { @@ -130,7 +130,7 @@ public void created_timestamp_metadata_returns_timestamp() using (var session = theStore.LightweightSession()) { session.Store(shop); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/DocumentDbTests/Metadata/last_modified_queries.cs b/src/DocumentDbTests/Metadata/last_modified_queries.cs index 7fdceaeda7..c516bb115d 100644 --- a/src/DocumentDbTests/Metadata/last_modified_queries.cs +++ b/src/DocumentDbTests/Metadata/last_modified_queries.cs @@ -50,7 +50,7 @@ public async Task sample_usage(IQuerySession session) [Fact] - public void query_modified_since_docs() + public async Task query_modified_since_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -59,14 +59,14 @@ public void query_modified_since_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); var metadata = session.MetadataFor(user4); metadata.ShouldNotBeNull(); var epoch = metadata.LastModified; session.Store(user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.ModifiedSince(epoch)) @@ -82,7 +82,7 @@ public void query_modified_since_docs() } [Fact] - public void query_modified_before_docs() + public async Task query_modified_before_docs() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -91,10 +91,10 @@ public void query_modified_before_docs() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); var metadata = session.MetadataFor(user4); metadata.ShouldNotBeNull(); diff --git a/src/DocumentDbTests/Metadata/projecting_metadata_to_documents.cs b/src/DocumentDbTests/Metadata/projecting_metadata_to_documents.cs index 04c8e47000..3ad242edff 100644 --- a/src/DocumentDbTests/Metadata/projecting_metadata_to_documents.cs +++ b/src/DocumentDbTests/Metadata/projecting_metadata_to_documents.cs @@ -53,7 +53,7 @@ public void set_the_metadata_projections_via_attributes() } [Fact] - public void doc_has_projected_data_after_storage() + public async Task doc_has_projected_data_after_storage() { StoreOptions(c => { @@ -67,7 +67,7 @@ public void doc_has_projected_data_after_storage() { session.Store(doc); session.MetadataFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -78,7 +78,7 @@ public void doc_has_projected_data_after_storage() } [Fact] - public void doc_metadata_is_read_only_on_store() + public async Task doc_metadata_is_read_only_on_store() { var doc = new DocWithAttributeMeta(); @@ -88,7 +88,7 @@ public void doc_metadata_is_read_only_on_store() doc.Version = Guid.Empty; session.Store(doc); session.MetadataFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -105,7 +105,7 @@ public void doc_metadata_is_read_only_on_store() [Fact] - public void doc_metadata_is_mapped_for_query_includes() + public async Task doc_metadata_is_mapped_for_query_includes() { StoreOptions(c => { @@ -122,7 +122,7 @@ public void doc_metadata_is_mapped_for_query_includes() session.Store(doc); session.MetadataFor(include).ShouldBeNull(); session.MetadataFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -138,7 +138,7 @@ public void doc_metadata_is_mapped_for_query_includes() } [Fact] - public void doc_metadata_is_updated_for_user_supplied_query() + public async Task doc_metadata_is_updated_for_user_supplied_query() { StoreOptions(c => { @@ -152,7 +152,7 @@ public void doc_metadata_is_updated_for_user_supplied_query() { session.Store(doc); session.MetadataFor(doc).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -162,7 +162,7 @@ public void doc_metadata_is_updated_for_user_supplied_query() ShouldBeTestExtensions.ShouldNotBe(userQuery.LastModified, DateTimeOffset.MinValue); lastMod = userQuery.LastModified; session.Store(userQuery); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -234,7 +234,7 @@ public async Task doc_metadata_is_mapped_for_bulk_inserted_conjoined_tenant() (DateTime.UtcNow - loaded.LastModified.ToUniversalTime()).ShouldBeLessThan(TimeSpan.FromMinutes(1)); } - public void doc_metadata_is_mapped_for_doc_hierarchies() + public async Task doc_metadata_is_mapped_for_doc_hierarchies() { StoreOptions(c => { @@ -259,7 +259,7 @@ public void doc_metadata_is_mapped_for_doc_hierarchies() var emerald = new EmeraldGreenDocWithMeta { Description = "emerald doc" }; session.Store(doc, red, green, blue, emerald); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.IdentitySession()) @@ -276,7 +276,7 @@ public void doc_metadata_is_mapped_for_doc_hierarchies() ShouldBeStringTestExtensions.ShouldBe(redDocs.First().DocType, "red_doc_with_meta"); session.Delete(redDocs.First()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/MultiTenancy/UniqueIndexMultiTenantTests.cs b/src/DocumentDbTests/MultiTenancy/UniqueIndexMultiTenantTests.cs index 44e99fbe9c..8c95f6720c 100644 --- a/src/DocumentDbTests/MultiTenancy/UniqueIndexMultiTenantTests.cs +++ b/src/DocumentDbTests/MultiTenancy/UniqueIndexMultiTenantTests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Schema; using Marten.Schema.Indexing.Unique; @@ -45,7 +46,7 @@ public UniqueCodePerTenant() } [Fact] - public void given_two_documents_for_different_tenants_succeeds_using_attribute() + public async Task given_two_documents_for_different_tenants_succeeds_using_attribute() { var store = StoreOptions(_ => { @@ -58,13 +59,13 @@ public void given_two_documents_for_different_tenants_succeeds_using_attribute() using var session = store.LightweightSession(); session.Store(new UniqueCodePerTenant { Code = "ABC" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(new UniqueCodePerTenant { Code = "ABC" }); try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { @@ -73,7 +74,7 @@ public void given_two_documents_for_different_tenants_succeeds_using_attribute() } [Fact] - public void + public async Task given_two_documents_with_the_same_value_for_unique_field_with_single_property_for_different_tenants_succeeds_using_computed_index() { var store = StoreOptions(_ => @@ -89,13 +90,13 @@ public void using (var session = store.LightweightSession()) { session.Store(new Project { Name = "Project A" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(new Project { Name = "Project A" }); try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { @@ -107,19 +108,19 @@ public void using (var session = store.LightweightSession("abc")) { session.Store(new Project { Name = "Project A" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } //as can tenant def, but only once within the tenant using (var session = store.LightweightSession("def")) { session.Store(new Project { Name = "Project A" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(new Project { Name = "Project A" }); try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { @@ -129,7 +130,7 @@ public void } [Fact] - public void + public async Task given_two_documents_with_the_same_value_for_unique_field_with_single_property_for_different_tenants_succeeds_using_duplicated_field() { var store = StoreOptions(_ => @@ -146,13 +147,13 @@ public void using (var session = store.LightweightSession()) { session.Store(new ProjectUsingDuplicateField { Name = "Project A" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(new ProjectUsingDuplicateField { Name = "Project A" }); try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { @@ -164,19 +165,19 @@ public void using (var session = store.LightweightSession("abc")) { session.Store(new ProjectUsingDuplicateField { Name = "Project A" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } //as can tenant def, but only once within the tenant using (var session = store.LightweightSession("def")) { session.Store(new ProjectUsingDuplicateField { Name = "Project A" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Store(new ProjectUsingDuplicateField { Name = "Project A" }); try { - session.SaveChanges(); + await session.SaveChangesAsync(); } catch (DocumentAlreadyExistsException exception) { diff --git a/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy.cs b/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy.cs index 48bc86c740..bb4202e72a 100644 --- a/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy.cs +++ b/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy.cs @@ -15,7 +15,7 @@ namespace DocumentDbTests.MultiTenancy; -public class conjoined_multi_tenancy: StoreContext, IClassFixture +public class conjoined_multi_tenancy: StoreContext, IClassFixture, IAsyncLifetime { private readonly ITestOutputHelper _output; private readonly Target[] _greens = Target.GenerateRandomData(100).ToArray(); @@ -28,20 +28,30 @@ public class conjoined_multi_tenancy: StoreContext, IClassF private readonly Target targetRed2 = Target.Random(); public conjoined_multi_tenancy(MultiTenancyFixture fixture): base(fixture) + { + + } + + public async Task InitializeAsync() { using (var session = theStore.LightweightSession("Red")) { session.Store(targetRed1, targetRed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Blue")) { session.Store(targetBlue1, targetBlue2); - session.SaveChanges(); + await session.SaveChangesAsync(); } } + public Task DisposeAsync() + { + return Task.CompletedTask; + } + [Fact] public void cannot_load_by_id_across_tenants() { @@ -198,11 +208,11 @@ public async Task can_add_same_primary_key_to_multiple_tenant() } [Fact] - public void can_upsert_in_multi_tenancy() + public async Task can_upsert_in_multi_tenancy() { using var session = theStore.LightweightSession("123"); session.Store(Target.GenerateRandomData(10).ToArray()); - session.SaveChanges(); + await session.SaveChangesAsync(); } [Fact] @@ -445,7 +455,7 @@ public void use_fluent_interface() } [Fact] - public void will_not_cross_the_streams() + public async Task will_not_cross_the_streams() { var user = new User { UserName = "Me" }; user.Id = Guid.NewGuid(); @@ -453,7 +463,7 @@ public void will_not_cross_the_streams() using (var red = theStore.LightweightSession("Red")) { red.Store(user); - red.SaveChanges(); + await red.SaveChangesAsync(); } using (var green = theStore.LightweightSession("Green")) @@ -462,7 +472,7 @@ public void will_not_cross_the_streams() // Nothing should happen here green.Store(greenUser); - green.SaveChanges(); + await green.SaveChangesAsync(); } // Still got the original data @@ -534,7 +544,7 @@ public async Task write_to_tenant() [Fact] - public void write_to_tenant_with_explicitly_overridden_tenant() + public async Task write_to_tenant_with_explicitly_overridden_tenant() { var reds = Target.GenerateRandomData(50).ToArray(); var greens = Target.GenerateRandomData(75).ToArray(); @@ -548,7 +558,7 @@ public void write_to_tenant_with_explicitly_overridden_tenant() session.ForTenant("Green").Store(greens); session.ForTenant("Blue").Store(blues); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var red = theStore.QuerySession("Red")) diff --git a/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs b/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs index d3b5e98e56..ba0f97a6ab 100644 --- a/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs +++ b/src/DocumentDbTests/MultiTenancy/conjoined_multi_tenancy_with_partitioning.cs @@ -15,7 +15,7 @@ namespace DocumentDbTests.MultiTenancy; -public class conjoined_multi_tenancy_with_partitioning: OneOffConfigurationsContext +public class conjoined_multi_tenancy_with_partitioning: OneOffConfigurationsContext, IAsyncLifetime { private readonly ITestOutputHelper _output; private readonly Target[] _greens = Target.GenerateRandomData(100).ToArray(); @@ -39,20 +39,28 @@ public conjoined_multi_tenancy_with_partitioning() .AddPartition("blue", "Blue"); }); }); + } + public async Task InitializeAsync() + { using (var session = theStore.LightweightSession("Red")) { session.Store(targetRed1, targetRed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Blue")) { session.Store(targetBlue1, targetBlue2); - session.SaveChanges(); + await session.SaveChangesAsync(); } } + public Task DisposeAsync() + { + return Task.CompletedTask; + } + [Fact] public async Task primary_key_is_ordered_by_id_then_tenant_id() { @@ -217,11 +225,11 @@ public async Task can_add_same_primary_key_to_multiple_tenant() } [Fact] - public void can_upsert_in_multi_tenancy() + public async Task can_upsert_in_multi_tenancy() { using var session = theStore.LightweightSession("123"); session.Store(Target.GenerateRandomData(10).ToArray()); - session.SaveChanges(); + await session.SaveChangesAsync(); } [Fact] @@ -464,7 +472,7 @@ public void use_fluent_interface() } [Fact] - public void will_not_cross_the_streams() + public async Task will_not_cross_the_streams() { var user = new User { UserName = "Me" }; user.Id = Guid.NewGuid(); @@ -472,7 +480,7 @@ public void will_not_cross_the_streams() using (var red = theStore.LightweightSession("Red")) { red.Store(user); - red.SaveChanges(); + await red.SaveChangesAsync(); } using (var green = theStore.LightweightSession("Green")) @@ -481,7 +489,7 @@ public void will_not_cross_the_streams() // Nothing should happen here green.Store(greenUser); - green.SaveChanges(); + await green.SaveChangesAsync(); } // Still got the original data @@ -553,7 +561,7 @@ public async Task write_to_tenant() [Fact] - public void write_to_tenant_with_explicitly_overridden_tenant() + public async Task write_to_tenant_with_explicitly_overridden_tenant() { var reds = Target.GenerateRandomData(50).ToArray(); var greens = Target.GenerateRandomData(75).ToArray(); @@ -567,7 +575,7 @@ public void write_to_tenant_with_explicitly_overridden_tenant() session.ForTenant("Green").Store(greens); session.ForTenant("Blue").Store(blues); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var red = theStore.QuerySession("Red")) diff --git a/src/DocumentDbTests/Reading/BatchedQuerying/batched_querying_acceptance_Tests.cs b/src/DocumentDbTests/Reading/BatchedQuerying/batched_querying_acceptance_Tests.cs index 2f0dff9396..c566e9d70f 100644 --- a/src/DocumentDbTests/Reading/BatchedQuerying/batched_querying_acceptance_Tests.cs +++ b/src/DocumentDbTests/Reading/BatchedQuerying/batched_querying_acceptance_Tests.cs @@ -14,7 +14,7 @@ namespace DocumentDbTests.Reading.BatchedQuerying; -public class batched_querying_acceptance_Tests: OneOffConfigurationsContext +public class batched_querying_acceptance_Tests: OneOffConfigurationsContext, IAsyncLifetime { private readonly ITestOutputHelper _output; private readonly Target target1 = Target.Random(); @@ -46,6 +46,11 @@ public class batched_querying_acceptance_Tests: OneOffConfigurationsContext public batched_querying_acceptance_Tests(ITestOutputHelper output) { _output = output; + + } + + public async Task InitializeAsync() + { StoreOptions(_ => { _.Schema.For().AddSubClass(typeof(AdminUser)).AddSubClass(typeof(SuperUser)) @@ -56,7 +61,12 @@ public batched_querying_acceptance_Tests(ITestOutputHelper output) session.Store(target1, target2, target3); session.Store(user1, user2, admin1, admin2, super1, super2); - session.SaveChanges(); + await session.SaveChangesAsync(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } public void sample_config() diff --git a/src/DocumentDbTests/Reading/Json/document_session_find_json_Tests.cs b/src/DocumentDbTests/Reading/Json/document_session_find_json_Tests.cs index f56f62980c..a0625d8637 100644 --- a/src/DocumentDbTests/Reading/Json/document_session_find_json_Tests.cs +++ b/src/DocumentDbTests/Reading/Json/document_session_find_json_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -10,12 +11,12 @@ public class document_session_find_json_Tests: IntegrationContext { #region sample_find-json-by-id [Fact] - public void when_find_then_a_json_should_be_returned() + public async Task when_find_then_a_json_should_be_returned() { var issue = new Issue { Title = "Issue 2" }; theSession.Store(issue); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var json = theSession.Json.FindById(issue.Id); json.ShouldBe($"{{\"Id\": \"{issue.Id}\", \"Tags\": null, \"BugId\": null, \"Title\": \"Issue 2\", \"Number\": 0, \"Status\": null, \"AssigneeId\": null, \"ReporterId\": null}}"); @@ -33,4 +34,4 @@ public void when_find_then_a_null_should_be_returned() public document_session_find_json_Tests(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Json/streaming_json_results.cs b/src/DocumentDbTests/Reading/Json/streaming_json_results.cs index 1d1fa1cda7..26a5b88c06 100644 --- a/src/DocumentDbTests/Reading/Json/streaming_json_results.cs +++ b/src/DocumentDbTests/Reading/Json/streaming_json_results.cs @@ -997,7 +997,7 @@ public async Task use_select_to_another_type_as_json() theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Postgres sticks some extra spaces into the JSON string diff --git a/src/DocumentDbTests/Reading/Loading/document_session_load_already_loaded_document_Tests.cs b/src/DocumentDbTests/Reading/Loading/document_session_load_already_loaded_document_Tests.cs index 37fc8126be..ee331985f3 100644 --- a/src/DocumentDbTests/Reading/Loading/document_session_load_already_loaded_document_Tests.cs +++ b/src/DocumentDbTests/Reading/Loading/document_session_load_already_loaded_document_Tests.cs @@ -11,11 +11,11 @@ namespace DocumentDbTests.Reading.Loading; public class document_session_load_already_loaded_document_Tests : IntegrationContext { [Fact] - public void when_loading_then_a_different_document_should_be_returned() + public async Task when_loading_then_a_different_document_should_be_returned() { var user = new User { FirstName = "Tim", LastName = "Cools" }; theSession.Store(user); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.IdentitySession(); var first = session.Load(user.Id); diff --git a/src/DocumentDbTests/Reading/Loading/document_session_load_not_yet_persisted_document_Tests.cs b/src/DocumentDbTests/Reading/Loading/document_session_load_not_yet_persisted_document_Tests.cs index 9b14b4246c..3ba0769a54 100644 --- a/src/DocumentDbTests/Reading/Loading/document_session_load_not_yet_persisted_document_Tests.cs +++ b/src/DocumentDbTests/Reading/Loading/document_session_load_not_yet_persisted_document_Tests.cs @@ -1,4 +1,5 @@ -using Marten; +using System.Threading.Tasks; +using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -34,14 +35,14 @@ public void given_document_is_already_added_then_a_new_document_should_be_return } [Fact] - public void given_document_with_same_id_is_already_added_then_exception_should_occur() + public async Task given_document_with_same_id_is_already_added_then_exception_should_occur() { var user1 = new User { FirstName = "Tim", LastName = "Cools" }; var user2 = new User { FirstName = "Tim2", LastName = "Cools2", Id = user1.Id }; theSession.Store(user1); theSession.Store(user2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); //the non tracked session doesn't verify whether changer are already added. //so no exception should be thrown @@ -50,4 +51,4 @@ public void given_document_with_same_id_is_already_added_then_exception_should_o public not_tracked_document_session_load_not_yet_persisted_document_Tests(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/query_by_sql.cs b/src/DocumentDbTests/Reading/query_by_sql.cs index a0b0080af0..b4f0333567 100644 --- a/src/DocumentDbTests/Reading/query_by_sql.cs +++ b/src/DocumentDbTests/Reading/query_by_sql.cs @@ -71,14 +71,14 @@ public async Task stream_query_by_one_parameter() } [Fact] - public void query_by_one_parameter() + public async Task query_by_one_parameter() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var firstnames = session.Query("where data ->> 'LastName' = ?", "Miller").OrderBy(x => x.FirstName) @@ -91,14 +91,14 @@ public void query_by_one_parameter() } [Fact] - public void query_ignores_case_of_where_keyword() + public async Task query_ignores_case_of_where_keyword() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var firstnames = session.Query("WHERE data ->> 'LastName' = ?", "Miller").OrderBy(x => x.FirstName) @@ -111,14 +111,14 @@ public void query_ignores_case_of_where_keyword() } [Fact] - public void query_by_one_named_parameter() + public async Task query_by_one_named_parameter() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var firstnames = session.Query("where data ->> 'LastName' = :Name", new { Name = "Miller" }) @@ -132,14 +132,14 @@ public void query_by_one_named_parameter() } [Fact] - public void query_by_two_parameters() + public async Task query_by_two_parameters() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); #region sample_using_parameterized_sql @@ -156,14 +156,14 @@ public void query_by_two_parameters() #region sample_query_by_two_named_parameters [Fact] - public void query_by_two_named_parameters() + public async Task query_by_two_named_parameters() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var user = session.Query("where data ->> 'FirstName' = :FirstName and data ->> 'LastName' = :LastName", new { FirstName = "Jeremy", LastName = "Miller" }) @@ -175,14 +175,14 @@ public void query_by_two_named_parameters() #endregion [Fact] - public void query_two_fields_by_one_named_parameter() + public async Task query_two_fields_by_one_named_parameter() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var user = session.Query("where data ->> 'FirstName' = :Name or data ->> 'LastName' = :Name", new { Name = "Jeremy" }) @@ -192,14 +192,14 @@ public void query_two_fields_by_one_named_parameter() } [Fact] - public void query_for_multiple_documents() + public async Task query_for_multiple_documents() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var firstnames = session.Query("where data ->> 'LastName' = 'Miller'").OrderBy(x => x.FirstName) @@ -213,14 +213,14 @@ public void query_for_multiple_documents() [Fact] - public void query_for_multiple_documents_with_ordering() + public async Task query_for_multiple_documents_with_ordering() { using var session = theStore.LightweightSession(); session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); - session.SaveChanges(); + await session.SaveChangesAsync(); var firstnames = session.Query("where data ->> 'LastName' = 'Miller' order by data ->> 'FirstName'") @@ -236,12 +236,12 @@ public void query_for_multiple_documents_with_ordering() #region sample_query_with_only_the_where_clause [Fact] - public void query_for_single_document() + public async Task query_for_single_document() { using var session = theStore.LightweightSession(); var u = new User { FirstName = "Jeremy", LastName = "Miller" }; session.Store(u); - session.SaveChanges(); + await session.SaveChangesAsync(); var user = session.Query("where data ->> 'FirstName' = 'Jeremy'").Single(); user.LastName.ShouldBe("Miller"); @@ -251,12 +251,12 @@ public void query_for_single_document() #endregion [Fact] - public void query_for_single_document_where_clause_trimmed() + public async Task query_for_single_document_where_clause_trimmed() { using var session = theStore.LightweightSession(); var u = new User { FirstName = "Jeremy", LastName = "Miller" }; session.Store(u); - session.SaveChanges(); + await session.SaveChangesAsync(); var user = session.Query(@" where data ->> 'FirstName' = 'Jeremy'").Single(); @@ -267,12 +267,12 @@ public void query_for_single_document_where_clause_trimmed() #region sample_query_with_matches_sql [Fact] - public void query_with_matches_sql() + public async Task query_with_matches_sql() { using var session = theStore.LightweightSession(); var u = new User { FirstName = "Eric", LastName = "Smith" }; session.Store(u); - session.SaveChanges(); + await session.SaveChangesAsync(); var user = session.Query().Where(x => x.MatchesSql("data->> 'FirstName' = ?", "Eric")).Single(); user.LastName.ShouldBe("Smith"); @@ -282,12 +282,12 @@ public void query_with_matches_sql() #endregion [Fact] - public void query_with_select_in_query() + public async Task query_with_select_in_query() { using var session = theStore.LightweightSession(); var u = new User { FirstName = "Jeremy", LastName = "Miller" }; session.Store(u); - session.SaveChanges(); + await session.SaveChangesAsync(); #region sample_use_all_your_own_sql diff --git a/src/DocumentDbTests/SessionMechanics/DocumentSession_change_set_tracking_Tests.cs b/src/DocumentDbTests/SessionMechanics/DocumentSession_change_set_tracking_Tests.cs index a60fafdd12..82c0074db2 100644 --- a/src/DocumentDbTests/SessionMechanics/DocumentSession_change_set_tracking_Tests.cs +++ b/src/DocumentDbTests/SessionMechanics/DocumentSession_change_set_tracking_Tests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Linq.SqlGeneration; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -11,7 +12,7 @@ namespace DocumentDbTests.SessionMechanics; public class DocumentSession_change_set_tracking_Tests : IntegrationContext { [Fact] - public void categorize_changes_inserts_and_deletions() + public async Task categorize_changes_inserts_and_deletions() { var logger = new RecordingLogger(); theSession.Logger = logger; @@ -42,7 +43,7 @@ public void categorize_changes_inserts_and_deletions() logger.LastCommit.ShouldBeNull(); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Everything should be cleared out theSession.PendingChanges.Updates().Any().ShouldBeFalse(); @@ -55,7 +56,7 @@ public void categorize_changes_inserts_and_deletions() logger.LastCommit.Deleted.OfType().Select(x => (Guid)x.Id).ShouldHaveTheSameElementsAs(id1, id2); theSession.Store(new Target()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); logger.Commits.Count().ShouldBe(2); logger.LastCommit.Updated.Count().ShouldBe(1); @@ -64,4 +65,4 @@ public void categorize_changes_inserts_and_deletions() public DocumentSession_change_set_tracking_Tests(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/SessionMechanics/UnitOfWork_Operation_Ordering_Tests.cs b/src/DocumentDbTests/SessionMechanics/UnitOfWork_Operation_Ordering_Tests.cs index 18e784bdc0..dcefb691eb 100644 --- a/src/DocumentDbTests/SessionMechanics/UnitOfWork_Operation_Ordering_Tests.cs +++ b/src/DocumentDbTests/SessionMechanics/UnitOfWork_Operation_Ordering_Tests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ namespace DocumentDbTests.SessionMechanics; -public class UnitOfWork_Operation_Ordering_Tests: OneOffConfigurationsContext +public class UnitOfWork_Operation_Ordering_Tests: OneOffConfigurationsContext, IAsyncLifetime { private readonly Company _company; @@ -44,18 +45,27 @@ public UnitOfWork_Operation_Ordering_Tests() _user1Issue1 = new Issue { AssigneeId = _userWithIssues.Id }; _user1Issue2 = new Issue { AssigneeId = _userWithIssues.Id }; + } + + public async Task InitializeAsync() + { using var session = theStore.LightweightSession("Bug_1229"); session.Store(_company); session.Store(_userNoIssues, _userWithIssues); session.Store(_user1Issue1, _user1Issue2); - session.SaveChanges(); + await session.SaveChangesAsync(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } [Fact] - public void unrelated_inserts_ordered_correctly() + public async Task unrelated_inserts_ordered_correctly() { - RunTest(s => + await RunTest(s => { s.Insert(new Company()); s.Insert(new User()); @@ -68,9 +78,9 @@ public void unrelated_inserts_ordered_correctly() } [Fact] - public void unrelated_updates_ordered_correctly() + public async Task unrelated_updates_ordered_correctly() { - RunTest(s => + await RunTest(s => { _company.Name = "Something else"; _user1Issue1.Tags = new[] { "new tag" }; @@ -87,9 +97,9 @@ public void unrelated_updates_ordered_correctly() } [Fact] - public void related_inserts_ordered_correctly() + public async Task related_inserts_ordered_correctly() { - RunTest(s => + await RunTest(s => { var newUser = new User(); @@ -103,9 +113,9 @@ public void related_inserts_ordered_correctly() } [Fact] - public void related_upserts_ordered_correctly() + public async Task related_upserts_ordered_correctly() { - RunTest(s => + await RunTest(s => { var newUser = new User(); @@ -119,9 +129,9 @@ public void related_upserts_ordered_correctly() } [Fact] - public void related_inserts_ordered_incorrectly() + public async Task related_inserts_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { var newUser = new User(); @@ -135,9 +145,9 @@ public void related_inserts_ordered_incorrectly() } [Fact] - public void related_inserts_on_subclass_fk_in_ordered_incorrectly() + public async Task related_inserts_on_subclass_fk_in_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { var newUser = new AdminUser(); @@ -151,9 +161,9 @@ public void related_inserts_on_subclass_fk_in_ordered_incorrectly() } [Fact] - public void related_inserts_on_subclass_fk_out_ordered_incorrectly() + public async Task related_inserts_on_subclass_fk_out_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { var newUser = new AdminUser(); @@ -167,9 +177,9 @@ public void related_inserts_on_subclass_fk_out_ordered_incorrectly() } [Fact] - public void unrelated_deletes() + public async Task unrelated_deletes() { - RunTest(s => + await RunTest(s => { s.Delete(_company); s.Delete(_userNoIssues); @@ -182,9 +192,9 @@ public void unrelated_deletes() } [Fact] - public void related_deletes_ordered_correctly() + public async Task related_deletes_ordered_correctly() { - RunTest(s => + await RunTest(s => { s.Delete(_company); s.Delete(_user1Issue1); @@ -198,9 +208,9 @@ public void related_deletes_ordered_correctly() } [Fact] - public void related_deletes_ordered_incorrectly() + public async Task related_deletes_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { s.Delete(_company); s.Delete(_user1Issue1); @@ -214,9 +224,9 @@ public void related_deletes_ordered_incorrectly() } [Fact] - public void related_deletes_and_unrelated_inserts_ordered_incorrectly() + public async Task related_deletes_and_unrelated_inserts_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { s.Insert(new Company()); s.Insert(new User()); @@ -232,9 +242,9 @@ public void related_deletes_and_unrelated_inserts_ordered_incorrectly() } [Fact] - public void related_deletes_and_unrelated_inserts_ordered_correctly() + public async Task related_deletes_and_unrelated_inserts_ordered_correctly() { - RunTest(s => + await RunTest(s => { s.Insert(new Company()); s.Insert(new User()); @@ -250,9 +260,9 @@ public void related_deletes_and_unrelated_inserts_ordered_correctly() } [Fact] - public void related_deletes_and_related_inserts_ordered_incorrectly() + public async Task related_deletes_and_related_inserts_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { var newUser = new User(); @@ -271,9 +281,9 @@ public void related_deletes_and_related_inserts_ordered_incorrectly() } [Fact] - public void related_deletes_and_related_upserts_ordered_incorrectly() + public async Task related_deletes_and_related_upserts_ordered_incorrectly() { - RunTest(s => + await RunTest(s => { var newUser = new User(); @@ -292,9 +302,9 @@ public void related_deletes_and_related_upserts_ordered_incorrectly() } [Fact] - public void upsert_followed_by_delete_should_order_correctly() + public async Task upsert_followed_by_delete_should_order_correctly() { - RunTest(s => + await RunTest(s => { var newUser = new User(); s.Store(newUser); @@ -306,7 +316,7 @@ public void upsert_followed_by_delete_should_order_correctly() ); } - private void RunTest( + private async Task RunTest( Action act, int expectedCompanyCount, int expectedUserCount, @@ -316,7 +326,7 @@ private void RunTest( { act(s); - s.SaveChanges(); + await s.SaveChangesAsync(); } using (var s = theStore.QuerySession("Bug_1229")) diff --git a/src/DocumentDbTests/SessionMechanics/UnitOfWork_PendingChanges_Functionality_Tests.cs b/src/DocumentDbTests/SessionMechanics/UnitOfWork_PendingChanges_Functionality_Tests.cs index 8b4a5fcbae..9a1fdf2884 100644 --- a/src/DocumentDbTests/SessionMechanics/UnitOfWork_PendingChanges_Functionality_Tests.cs +++ b/src/DocumentDbTests/SessionMechanics/UnitOfWork_PendingChanges_Functionality_Tests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Linq.SqlGeneration; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -193,7 +194,7 @@ public void pending_deletions() } [Fact] - public void pending_with_dirty_checks() + public async Task pending_with_dirty_checks() { var user1 = new User(); var user2 = new User(); @@ -201,7 +202,7 @@ public void pending_with_dirty_checks() using (var session1 = theStore.LightweightSession()) { session1.Store(user1, user2); - session1.SaveChanges(); + await session1.SaveChangesAsync(); } using (var session2 = theStore.DirtyTrackedSession()) diff --git a/src/DocumentDbTests/SessionMechanics/Using_Global_DocumentSessionListener_Tests.cs b/src/DocumentDbTests/SessionMechanics/Using_Global_DocumentSessionListener_Tests.cs index 0af2477107..cf92d34bf1 100644 --- a/src/DocumentDbTests/SessionMechanics/Using_Global_DocumentSessionListener_Tests.cs +++ b/src/DocumentDbTests/SessionMechanics/Using_Global_DocumentSessionListener_Tests.cs @@ -16,7 +16,7 @@ public Using_Global_DocumentSessionListener_Tests() } [Fact] - public void call_listener_events_on_synchronous_session_saves() + public async Task call_listener_events_on_synchronous_session_saves() { #region sample_registering-a-document-session-listener var stub1 = new StubDocumentSessionListener(); @@ -38,7 +38,7 @@ public void call_listener_events_on_synchronous_session_saves() { session.Store(new User(), new User()); - session.SaveChanges(); + await session.SaveChangesAsync(); stub1.SaveChangesSession.ShouldBeTheSameAs(session); stub1.AfterCommitSession.ShouldBeTheSameAs(session); @@ -148,7 +148,7 @@ public void call_listener_events_on_document_store_objects() } [Fact] - public void call_listener_events_on_document_load() + public async Task call_listener_events_on_document_load() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -170,7 +170,7 @@ public void call_listener_events_on_document_load() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession()) @@ -184,7 +184,7 @@ public void call_listener_events_on_document_load() } [Fact] - public void call_listener_events_on_document_query() + public async Task call_listener_events_on_document_query() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -206,7 +206,7 @@ public void call_listener_events_on_document_query() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession()) @@ -289,7 +289,7 @@ public void call_listener_events_on_document_store_objects_and_dirty_tracking_se } [Fact] - public void call_listener_events_on_document_load_and_dirty_tracking_session() + public async Task call_listener_events_on_document_load_and_dirty_tracking_session() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -311,7 +311,7 @@ public void call_listener_events_on_document_load_and_dirty_tracking_session() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.DirtyTrackedSession()) @@ -325,7 +325,7 @@ public void call_listener_events_on_document_load_and_dirty_tracking_session() } [Fact] - public void call_listener_events_on_document_query_and_dirty_tracking_session() + public async Task call_listener_events_on_document_query_and_dirty_tracking_session() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -347,7 +347,7 @@ public void call_listener_events_on_document_query_and_dirty_tracking_session() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.DirtyTrackedSession()) @@ -364,7 +364,7 @@ public void call_listener_events_on_document_query_and_dirty_tracking_session() } [Fact] - public void call_listener_events_on_document_load_with_lightweightsession() + public async Task call_listener_events_on_document_load_with_lightweightsession() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -386,7 +386,7 @@ public void call_listener_events_on_document_load_with_lightweightsession() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } // DocumentLoaded event should work fine with LightWeightSession diff --git a/src/DocumentDbTests/SessionMechanics/Using_Local_DocumentSessionListener_Tests.cs b/src/DocumentDbTests/SessionMechanics/Using_Local_DocumentSessionListener_Tests.cs index fa9a8964e8..8bbfd0000c 100644 --- a/src/DocumentDbTests/SessionMechanics/Using_Local_DocumentSessionListener_Tests.cs +++ b/src/DocumentDbTests/SessionMechanics/Using_Local_DocumentSessionListener_Tests.cs @@ -14,7 +14,7 @@ namespace DocumentDbTests.SessionMechanics; public class Using_Local_DocumentSessionListener_Tests: OneOffConfigurationsContext { [Fact] - public void call_listener_events_on_synchronous_session_saves() + public async Task call_listener_events_on_synchronous_session_saves() { #region sample_registering-a-document-session-listener @@ -36,7 +36,7 @@ public void call_listener_events_on_synchronous_session_saves() { session.Store(new User(), new User()); - session.SaveChanges(); + await session.SaveChangesAsync(); stub1.SaveChangesSession.ShouldBeTheSameAs(session); stub1.AfterCommitSession.ShouldBeTheSameAs(session); @@ -137,7 +137,7 @@ public void call_listener_events_on_document_store_objects() } [Fact] - public void call_listener_events_on_document_load() + public async Task call_listener_events_on_document_load() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -156,7 +156,7 @@ public void call_listener_events_on_document_load() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(new SessionOptions { Listeners = { stub1, stub2 } })) @@ -170,7 +170,7 @@ public void call_listener_events_on_document_load() } [Fact] - public void call_listener_events_on_document_query() + public async Task call_listener_events_on_document_query() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -189,7 +189,7 @@ public void call_listener_events_on_document_query() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(new SessionOptions { Listeners = { stub1, stub2 } })) @@ -270,7 +270,7 @@ public void call_listener_events_on_document_store_objects_and_dirty_tracking_se } [Fact] - public void call_listener_events_on_document_load_and_dirty_tracking_session() + public async Task call_listener_events_on_document_load_and_dirty_tracking_session() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -289,7 +289,7 @@ public void call_listener_events_on_document_load_and_dirty_tracking_session() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.DirtyTrackedSession(new SessionOptions { Listeners = { stub1, stub2 } })) @@ -303,7 +303,7 @@ public void call_listener_events_on_document_load_and_dirty_tracking_session() } [Fact] - public void call_listener_events_on_document_query_and_dirty_tracking_session() + public async Task call_listener_events_on_document_query_and_dirty_tracking_session() { var stub1 = new StubDocumentSessionListener(); var stub2 = new StubDocumentSessionListener(); @@ -322,7 +322,7 @@ public void call_listener_events_on_document_query_and_dirty_tracking_session() using (var session = store.LightweightSession()) { session.StoreObjects(new[] { user1, user2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.DirtyTrackedSession(new SessionOptions { Listeners = { stub1, stub2 } })) diff --git a/src/DocumentDbTests/SessionMechanics/dirty_tracked_sessions.cs b/src/DocumentDbTests/SessionMechanics/dirty_tracked_sessions.cs index 4d8e92ce4d..45a4965f1f 100644 --- a/src/DocumentDbTests/SessionMechanics/dirty_tracked_sessions.cs +++ b/src/DocumentDbTests/SessionMechanics/dirty_tracked_sessions.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -13,13 +14,13 @@ public dirty_tracked_sessions(DefaultStoreFixture fixture): base(fixture) } [Fact] - public void store_and_update_a_document() + public async Task store_and_update_a_document() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using (var session2 = theStore.DirtyTrackedSession()) { @@ -29,7 +30,7 @@ public void store_and_update_a_document() user2.FirstName = "Jens"; user2.LastName = "Pettersson"; - session2.SaveChanges(); + await session2.SaveChangesAsync(); } using (var session3 = theStore.LightweightSession()) @@ -41,17 +42,17 @@ public void store_and_update_a_document() } [Fact] - public void store_and_update_a_document_in_same_session() + public async Task store_and_update_a_document_in_same_session() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); user.FirstName = "Jens"; user.LastName = "Pettersson"; - session.SaveChanges(); + await session.SaveChangesAsync(); using var session3 = theStore.LightweightSession(); var user3 = session3.Load(user.Id); @@ -61,18 +62,18 @@ public void store_and_update_a_document_in_same_session() [Fact] - public void store_reload_and_update_a_document_in_same_dirty_tracked_session() + public async Task store_reload_and_update_a_document_in_same_dirty_tracked_session() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var user2 = session.Load(user.Id); user2.FirstName = "Jens"; user2.LastName = "Pettersson"; - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var user3 = query.Load(user.Id); @@ -81,18 +82,18 @@ public void store_reload_and_update_a_document_in_same_dirty_tracked_session() } [Fact] - public void store_reload_update_and_delete_document_in_same_dirty_tracked_session() + public async Task store_reload_update_and_delete_document_in_same_dirty_tracked_session() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var user2 = session.Load(user.Id); user2.FirstName = "Jens"; session.Delete(user2); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var user3 = query.Load(user.Id); @@ -100,18 +101,18 @@ public void store_reload_update_and_delete_document_in_same_dirty_tracked_sessio } [Fact] - public void store_reload_update_and_delete_by_id_in_same_dirty_tracked_session() + public async Task store_reload_update_and_delete_by_id_in_same_dirty_tracked_session() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var user2 = session.Load(user.Id); user2.FirstName = "Jens"; session.Delete(user2.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var user3 = query.Load(user.Id); @@ -119,20 +120,20 @@ public void store_reload_update_and_delete_by_id_in_same_dirty_tracked_session() } [Fact] - public void store_reload_delete_reload_and_update_document_in_same_dirty_tracked_session() + public async Task store_reload_delete_reload_and_update_document_in_same_dirty_tracked_session() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var user2 = session.Load(user.Id); user2.FirstName = "Jens"; session.Delete(user2); user2 = session.Load(user.Id); user2.FirstName = "Jens"; - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var user3 = query.Load(user.Id); @@ -140,18 +141,18 @@ public void store_reload_delete_reload_and_update_document_in_same_dirty_tracked } [Fact] - public void store_reload_update_and_eject_document_in_same_dirty_tracked_session() + public async Task store_reload_update_and_eject_document_in_same_dirty_tracked_session() { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = theStore.DirtyTrackedSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var user2 = session.Load(user.Id); user2.FirstName = "Jens"; session.Eject(user2); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var user3 = query.Load(user.Id); diff --git a/src/DocumentDbTests/SessionMechanics/document_session_logs_SaveChanges.cs b/src/DocumentDbTests/SessionMechanics/document_session_logs_SaveChanges.cs index a6f3d24502..743e692bfb 100644 --- a/src/DocumentDbTests/SessionMechanics/document_session_logs_SaveChanges.cs +++ b/src/DocumentDbTests/SessionMechanics/document_session_logs_SaveChanges.cs @@ -14,7 +14,7 @@ namespace DocumentDbTests.SessionMechanics; public class document_session_logs_SaveChanges : IntegrationContext { [Fact] - public void records_on_SaveChanges() + public async Task records_on_SaveChanges() { var logger = new RecordingLogger(); @@ -22,7 +22,7 @@ public void records_on_SaveChanges() theSession.Store(Target.Random()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); logger.LastSession.ShouldBe(theSession); } diff --git a/src/DocumentDbTests/SessionMechanics/ejecting_documents.cs b/src/DocumentDbTests/SessionMechanics/ejecting_documents.cs index 7cc3a7b357..ff191c2f67 100644 --- a/src/DocumentDbTests/SessionMechanics/ejecting_documents.cs +++ b/src/DocumentDbTests/SessionMechanics/ejecting_documents.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Xunit; @@ -9,7 +10,7 @@ namespace DocumentDbTests.SessionMechanics; public class ejecting_documents : IntegrationContext { [Fact] - public void demonstrate_eject() + public async Task demonstrate_eject() { #region sample_ejecting_a_document var target1 = Target.Random(); @@ -29,7 +30,7 @@ public void demonstrate_eject() // Now that 2nd document is no longer in the identity map session.Load(target2.Id).ShouldBeNull(); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -80,7 +81,7 @@ public void eject_a_document_clears_it_from_the_identity_map_dirty() } [Fact] - public void eject_a_document_clears_it_from_the_unit_of_work_regular() + public async Task eject_a_document_clears_it_from_the_unit_of_work_regular() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -91,7 +92,7 @@ public void eject_a_document_clears_it_from_the_unit_of_work_regular() session.Eject(target2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -102,7 +103,7 @@ public void eject_a_document_clears_it_from_the_unit_of_work_regular() } [Fact] - public void eject_a_document_clears_it_from_the_unit_of_work_dirty() + public async Task eject_a_document_clears_it_from_the_unit_of_work_dirty() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -113,7 +114,7 @@ public void eject_a_document_clears_it_from_the_unit_of_work_dirty() session.Eject(target2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -124,7 +125,7 @@ public void eject_a_document_clears_it_from_the_unit_of_work_dirty() } [Fact] - public void eject_a_document_clears_it_from_the_unit_of_work_lightweight() + public async Task eject_a_document_clears_it_from_the_unit_of_work_lightweight() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -135,7 +136,7 @@ public void eject_a_document_clears_it_from_the_unit_of_work_lightweight() session.Eject(target2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -146,7 +147,7 @@ public void eject_a_document_clears_it_from_the_unit_of_work_lightweight() } [Fact] - public void eject_a_document_type_clears_it_from_the_identity_map_regular() + public async Task eject_a_document_type_clears_it_from_the_identity_map_regular() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -167,7 +168,7 @@ public void eject_a_document_type_clears_it_from_the_identity_map_regular() session.PendingChanges.OperationsFor().Any().ShouldBeTrue(); session.PendingChanges.OperationsFor().Any().ShouldBeFalse(); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(target1.Id).ShouldBeNull(); session.Load(target2.Id).ShouldBeNull(); @@ -204,7 +205,7 @@ public void eject_a_document_type_clears_it_from_the_identity_map_dirty() } [Fact] - public void eject_a_document_type_clears_it_from_the_unit_of_work_regular() + public async Task eject_a_document_type_clears_it_from_the_unit_of_work_regular() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -220,7 +221,7 @@ public void eject_a_document_type_clears_it_from_the_unit_of_work_regular() session.EjectAllOfType(typeof(Target)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -232,7 +233,7 @@ public void eject_a_document_type_clears_it_from_the_unit_of_work_regular() } [Fact] - public void eject_a_document_type_clears_updates_from_the_unit_of_work_regular() + public async Task eject_a_document_type_clears_updates_from_the_unit_of_work_regular() { var target1 = new Target { Number = 1 }; var target2 = new Target { Number = 2 }; @@ -244,7 +245,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_regular() session.Store(target1, target2); session.Store(user1, user2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.IdentitySession()) @@ -260,7 +261,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_regular() session.EjectAllOfType(typeof(Target)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -273,7 +274,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_regular() } [Fact] - public void eject_a_document_type_clears_it_from_the_unit_of_work_dirty() + public async Task eject_a_document_type_clears_it_from_the_unit_of_work_dirty() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -289,7 +290,7 @@ public void eject_a_document_type_clears_it_from_the_unit_of_work_dirty() session.EjectAllOfType(typeof(Target)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -301,7 +302,7 @@ public void eject_a_document_type_clears_it_from_the_unit_of_work_dirty() } [Fact] - public void eject_a_document_type_clears_updates_from_the_unit_of_work_dirty() + public async Task eject_a_document_type_clears_updates_from_the_unit_of_work_dirty() { var target1 = new Target { Number = 1 }; var target2 = new Target { Number = 2 }; @@ -313,7 +314,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_dirty() session.Store(target1, target2); session.Store(user1, user2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.DirtyTrackedSession()) @@ -326,7 +327,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_dirty() session.EjectAllOfType(typeof(Target)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -339,7 +340,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_dirty() } [Fact] - public void eject_a_document_type_clears_it_from_the_unit_of_work_lightweight() + public async Task eject_a_document_type_clears_it_from_the_unit_of_work_lightweight() { var target1 = Target.Random(); var target2 = Target.Random(); @@ -355,7 +356,7 @@ public void eject_a_document_type_clears_it_from_the_unit_of_work_lightweight() session.EjectAllOfType(typeof(Target)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -367,7 +368,7 @@ public void eject_a_document_type_clears_it_from_the_unit_of_work_lightweight() } [Fact] - public void eject_a_document_type_clears_updates_from_the_unit_of_work_lightweight() + public async Task eject_a_document_type_clears_updates_from_the_unit_of_work_lightweight() { var target1 = new Target { Number = 1 }; var target2 = new Target { Number = 2 }; @@ -379,7 +380,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_lightweig session.Store(target1, target2); session.Store(user1, user2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -395,7 +396,7 @@ public void eject_a_document_type_clears_updates_from_the_unit_of_work_lightweig session.EjectAllOfType(typeof(Target)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs b/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs index 9b023f32be..bc0bdc95c5 100644 --- a/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs +++ b/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs @@ -13,12 +13,12 @@ public class identity_map_mechanics: IntegrationContext { [Theory] [SessionTypes] - public void when_loading_then_the_document_should_be_returned(DocumentTracking tracking) + public async Task when_loading_then_the_document_should_be_returned(DocumentTracking tracking) { var user = new User { FirstName = "Tim", LastName = "Cools" }; var session = OpenSession(tracking); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var identitySession = theStore.IdentitySession(); var first = identitySession.Load(user.Id); @@ -29,12 +29,12 @@ public void when_loading_then_the_document_should_be_returned(DocumentTracking t [Theory] [SessionTypes] - public void when_loading_by_ids_then_the_same_document_should_be_returned(DocumentTracking tracking) + public async Task when_loading_by_ids_then_the_same_document_should_be_returned(DocumentTracking tracking) { var user = new User { FirstName = "Tim", LastName = "Cools" }; var session = OpenSession(tracking); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var identitySession = theStore.IdentitySession(); var first = identitySession.Load(user.Id); @@ -45,7 +45,7 @@ public void when_loading_by_ids_then_the_same_document_should_be_returned(Docume } [Fact] - public void when_querying_and_modifying_multiple_documents_should_track_and_persist() + public async Task when_querying_and_modifying_multiple_documents_should_track_and_persist() { var user1 = new User { FirstName = "James", LastName = "Worthy 1" }; var user2 = new User { FirstName = "James", LastName = "Worthy 2" }; @@ -54,7 +54,7 @@ public void when_querying_and_modifying_multiple_documents_should_track_and_pers using var session = theStore.LightweightSession(); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); using (var session2 = theStore.DirtyTrackedSession()) { @@ -65,7 +65,7 @@ public void when_querying_and_modifying_multiple_documents_should_track_and_pers user.LastName += " - updated"; } - session2.SaveChanges(); + await session2.SaveChangesAsync(); } using (var session2 = theStore.IdentitySession()) @@ -78,7 +78,7 @@ public void when_querying_and_modifying_multiple_documents_should_track_and_pers } [Fact] - public void when_querying_and_modifying_multiple_documents_should_track_and_persist_dirty() + public async Task when_querying_and_modifying_multiple_documents_should_track_and_persist_dirty() { var user1 = new User { FirstName = "James", LastName = "Worthy 1" }; var user2 = new User { FirstName = "James", LastName = "Worthy 2" }; @@ -89,7 +89,7 @@ public void when_querying_and_modifying_multiple_documents_should_track_and_pers session.Store(user2); session.Store(user3); - session.SaveChanges(); + await session.SaveChangesAsync(); using (var session2 = theStore.DirtyTrackedSession()) { @@ -100,7 +100,7 @@ public void when_querying_and_modifying_multiple_documents_should_track_and_pers user.LastName += " - updated"; } - session2.SaveChanges(); + await session2.SaveChangesAsync(); } using (var session2 = theStore.IdentitySession()) diff --git a/src/DocumentDbTests/SessionMechanics/updating_by_batch.cs b/src/DocumentDbTests/SessionMechanics/updating_by_batch.cs index 57f05d82f0..c1283e1739 100644 --- a/src/DocumentDbTests/SessionMechanics/updating_by_batch.cs +++ b/src/DocumentDbTests/SessionMechanics/updating_by_batch.cs @@ -12,14 +12,14 @@ namespace DocumentDbTests.SessionMechanics; public class updating_by_batch : OneOffConfigurationsContext { [Fact] - public void can_make_updates_with_more_than_one_batch() + public async Task can_make_updates_with_more_than_one_batch() { var targets = Target.GenerateRandomData(100).ToArray(); StoreOptions(_ => _.UpdateBatchSize = 10); using var session = theStore.LightweightSession(); session.Store(targets); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count().ShouldBe(100); } @@ -40,7 +40,7 @@ public async Task can_make_updates_with_more_than_one_batch_async() } [Fact] - public void can_delete_and_make_updates_with_more_than_one_batch_GH_987() + public async Task can_delete_and_make_updates_with_more_than_one_batch_GH_987() { var targets = Target.GenerateRandomData(100).ToArray(); StoreOptions(_ => @@ -52,7 +52,7 @@ public void can_delete_and_make_updates_with_more_than_one_batch_GH_987() session.DeleteWhere(t => t.Id != Guid.Empty); session.Store(targets); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count().ShouldBe(100); } @@ -72,4 +72,4 @@ public async Task can_delete_and_make_updates_with_more_than_one_batch_async() var t = await session.Query().CountAsync(); t.ShouldBe(100); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Writing/Identity/Sequences/Bug_255_Hilo_table_being_erroneously_recreated.cs b/src/DocumentDbTests/Writing/Identity/Sequences/Bug_255_Hilo_table_being_erroneously_recreated.cs index 36733ebf4c..6de0de47d7 100644 --- a/src/DocumentDbTests/Writing/Identity/Sequences/Bug_255_Hilo_table_being_erroneously_recreated.cs +++ b/src/DocumentDbTests/Writing/Identity/Sequences/Bug_255_Hilo_table_being_erroneously_recreated.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using JasperFx.Core; using Marten; using Marten.Testing.Documents; @@ -13,7 +14,7 @@ namespace DocumentDbTests.Writing.Identity.Sequences; public class Bug_255_Hilo_table_being_erroneously_recreated : BugIntegrationContext { [Fact] - public void only_generated_once_default_connection_string_schema() + public async Task only_generated_once_default_connection_string_schema() { var logger = new DdlLogger(); @@ -23,7 +24,7 @@ public void only_generated_once_default_connection_string_schema() }); theSession.Store(new IntDoc()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var store2 = SeparateStore(_ => @@ -34,7 +35,7 @@ public void only_generated_once_default_connection_string_schema() using (var session = store2.LightweightSession()) { session.Store(new IntDoc()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Writing/Identity/Sequences/CombGuidIdGenerationTests.cs b/src/DocumentDbTests/Writing/Identity/Sequences/CombGuidIdGenerationTests.cs index 2a7a50b52c..a5936b56cd 100644 --- a/src/DocumentDbTests/Writing/Identity/Sequences/CombGuidIdGenerationTests.cs +++ b/src/DocumentDbTests/Writing/Identity/Sequences/CombGuidIdGenerationTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using System.Threading.Tasks; using JasperFx.Core; using JasperFx.Core.Reflection; using Marten; @@ -40,7 +41,7 @@ public void When_ids_are_generated_the_first_id_should_be_less_than_the_second() } [Fact] - public void When_documents_are_stored_after_each_other_then_the_first_id_should_be_less_than_the_second() + public async Task When_documents_are_stored_after_each_other_then_the_first_id_should_be_less_than_the_second() { StoreOptions(options => { @@ -58,11 +59,11 @@ public void When_documents_are_stored_after_each_other_then_the_first_id_should_ }); - StoreUser(theStore, "User1"); + await StoreUser(theStore, "User1"); Thread.Sleep(4); //we need some time inbetween to ensure the timepart of the CombGuid is different - StoreUser(theStore, "User2"); + await StoreUser(theStore, "User2"); Thread.Sleep(4); - StoreUser(theStore, "User3"); + await StoreUser(theStore, "User3"); var users = GetUsers(theStore); @@ -119,10 +120,10 @@ private static UserWithGuid[] GetUsers(IDocumentStore documentStore) return session.Query().ToArray(); } - private static void StoreUser(IDocumentStore documentStore, string lastName) + private static async Task StoreUser(IDocumentStore documentStore, string lastName) { using var session = documentStore.IdentitySession(); session.Store(new UserWithGuid { LastName = lastName }); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Writing/Identity/Sequences/CustomKeyGenerationTests.cs b/src/DocumentDbTests/Writing/Identity/Sequences/CustomKeyGenerationTests.cs index b7542ffa66..fcb6612092 100644 --- a/src/DocumentDbTests/Writing/Identity/Sequences/CustomKeyGenerationTests.cs +++ b/src/DocumentDbTests/Writing/Identity/Sequences/CustomKeyGenerationTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using JasperFx.Core; using JasperFx.CodeGeneration; using JasperFx.CodeGeneration.Frames; @@ -32,7 +33,7 @@ public void GenerateCode(GeneratedMethod assign, DocumentMapping mapping) public class CustomKeyGenerationTests : OneOffConfigurationsContext { [Fact] - public void When_a_custom_id_generation_is_used() + public async Task When_a_custom_id_generation_is_used() { StoreOptions(options => { @@ -51,7 +52,7 @@ public void When_a_custom_id_generation_is_used() using (var session = theStore.LightweightSession()) { session.Store(new UserWithString { LastName = "last" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session1 = theStore.QuerySession()) diff --git a/src/DocumentDbTests/Writing/Identity/Sequences/IdentityKeyGenerationTests.cs b/src/DocumentDbTests/Writing/Identity/Sequences/IdentityKeyGenerationTests.cs index a18dd33fff..e8c5c91ca3 100644 --- a/src/DocumentDbTests/Writing/Identity/Sequences/IdentityKeyGenerationTests.cs +++ b/src/DocumentDbTests/Writing/Identity/Sequences/IdentityKeyGenerationTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; using Shouldly; @@ -9,16 +10,16 @@ namespace DocumentDbTests.Writing.Identity.Sequences; public class IdentityKeyGenerationTests : OneOffConfigurationsContext { [Fact] - public void When_documents_are_stored_after_each_other_then_the_first_id_should_be_less_than_the_second() + public async Task When_documents_are_stored_after_each_other_then_the_first_id_should_be_less_than_the_second() { StoreOptions(_ => { _.Schema.For().UseIdentityKey(); }); - StoreUser(theStore, "User1"); - StoreUser(theStore, "User2"); - StoreUser(theStore, "User3"); + await StoreUser(theStore, "User1"); + await StoreUser(theStore, "User2"); + await StoreUser(theStore, "User3"); var users = GetUsers(theStore); @@ -62,11 +63,11 @@ private static UserWithString[] GetUsers(IDocumentStore documentStore) return session.Query().ToArray(); } - private static void StoreUser(IDocumentStore documentStore, string lastName) + private static async Task StoreUser(IDocumentStore documentStore, string lastName) { using var session = documentStore.IdentitySession(); session.Store(new UserWithString { LastName = lastName}); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/DocumentDbTests/Writing/Identity/private_identity_fields.cs b/src/DocumentDbTests/Writing/Identity/private_identity_fields.cs index eb58179c09..dd99777f37 100644 --- a/src/DocumentDbTests/Writing/Identity/private_identity_fields.cs +++ b/src/DocumentDbTests/Writing/Identity/private_identity_fields.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -13,12 +14,12 @@ public private_identity_fields(DefaultStoreFixture fixture) : base(fixture) } [Fact] - public void when_id_setter_is_private() + public async Task when_id_setter_is_private() { var user = new UserWithPrivateId(); theSession.Store(user); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); user.Id.ShouldNotBe(Guid.Empty); @@ -27,13 +28,13 @@ public void when_id_setter_is_private() } [Fact] - public void when_no_id_setter() + public async Task when_no_id_setter() { var user = new UserWithoutIdSetter(); theSession.Store(user); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); user.Id.ShouldBe(Guid.Empty); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Writing/Identity/using_int_identity.cs b/src/DocumentDbTests/Writing/Identity/using_int_identity.cs index 0ab2f6135c..b5005579d8 100644 --- a/src/DocumentDbTests/Writing/Identity/using_int_identity.cs +++ b/src/DocumentDbTests/Writing/Identity/using_int_identity.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -9,12 +10,12 @@ namespace DocumentDbTests.Writing.Identity; public class using_int_identity : IntegrationContext { [Fact] - public void persist_and_load() + public async Task persist_and_load() { var IntDoc = new IntDoc { Id = 456 }; theSession.Store(IntDoc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.LightweightSession(); SpecificationExtensions.ShouldNotBeNull(session.Load(456)); @@ -40,17 +41,17 @@ public void auto_assign_id_for_0_id() } [Fact] - public void persist_and_delete() + public async Task persist_and_delete() { var IntDoc = new IntDoc { Id = 567 }; theSession.Store(IntDoc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Delete(IntDoc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -60,14 +61,14 @@ public void persist_and_delete() } [Fact] - public void load_by_array_of_ids() + public async Task load_by_array_of_ids() { theSession.Store(new IntDoc { Id = 3 }); theSession.Store(new IntDoc { Id = 4 }); theSession.Store(new IntDoc { Id = 5 }); theSession.Store(new IntDoc { Id = 6 }); theSession.Store(new IntDoc { Id = 7 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.QuerySession(); session.LoadMany(4, 5, 6).Count().ShouldBe(3); diff --git a/src/DocumentDbTests/Writing/Identity/using_long_identity.cs b/src/DocumentDbTests/Writing/Identity/using_long_identity.cs index ab608f82e2..6b36bae5d5 100644 --- a/src/DocumentDbTests/Writing/Identity/using_long_identity.cs +++ b/src/DocumentDbTests/Writing/Identity/using_long_identity.cs @@ -41,17 +41,17 @@ public void auto_assign_id_for_0_id() } [Fact] - public void persist_and_delete() + public async Task persist_and_delete() { var LongDoc = new LongDoc { Id = 567 }; theSession.Store(LongDoc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Delete((int) LongDoc.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -61,14 +61,14 @@ public void persist_and_delete() } [Fact] - public void load_by_array_of_ids() + public async Task load_by_array_of_ids() { theSession.Store(new LongDoc{Id = 3}); theSession.Store(new LongDoc{Id = 4}); theSession.Store(new LongDoc{Id = 5}); theSession.Store(new LongDoc{Id = 6}); theSession.Store(new LongDoc{Id = 7}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.QuerySession(); session.LoadMany(4, 5, 6).Count().ShouldBe(3); diff --git a/src/DocumentDbTests/Writing/Identity/using_natural_identity_keys.cs b/src/DocumentDbTests/Writing/Identity/using_natural_identity_keys.cs index 01b7cba943..7eed3a382d 100644 --- a/src/DocumentDbTests/Writing/Identity/using_natural_identity_keys.cs +++ b/src/DocumentDbTests/Writing/Identity/using_natural_identity_keys.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using JasperFx.Core; using JasperFx.Core.Reflection; using Marten.Schema; @@ -33,14 +34,14 @@ public void finds_the_right_id_member_for_doc_with_both_id_column_and_identity_a } [Fact] - public void can_persist_with_natural_key() + public async Task can_persist_with_natural_key() { var doc = new NonStandardDoc { Name = "somebody" }; using (var session = theStore.LightweightSession()) { session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/DocumentDbTests/Writing/Identity/using_string_identity.cs b/src/DocumentDbTests/Writing/Identity/using_string_identity.cs index 5a655cffa5..642d182054 100644 --- a/src/DocumentDbTests/Writing/Identity/using_string_identity.cs +++ b/src/DocumentDbTests/Writing/Identity/using_string_identity.cs @@ -11,12 +11,12 @@ namespace DocumentDbTests.Writing.Identity; public class using_string_identity : IntegrationContext { [Fact] - public void persist_and_load() + public async Task persist_and_load() { var account = new Account{Id = "email@server.com"}; theSession.Store(account); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.QuerySession(); session.Load("email@server.com").ShouldNotBeNull(); @@ -64,17 +64,17 @@ public void throws_exception_if_trying_to_save_empty_id() } [Fact] - public void persist_and_delete() + public async Task persist_and_delete() { var account = new Account { Id = "email@server.com" }; theSession.Store(account); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Delete(account.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -84,7 +84,7 @@ public void persist_and_delete() } [Fact] - public void load_by_array_of_ids() + public async Task load_by_array_of_ids() { theSession.Store(new Account { Id = "A" }); theSession.Store(new Account { Id = "B" }); @@ -92,7 +92,7 @@ public void load_by_array_of_ids() theSession.Store(new Account { Id = "D" }); theSession.Store(new Account { Id = "E" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.QuerySession(); session.LoadMany("A", "B", "E").Count().ShouldBe(3); diff --git a/src/DocumentDbTests/Writing/bulk_loading.cs b/src/DocumentDbTests/Writing/bulk_loading.cs index 5c952fb015..42b7a20097 100644 --- a/src/DocumentDbTests/Writing/bulk_loading.cs +++ b/src/DocumentDbTests/Writing/bulk_loading.cs @@ -265,7 +265,7 @@ public async Task load_with_small_batch_async() [Fact] public async Task load_across_multiple_tenants_async() { - StoreOptions(opts => + StoreOptions(opts => { opts.Policies.AllDocumentsAreMultiTenanted(); }); @@ -402,7 +402,7 @@ public async Task load_with_small_batch_and_overwrites_smoke_test_async() } [Fact] - public void store_multiple_types_of_documents_at_one_time() + public async Task store_multiple_types_of_documents_at_one_time() { var user1 = new User(); var user2 = new User(); @@ -412,7 +412,7 @@ public void store_multiple_types_of_documents_at_one_time() var company2 = new Company(); theSession.Store(user1, user2, issue1, issue2, company1, company2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var querying = theStore.QuerySession()) { @@ -423,7 +423,7 @@ public void store_multiple_types_of_documents_at_one_time() } [Fact] - public void store_multiple_types_of_documents_at_one_time_by_StoreObjects() + public async Task store_multiple_types_of_documents_at_one_time_by_StoreObjects() { var user1 = new User(); var user2 = new User(); @@ -434,7 +434,7 @@ public void store_multiple_types_of_documents_at_one_time_by_StoreObjects() var documents = new object[] { user1, user2, issue1, issue2, company1, company2}; theSession.StoreObjects(documents); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var querying = theStore.QuerySession()) { @@ -497,7 +497,7 @@ public void load_enlist_transaction() { theStore.BulkInsertEnlistTransaction(data, Transaction.Current); scope.Complete(); - } + } using var session = theStore.QuerySession(); session.Query().Count().ShouldBe(data.Length); @@ -510,7 +510,7 @@ public void load_enlist_transaction_no_commit() using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { - theStore.BulkInsertEnlistTransaction(data, Transaction.Current); + theStore.BulkInsertEnlistTransaction(data, Transaction.Current); } using var session = theStore.QuerySession(); diff --git a/src/DocumentDbTests/Writing/document_inserts.cs b/src/DocumentDbTests/Writing/document_inserts.cs index c14c0f0506..d62d19aac5 100644 --- a/src/DocumentDbTests/Writing/document_inserts.cs +++ b/src/DocumentDbTests/Writing/document_inserts.cs @@ -12,12 +12,12 @@ namespace DocumentDbTests.Writing; public class document_inserts: IntegrationContext { [Fact] - public void can_insert_all_new_documents() + public async Task can_insert_all_new_documents() { using (var session = theStore.LightweightSession()) { session.Insert(Target.GenerateRandomData(99).ToArray()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -48,14 +48,14 @@ public async Task can_insert_a_mixed_bag_of_documents() } [Fact] - public void can_insert_records() + public async Task can_insert_records() { var docs = new RecordDocument(Guid.NewGuid(), Guid.NewGuid().ToString()); using (var session = theStore.LightweightSession()) { session.Store(docs); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -68,7 +68,7 @@ public record RecordDocument(Guid Id, string Name); [Fact] - public void insert_sad_path() + public async Task insert_sad_path() { var target = Target.Random(); @@ -77,17 +77,17 @@ public void insert_sad_path() using (var session = theStore.LightweightSession()) { session.Insert(target); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion using (var session = theStore.LightweightSession()) { - Exception.ShouldBeThrownBy(() => + await Should.ThrowAsync(async () => { session.Insert(target); - session.SaveChanges(); + await session.SaveChangesAsync(); }); } } diff --git a/src/DocumentDbTests/Writing/document_updates.cs b/src/DocumentDbTests/Writing/document_updates.cs index 19df47e813..207edaf511 100644 --- a/src/DocumentDbTests/Writing/document_updates.cs +++ b/src/DocumentDbTests/Writing/document_updates.cs @@ -14,7 +14,7 @@ public class document_updates: IntegrationContext [Fact] - public void can_update_existing_documents() + public async Task can_update_existing_documents() { var targets = Target.GenerateRandomData(99).ToArray(); theStore.BulkInsert(targets); @@ -24,7 +24,7 @@ public void can_update_existing_documents() { targets[0].Double = theNewNumber; session.Update(targets[0]); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -35,15 +35,16 @@ public void can_update_existing_documents() } [Fact] - public void update_sad_path() + public async Task update_sad_path() { var target = Target.Random(); using var session = theStore.LightweightSession(); - Exception.ShouldBeThrownBy(() => + + await Should.ThrowAsync(async () => { session.Update(target); - session.SaveChanges(); + await session.SaveChangesAsync(); }); } diff --git a/src/DocumentDbTests/Writing/storing_documents.cs b/src/DocumentDbTests/Writing/storing_documents.cs index 176554da15..27e595a815 100644 --- a/src/DocumentDbTests/Writing/storing_documents.cs +++ b/src/DocumentDbTests/Writing/storing_documents.cs @@ -21,14 +21,14 @@ public storing_documents(DefaultStoreFixture fixture): base(fixture) [Theory] [InlineData(DocumentTracking.IdentityOnly)] [InlineData(DocumentTracking.None)] - public void store_a_document(DocumentTracking tracking) + public async Task store_a_document(DocumentTracking tracking) { using var session = OpenSession(tracking); var user = new User { FirstName = "James", LastName = "Worthy" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var session3 = theStore.LightweightSession(); var user3 = session3.Load(user.Id); @@ -39,13 +39,13 @@ public void store_a_document(DocumentTracking tracking) [Theory] [InlineData(DocumentTracking.IdentityOnly)] [InlineData(DocumentTracking.None)] - public void store_and_update_a_document_then_document_should_not_be_updated(DocumentTracking tracking) + public async Task store_and_update_a_document_then_document_should_not_be_updated(DocumentTracking tracking) { var user = new User { FirstName = "James", LastName = "Worthy" }; using var session = OpenSession(tracking); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using (var session2 = theStore.LightweightSession()) { @@ -55,7 +55,7 @@ public void store_and_update_a_document_then_document_should_not_be_updated(Docu user2.FirstName = "Jens"; user2.LastName = "Pettersson"; - session2.SaveChanges(); + await session2.SaveChangesAsync(); } using (var session3 = theStore.LightweightSession()) @@ -69,7 +69,7 @@ public void store_and_update_a_document_then_document_should_not_be_updated(Docu [Theory] [InlineData(DocumentTracking.IdentityOnly)] [InlineData(DocumentTracking.None)] - public void store_and_update_a_document_in_same_session_then_document_should_not_be_updated( + public async Task store_and_update_a_document_in_same_session_then_document_should_not_be_updated( DocumentTracking tracking) { using var session = OpenSession(tracking); @@ -77,11 +77,11 @@ public void store_and_update_a_document_in_same_session_then_document_should_not var user = new User { FirstName = "James", LastName = "Worthy" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); user.FirstName = "Jens"; user.LastName = "Pettersson"; - session.SaveChanges(); + await session.SaveChangesAsync(); using var session3 = theStore.QuerySession(); var user3 = session3.Load(user.Id); @@ -92,7 +92,7 @@ public void store_and_update_a_document_in_same_session_then_document_should_not [Theory] [InlineData(DocumentTracking.IdentityOnly)] [InlineData(DocumentTracking.None)] - public void store_reload_and_update_a_document_in_same_session_then_document_should_not_be_updated( + public async Task store_reload_and_update_a_document_in_same_session_then_document_should_not_be_updated( DocumentTracking tracking) { using var session = OpenSession(tracking); @@ -100,12 +100,12 @@ public void store_reload_and_update_a_document_in_same_session_then_document_sho var user = new User { FirstName = "James", LastName = "Worthy" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var user2 = session.Load(user.Id); user2.FirstName = "Jens"; user2.LastName = "Pettersson"; - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = theStore.QuerySession(); var user3 = querySession.Load(user.Id); @@ -124,14 +124,14 @@ public void store_document_inherited_from_document_with_id_from_another_assembly [Theory] [SessionTypes] - public void persist_a_single_document(DocumentTracking tracking) + public async Task persist_a_single_document(DocumentTracking tracking) { using var session = OpenSession(tracking); var user = new User { FirstName = "Magic", LastName = "Johnson" }; session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var conn = theStore.Tenancy.Default.Database.CreateConnection(); conn.Open(); @@ -148,7 +148,7 @@ public void persist_a_single_document(DocumentTracking tracking) [Theory] [SessionTypes] - public void persist_and_reload_a_document(DocumentTracking tracking) + public async Task persist_and_reload_a_document(DocumentTracking tracking) { using var session = OpenSession(tracking); @@ -156,7 +156,7 @@ public void persist_and_reload_a_document(DocumentTracking tracking) // session is Marten's IDocumentSession service session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var session2 = theStore.LightweightSession(); session2.ShouldNotBeSameAs(session); @@ -200,7 +200,7 @@ public void try_to_load_a_document_that_does_not_exist(DocumentTracking tracking [Theory] [SessionTypes] - public void load_by_id_array(DocumentTracking tracking) + public async Task load_by_id_array(DocumentTracking tracking) { using var session = OpenSession(tracking); @@ -215,7 +215,7 @@ public void load_by_id_array(DocumentTracking tracking) session.Store(user3); session.Store(user4); session.Store(user5); - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = theStore.QuerySession(); var users = querySession.LoadMany(user2.Id, user3.Id, user4.Id); diff --git a/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs b/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs index e737330df5..a83029371b 100644 --- a/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs +++ b/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs @@ -249,7 +249,7 @@ public async Task use_inline_asynchronous() } [Fact] - public void use_inline_synchronous() + public async Task use_inline_synchronous() { StoreOptions(opts => opts.Projections.Add(new MyCustomProjection(), ProjectionLifecycle.Inline)); @@ -268,7 +268,7 @@ public void use_inline_synchronous() appendCustomEvent(1, 'a'); appendCustomEvent(1, 'a'); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Load(1) .ShouldBe(new CustomAggregate diff --git a/src/EventSourcingTests/Bugs/Bug_1019_event_type_not_found_bad_exception_message.cs b/src/EventSourcingTests/Bugs/Bug_1019_event_type_not_found_bad_exception_message.cs index f7cca94a99..3090de80ec 100644 --- a/src/EventSourcingTests/Bugs/Bug_1019_event_type_not_found_bad_exception_message.cs +++ b/src/EventSourcingTests/Bugs/Bug_1019_event_type_not_found_bad_exception_message.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Testing.Harness; using Weasel.Postgresql; @@ -9,7 +10,7 @@ namespace EventSourcingTests.Bugs public class Bug_1019_event_type_not_found_bad_exception_message: BugIntegrationContext { [Fact] - public void unknown_type_should_report_type_name() + public async Task unknown_type_should_report_type_name() { var streamGuid = Guid.Parse("378b8405-8cdc-40ef-bafa-2033cd3c43c3"); var typeName = "Bug1019.Product, EventSourcingTests"; @@ -18,7 +19,7 @@ public void unknown_type_should_report_type_name() { var product = new Bug1019.Product { Id = 1, Name = "prod1", Price = 108 }; session.Events.Append(streamGuid, product); - session.SaveChanges(); + await session.SaveChangesAsync(); var command = session.Connection.CreateCommand(); command.CommandText = @" update diff --git a/src/EventSourcingTests/Bugs/Bug_1069_using_generic_event_types_because_why_not.cs b/src/EventSourcingTests/Bugs/Bug_1069_using_generic_event_types_because_why_not.cs index bc484affe2..1ea132c9d1 100644 --- a/src/EventSourcingTests/Bugs/Bug_1069_using_generic_event_types_because_why_not.cs +++ b/src/EventSourcingTests/Bugs/Bug_1069_using_generic_event_types_because_why_not.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Harness; using Weasel.Core; using Xunit; @@ -25,7 +26,7 @@ public class Updated } [Fact] - public void try_to_save_then_load_events() + public async Task try_to_save_then_load_events() { var streamId = Guid.NewGuid(); var event1 = new Envelope { Value = new Created { Id = Guid.NewGuid() } }; @@ -34,19 +35,19 @@ public void try_to_save_then_load_events() using (var session = theStore.LightweightSession()) { session.Events.StartStream(streamId, event1, event2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { - var events = session.Events.FetchStream(streamId); + var events = await session.Events.FetchStreamAsync(streamId); events.Select(x => x.Data.GetType()) .ShouldHaveTheSameElementsAs(typeof(Envelope), typeof(Envelope)); } } [Fact] - public void try_to_save_then_load_events_across_stores() + public async Task try_to_save_then_load_events_across_stores() { var streamId = Guid.NewGuid(); var event1 = new Envelope { Value = new Created { Id = Guid.NewGuid() } }; @@ -55,7 +56,7 @@ public void try_to_save_then_load_events_across_stores() using (var session = theStore.LightweightSession()) { session.Events.StartStream(streamId, event1, event2); - session.SaveChanges(); + await session.SaveChangesAsync(); } var store2 = SeparateStore(_ => @@ -71,4 +72,4 @@ public void try_to_save_then_load_events_across_stores() } } -} \ No newline at end of file +} diff --git a/src/EventSourcingTests/Bugs/Bug_1754_multiple_event_stream_creations_one_session.cs b/src/EventSourcingTests/Bugs/Bug_1754_multiple_event_stream_creations_one_session.cs index a8a03abc14..89e45aadab 100644 --- a/src/EventSourcingTests/Bugs/Bug_1754_multiple_event_stream_creations_one_session.cs +++ b/src/EventSourcingTests/Bugs/Bug_1754_multiple_event_stream_creations_one_session.cs @@ -46,7 +46,7 @@ public async Task should_be_able_to_handle_multiple_event_streams_in_one_session } [Fact] - public void should_be_able_to_handle_multiple_event_streams_in_one_session_sync() + public async Task should_be_able_to_handle_multiple_event_streams_in_one_session_sync() { using var documentStore = SeparateStore(x => { @@ -69,7 +69,7 @@ public void should_be_able_to_handle_multiple_event_streams_in_one_session_sync( } session.Events.Append("original", new DataImportFinishedEvent {ImportCount = importCount}); - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = documentStore.QuerySession(); var importAggregate = querySession.Load(importStream.Key); diff --git a/src/EventSourcingTests/Bugs/Bug_1758_creating_stream_runs_extra_selects_and_deletes.cs b/src/EventSourcingTests/Bugs/Bug_1758_creating_stream_runs_extra_selects_and_deletes.cs index fe437f78cf..028db75378 100644 --- a/src/EventSourcingTests/Bugs/Bug_1758_creating_stream_runs_extra_selects_and_deletes.cs +++ b/src/EventSourcingTests/Bugs/Bug_1758_creating_stream_runs_extra_selects_and_deletes.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Events.Projections; using Marten.Services; @@ -14,7 +15,7 @@ namespace EventSourcingTests.Bugs; public class Bug_1758_creating_stream_runs_extra_selects_and_deletes : BugIntegrationContext { [Fact] - public void should_not_run_selects_and_deletes_to_non_affected_aggregates() + public async Task should_not_run_selects_and_deletes_to_non_affected_aggregates() { var logger = new CollectingLogger(); @@ -30,7 +31,7 @@ public void should_not_run_selects_and_deletes_to_non_affected_aggregates() using var session = documentStore.LightweightSession(); var id = session.Events.StartStream(new CreateAEvent {Name = "Test"}).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); var commit = logger.LastCommit; diff --git a/src/EventSourcingTests/Bugs/Bug_2289_tombstone_events_violate_seq_id_uniqueness.cs b/src/EventSourcingTests/Bugs/Bug_2289_tombstone_events_violate_seq_id_uniqueness.cs index 64cf6625b3..2bceff9407 100644 --- a/src/EventSourcingTests/Bugs/Bug_2289_tombstone_events_violate_seq_id_uniqueness.cs +++ b/src/EventSourcingTests/Bugs/Bug_2289_tombstone_events_violate_seq_id_uniqueness.cs @@ -2,6 +2,7 @@ using Marten.Testing.Harness; using Shouldly; using System.Linq; +using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; @@ -17,13 +18,13 @@ public Bug_2289_tombstone_events_violate_seq_id_uniqueness(ITestOutputHelper out } [Fact] - public void ensure_tombstone_event_has_sequence_set() + public async Task ensure_tombstone_event_has_sequence_set() { var joined = new MembersJoined { Members = new string[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; var stream = theSession.Events.StartStream(joined).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.Append(stream, 2, departed); @@ -33,10 +34,13 @@ public void ensure_tombstone_event_has_sequence_set() var departed3 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(stream, joined3, departed3); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Assert.Throws(() => theSession.SaveChanges()); + await Should.ThrowAsync(async () => + { + await theSession.SaveChangesAsync(); + }); var firstSequence = theSession.Events.QueryAllRawEvents() .OrderBy(e => e.Sequence) diff --git a/src/EventSourcingTests/Bugs/codegen_issue_with_IEvent.cs b/src/EventSourcingTests/Bugs/codegen_issue_with_IEvent.cs index 56270f6b49..cd4a25e78c 100644 --- a/src/EventSourcingTests/Bugs/codegen_issue_with_IEvent.cs +++ b/src/EventSourcingTests/Bugs/codegen_issue_with_IEvent.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Marten.Events; using Marten.Events.Projections; using Marten.Testing.Harness; @@ -10,7 +11,7 @@ namespace EventSourcingTests.Bugs; public class CodeGenIEventIssue: BugIntegrationContext { [Fact] - public void TestAggregation() + public async Task TestAggregation() { var store = StoreOptions(_ => { @@ -19,11 +20,11 @@ public void TestAggregation() using var session = store.LightweightSession(); session.Events.Append(Guid.NewGuid(), new FooCreated { Id = Guid.NewGuid() }); - session.SaveChanges(); + await session.SaveChangesAsync(); } [Fact] - public void TestRecordAggregation() + public async Task TestRecordAggregation() { var store = StoreOptions(_ => { @@ -35,7 +36,7 @@ public void TestRecordAggregation() session.Events.Append(id, new RecordLogCreated(id)); session.Events.Append(id, new RecordLogUpdated(id)); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/EventSourcingTests/Projections/CodeGeneration/aggregation_with_event_type_hierarchy.cs b/src/EventSourcingTests/Projections/CodeGeneration/aggregation_with_event_type_hierarchy.cs index 867f73d636..d3f8dd9334 100644 --- a/src/EventSourcingTests/Projections/CodeGeneration/aggregation_with_event_type_hierarchy.cs +++ b/src/EventSourcingTests/Projections/CodeGeneration/aggregation_with_event_type_hierarchy.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using JasperFx.CodeGeneration; using Marten.Events.Projections; using Marten.Testing.Harness; @@ -24,7 +25,7 @@ public aggregation_with_event_type_hierarchy() } [Fact] - public void inline_snapshot_can_project_with_base_types() + public async Task inline_snapshot_can_project_with_base_types() { var id = Guid.NewGuid(); @@ -35,7 +36,7 @@ public void inline_snapshot_can_project_with_base_types() new SomethingUpdated(id) ); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var something = theSession.Load(id); @@ -44,20 +45,20 @@ public void inline_snapshot_can_project_with_base_types() something.AddedCount.ShouldBe(1); theSession.Events.Append(id, new SomethingManuallySynched(id)); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); something = theSession.Load(id); something.Value.ShouldBe(SomethingManuallySynched.DefaultValue); theSession.Events.Append(id, new SomethingAutoSynched(id)); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); something = theSession.Load(id); something.Value.ShouldBe(SomethingAutoSynched.DefaultValue); } [Fact] - public void inline_snapshot_can_project_with_interface() + public async Task inline_snapshot_can_project_with_interface() { var id = Guid.NewGuid(); @@ -69,7 +70,7 @@ public void inline_snapshot_can_project_with_interface() new SomethingUnmappedEvent(id) ); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var something = theSession.Load(id); diff --git a/src/EventSourcingTests/Projections/EventProjectionTests.cs b/src/EventSourcingTests/Projections/EventProjectionTests.cs index bbdcfe08f0..ca441c4b22 100644 --- a/src/EventSourcingTests/Projections/EventProjectionTests.cs +++ b/src/EventSourcingTests/Projections/EventProjectionTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Events; using Marten.Events.Projections; @@ -34,7 +35,7 @@ public void documents_created_by_event_projection_should_be_registered_as_docume } [Fact] - public void use_simple_synchronous_project_methods() + public async Task use_simple_synchronous_project_methods() { UseProjection(); @@ -42,7 +43,7 @@ public void use_simple_synchronous_project_methods() theSession.Events.StartStream(stream, new UserCreated { UserName = "one" }, new UserCreated { UserName = "two" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); @@ -51,7 +52,7 @@ public void use_simple_synchronous_project_methods() .ShouldHaveTheSameElementsAs("one", "two"); theSession.Events.Append(stream, new UserDeleted { UserName = "one" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); query.Query() .OrderBy(x => x.UserName) @@ -61,7 +62,7 @@ public void use_simple_synchronous_project_methods() } [Fact] - public void use_simple_synchronous_project_methods_with_inline_lambdas() + public async Task use_simple_synchronous_project_methods_with_inline_lambdas() { UseProjection(); @@ -69,7 +70,7 @@ public void use_simple_synchronous_project_methods_with_inline_lambdas() theSession.Events.StartStream(stream, new UserCreated { UserName = "one" }, new UserCreated { UserName = "two" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); @@ -78,7 +79,7 @@ public void use_simple_synchronous_project_methods_with_inline_lambdas() .ShouldHaveTheSameElementsAs("one", "two"); theSession.Events.Append(stream, new UserDeleted { UserName = "one" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); query.Query() .OrderBy(x => x.UserName) @@ -88,7 +89,7 @@ public void use_simple_synchronous_project_methods_with_inline_lambdas() } [Fact] - public void synchronous_create_method() + public async Task synchronous_create_method() { UseProjection(); @@ -96,7 +97,7 @@ public void synchronous_create_method() theSession.Events.StartStream(stream, new UserCreated { UserName = "one" }, new UserCreated { UserName = "two" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); @@ -105,7 +106,7 @@ public void synchronous_create_method() .ShouldHaveTheSameElementsAs("one", "two"); theSession.Events.Append(stream, new UserDeleted { UserName = "one" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); query.Query() .OrderBy(x => x.UserName) @@ -115,7 +116,7 @@ public void synchronous_create_method() } [Fact] - public void use_event_metadata() + public async Task use_event_metadata() { UseProjection(); @@ -123,11 +124,11 @@ public void use_event_metadata() theSession.Events.Append(stream, new UserCreated { UserName = "one" }, new UserCreated { UserName = "two" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } [Fact] - public void use_event_metadata_with_string_stream_identity() + public async Task use_event_metadata_with_string_stream_identity() { StoreOptions(x => { @@ -139,14 +140,14 @@ public void use_event_metadata_with_string_stream_identity() theSession.Events.StartStream(stream, new UserCreated { UserName = "one" }, new UserCreated { UserName = "two" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.Append(stream, new UserCreated { UserName = "three" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } [Fact] - public void synchronous_with_transform_method() + public async Task synchronous_with_transform_method() { UseProjection(); @@ -154,7 +155,7 @@ public void synchronous_with_transform_method() theSession.Events.StartStream(stream, new UserCreated { UserName = "one" }, new UserCreated { UserName = "two" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); @@ -163,7 +164,7 @@ public void synchronous_with_transform_method() .ShouldHaveTheSameElementsAs("one", "two"); theSession.Events.Append(stream, new UserDeleted { UserName = "one" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); query.Query() .OrderBy(x => x.UserName) diff --git a/src/EventSourcingTests/Projections/inline_aggregation_by_stream_with_multiples.cs b/src/EventSourcingTests/Projections/inline_aggregation_by_stream_with_multiples.cs index 0919f12e17..cca61aa018 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_by_stream_with_multiples.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_by_stream_with_multiples.cs @@ -26,7 +26,7 @@ public class inline_aggregation_by_stream_with_multiples: OneOffConfigurationsCo [Theory] [InlineData(TenancyStyle.Single)] [InlineData(TenancyStyle.Conjoined)] - public void run_multiple_aggregates_sync(TenancyStyle tenancyStyle) + public async Task run_multiple_aggregates_sync(TenancyStyle tenancyStyle) { #region sample_registering-quest-party @@ -47,16 +47,16 @@ public void run_multiple_aggregates_sync(TenancyStyle tenancyStyle) #endregion - StoreOptions(_ => + StoreOptions(opts => { - _.AutoCreateSchemaObjects = AutoCreate.All; - _.Projections.Snapshot(SnapshotLifecycle.Inline); - _.Projections.Snapshot(SnapshotLifecycle.Inline); + opts.AutoCreateSchemaObjects = AutoCreate.All; + opts.Projections.Snapshot(SnapshotLifecycle.Inline); + opts.Projections.Snapshot(SnapshotLifecycle.Inline); }); var streamId = theSession.Events .StartStream(started, joined, slayed1, slayed2, joined2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Load(streamId).Monsters.ShouldHaveTheSameElementsAs("Troll", "Dragon"); diff --git a/src/EventSourcingTests/Projections/inline_aggregation_with_base_view_class.cs b/src/EventSourcingTests/Projections/inline_aggregation_with_base_view_class.cs index 6c74a888d9..ed9ba4309f 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_with_base_view_class.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_with_base_view_class.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Events.Projections; using Marten.Testing.Harness; using Shouldly; @@ -8,11 +9,11 @@ namespace EventSourcingTests.Projections; -public class inline_aggregation_with_base_view_class: OneOffConfigurationsContext +public class inline_aggregation_with_base_view_class: OneOffConfigurationsContext, IAsyncLifetime { private readonly MonsterSlayed slayed1 = new MonsterSlayed { Name = "Troll" }; private readonly MonsterSlayed slayed2 = new MonsterSlayed { Name = "Dragon" }; - private readonly Guid streamId; + private Guid streamId; public inline_aggregation_with_base_view_class() { @@ -23,11 +24,19 @@ public inline_aggregation_with_base_view_class() _.Projections.Snapshot(SnapshotLifecycle.Inline); _.Projections.Snapshot(SnapshotLifecycle.Inline); }); + } + public async Task InitializeAsync() + { streamId = theSession.Events .StartStream(slayed1, slayed2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } [Fact] diff --git a/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs b/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs index fb96ce80b2..ab5ac00e4d 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Events.Aggregation; using Marten.Events.Projections; using Marten.Testing.Harness; @@ -23,7 +24,7 @@ public void does_call_custom_projection_configuration() } [Fact] - public void does_delete_document_upon_deleted_event() + public async Task does_delete_document_upon_deleted_event() { StoreOptions(_ => { @@ -35,14 +36,14 @@ public void does_delete_document_upon_deleted_event() var todoId = Guid.NewGuid(); theSession.Events.StartStream(todoId, new TodoCreated(todoId, "Write code")); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Make sure the document has been created theSession.Load(todoId).ShouldNotBeNull(); // Append the delete theSession.Events.Append(todoId, new TodoDeleted(todoId)); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Make sure the document now has been deleted theSession.Load(todoId).ShouldBeNull(); diff --git a/src/EventSourcingTests/Projections/inline_aggregation_with_non_public_setter.cs b/src/EventSourcingTests/Projections/inline_aggregation_with_non_public_setter.cs index bc1be0fdd2..9c23fdf9ca 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_with_non_public_setter.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_with_non_public_setter.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Events.Projections; using Marten.Testing.Harness; @@ -9,26 +10,34 @@ namespace EventSourcingTests.Projections; -public class inline_aggregation_with_non_public_setter: OneOffConfigurationsContext +public class inline_aggregation_with_non_public_setter: OneOffConfigurationsContext, IAsyncLifetime { private readonly MonsterSlayed slayed1 = new MonsterSlayed { Name = "Troll" }; private readonly MonsterSlayed slayed2 = new MonsterSlayed { Name = "Dragon" }; - private readonly Guid streamId; + private Guid streamId; public inline_aggregation_with_non_public_setter() { - StoreOptions(_ => + StoreOptions(opts => { - _.AutoCreateSchemaObjects = AutoCreate.All; - _.UseDefaultSerialization(nonPublicMembersStorage: NonPublicMembersStorage.NonPublicSetters); - _.Projections.Snapshot(SnapshotLifecycle.Inline); - _.Projections.Snapshot(SnapshotLifecycle.Inline); + opts.AutoCreateSchemaObjects = AutoCreate.All; + opts.UseDefaultSerialization(nonPublicMembersStorage: NonPublicMembersStorage.NonPublicSetters); + opts.Projections.Snapshot(SnapshotLifecycle.Inline); + opts.Projections.Snapshot(SnapshotLifecycle.Inline); }); + } + public async Task InitializeAsync() + { streamId = theSession.Events .StartStream(slayed1, slayed2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } [Fact] diff --git a/src/EventSourcingTests/Projections/inline_aggregation_with_private_constructor.cs b/src/EventSourcingTests/Projections/inline_aggregation_with_private_constructor.cs index 594b21bfaa..4ced92ebe1 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_with_private_constructor.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_with_private_constructor.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Events.Projections; using Marten.Testing.Harness; @@ -39,14 +40,14 @@ public void run_inline_aggregation_with_private_constructor() Verify(); } - private void Verify() where T : IMonstersView + private async Task Verify() where T : IMonstersView { var slayed1 = new MonsterSlayed { Name = "Troll" }; var slayed2 = new MonsterSlayed { Name = "Dragon" }; var streamId = theSession.Events .StartStream(slayed1, slayed2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var loadedView = theSession.Load(streamId); diff --git a/src/EventSourcingTests/Projections/inline_aggregation_with_subclass.cs b/src/EventSourcingTests/Projections/inline_aggregation_with_subclass.cs index eef07c10c8..de6f195b95 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_with_subclass.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_with_subclass.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Events.Projections; using Marten.Testing.Harness; using Shouldly; @@ -20,12 +21,12 @@ public inline_aggregation_with_subclass() } [Fact] - public void can_create_subclass_projection() + public async Task can_create_subclass_projection() { var description = "FooDescription"; var streamId = theSession.Events.StartStream(new FooACreated { Description = description }).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var fooInstance = theSession.Query().Single(x => x.Id == streamId); @@ -34,12 +35,12 @@ public void can_create_subclass_projection() } [Fact] - public void can_query_subclass_root() + public async Task can_query_subclass_root() { var description = "FooDescription"; var streamId = theSession.Events.StartStream(new FooACreated { Description = description }).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var fooInstance = theSession.Query().Single(x => x.Id == streamId); diff --git a/src/EventSourcingTests/Projections/inline_transformation_of_events.cs b/src/EventSourcingTests/Projections/inline_transformation_of_events.cs index 72e07d2db8..591a17dcff 100644 --- a/src/EventSourcingTests/Projections/inline_transformation_of_events.cs +++ b/src/EventSourcingTests/Projections/inline_transformation_of_events.cs @@ -57,7 +57,7 @@ private async Task sample_usage() [Theory] [InlineData(TenancyStyle.Single)] [InlineData(TenancyStyle.Conjoined)] - public void sync_projection_of_events(TenancyStyle tenancyStyle) + public async Task sync_projection_of_events(TenancyStyle tenancyStyle) { StoreOptions(_ => { @@ -69,10 +69,10 @@ public void sync_projection_of_events(TenancyStyle tenancyStyle) var streamId = theSession.Events .StartStream(started, joined, slayed1, slayed2, joined2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var monsterEvents = - theSession.Events.FetchStream(streamId).OfType>().ToArray(); + (await theSession.Events.FetchStreamAsync(streamId)).OfType>().ToArray(); monsterEvents.Length.ShouldBe(2); // precondition @@ -84,7 +84,7 @@ public void sync_projection_of_events(TenancyStyle tenancyStyle) } [Fact] - public void sync_projection_of_events_with_direct_configuration() + public async Task sync_projection_of_events_with_direct_configuration() { StoreOptions(_ => { @@ -95,10 +95,10 @@ public void sync_projection_of_events_with_direct_configuration() var streamId = theSession.Events .StartStream(started, joined, slayed1, slayed2, joined2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var monsterEvents = - theSession.Events.FetchStream(streamId).OfType>().ToArray(); + (await theSession.Events.FetchStreamAsync(streamId)).OfType>().ToArray(); monsterEvents.Length.ShouldBe(2); // precondition diff --git a/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream.cs b/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream.cs index 41975a5c00..d87bdab7b1 100644 --- a/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream.cs +++ b/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream.cs @@ -43,7 +43,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyl { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, _) => + When.CalledForEachAsync(tenants, async (tenantId, _) => { using var session = store.LightweightSession(tenantId); session.Logger = new TestOutputMartenLogger(_output); @@ -52,7 +52,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyl var departed = new MembersDeparted { Members = new[] { "Thom" } }; var id = session.Events.StartStream(joined, departed).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -63,7 +63,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyl streamEvents.ElementAt(1).Version.ShouldBe(2); streamEvents.Each(e => ShouldBeTestExtensions.ShouldNotBe(e.Timestamp, default(DateTimeOffset))); - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] @@ -132,7 +132,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, _) => + When.CalledForEachAsync(tenants, async (tenantId, _) => { using var session = store.LightweightSession(tenantId); @@ -140,7 +140,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l var departed = new MembersDeparted { Members = new[] { "Thom" } }; var id = session.Events.StartStream(joined, departed).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.QueryAllRawEvents() .Where(x => x.StreamId == id).OrderBy(x => x.Version).ToList(); @@ -152,18 +152,18 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l streamEvents.ElementAt(1).Version.ShouldBe(2); streamEvents.Each(e => e.Timestamp.ShouldNotBe(default(DateTimeOffset))); - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(TenancyStyle tenancyStyle, + public async Task live_aggregate_equals_inlined_aggregate_without_hidden_contracts(TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var questId = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -176,7 +176,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(Ten var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -186,7 +186,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(Ten liveAggregate.Id.ShouldBe(inlinedAggregate.Id); inlinedAggregate.ToString().ShouldBe(liveAggregate.ToString()); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -194,12 +194,12 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(Ten [Theory] [MemberData(nameof(SessionParams))] - public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle tenancyStyle, string[] tenants) + public async Task open_persisted_stream_in_new_store_with_same_settings(TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var questId = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -208,7 +208,7 @@ public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle t var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } // events-aggregate-on-the-fly - works with same store @@ -270,7 +270,7 @@ public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle t .AggregateStream(questId, timestamp: DateTimeOffset.UtcNow.AddDays(-1)); party_yesterday.ShouldBeNull(); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -278,12 +278,12 @@ public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle t [Theory] [MemberData(nameof(SessionParams))] - public void query_before_saving(TenancyStyle tenancyStyle, string[] tenants) + public async Task query_before_saving(TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var questId = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -298,12 +298,12 @@ public void query_before_saving(TenancyStyle tenancyStyle, string[] tenants) var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); var party = session.Events.AggregateStream(questId); party.Id.ShouldBe(questId); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -344,12 +344,12 @@ public Task aggregate_stream_async_has_the_id(TenancyStyle tenancyStyle, string[ [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided( + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided( TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -358,7 +358,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream var id = Guid.NewGuid(); session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -368,17 +368,17 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -389,7 +389,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back(Te session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -399,26 +399,26 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back(Te streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var started = new QuestStarted(); using (var session = store.LightweightSession(tenantId)) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -429,7 +429,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back(Tenan session.Events.Append(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -441,7 +441,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back(Tenan streamEvents.ElementAt(2).Data.ShouldBeOfType(); streamEvents.ElementAt(2).Version.ShouldBe(3); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -449,12 +449,12 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back(Tenan [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema( + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -462,7 +462,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ var departed = new MembersDeparted { Members = new[] { "Thom" } }; var id = session.Events.StartStream(joined, departed).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -472,18 +472,18 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -492,7 +492,7 @@ public void var id = Guid.NewGuid(); session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -504,17 +504,17 @@ public void streamEvents.Each(x => SpecificationExtensions.ShouldBeGreaterThan(x.Sequence, 0L)); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema( + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -525,7 +525,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -535,26 +535,26 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema( + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var started = new QuestStarted(); using (var session = store.LightweightSession(tenantId)) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -564,7 +564,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an session.Events.Append(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -576,7 +576,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an streamEvents.ElementAt(2).Data.ShouldBeOfType(); streamEvents.ElementAt(2).Version.ShouldBe(3); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -584,32 +584,30 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an [Theory] [MemberData(nameof(SessionParams))] - public void assert_on_max_event_id_on_event_stream_append( + public async Task assert_on_max_event_id_on_event_stream_append( TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var started = new QuestStarted(); - using (var session = store.LightweightSession(tenantId)) - { - session.Events.StartStream(id, started); - session.SaveChanges(); + using var session = store.LightweightSession(tenantId); + session.Events.StartStream(id, started); + await session.SaveChangesAsync(); - var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; - var departed = new MembersDeparted { Members = new[] { "Thom" } }; + var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; + var departed = new MembersDeparted { Members = new[] { "Thom" } }; - // Events are appended into the stream only if the maximum event id for the stream - // would be 3 after the append operation. - session.Events.Append(id, 3, joined, departed); + // Events are appended into the stream only if the maximum event id for the stream + // would be 3 after the append operation. + session.Events.Append(id, 3, joined, departed); - session.SaveChanges(); - } - }).ShouldThrowIf( + await session.SaveChangesAsync(); + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -617,20 +615,20 @@ public void assert_on_max_event_id_on_event_stream_append( [Theory] [MemberData(nameof(SessionParams))] - public void capture_immutable_events(TenancyStyle tenancyStyle, string[] tenants) + public async Task capture_immutable_events(TenancyStyle tenancyStyle, string[] tenants) { var store = ConfigureStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var immutableEvent = new ImmutableEvent(id, "some-name"); using (var session = store.LightweightSession(tenantId)) { session.Events.Append(id, immutableEvent); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -643,7 +641,7 @@ public void capture_immutable_events(TenancyStyle tenancyStyle, string[] tenants @event.Id.ShouldBe(id); @event.Name.ShouldBe("some-name"); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); diff --git a/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream_with_string_identifiers.cs b/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream_with_string_identifiers.cs index 891d858dad..8df0fce859 100644 --- a/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream_with_string_identifiers.cs +++ b/src/EventSourcingTests/QuickAppend/quick_append_event_capture_and_fetching_the_stream_with_string_identifiers.cs @@ -20,7 +20,7 @@ public quick_append_event_capture_and_fetching_the_stream_with_string_identifier } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back() { var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; @@ -28,7 +28,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back() var id = "First"; theSession.Events.StartStream(id, joined, departed); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var streamEvents = theSession.Events.FetchStream(id); @@ -93,7 +93,7 @@ public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_async } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_linq() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_linq() { #region sample_start-stream-with-aggregate-type @@ -102,7 +102,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l var id = "Fourth"; theSession.Events.StartStream(id, joined, departed); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #endregion @@ -119,7 +119,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l } [Fact] - public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts() + public async Task live_aggregate_equals_inlined_aggregate_without_hidden_contracts() { var questId = "Fifth"; @@ -134,7 +134,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts() var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -147,7 +147,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts() } [Fact] - public void open_persisted_stream_in_new_store_with_same_settings() + public async Task open_persisted_stream_in_new_store_with_same_settings() { var questId = "Sixth"; @@ -158,7 +158,7 @@ public void open_persisted_stream_in_new_store_with_same_settings() var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } // events-aggregate-on-the-fly - works with same store @@ -278,7 +278,7 @@ public async Task aggregate_stream_async_has_the_id() } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -286,7 +286,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream var id = "Tenth"; session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -298,7 +298,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream } [Fact] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back() + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -308,7 +308,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back() session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -320,7 +320,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back() } [Fact] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back() + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back() { var id = "Twelth"; var started = new QuestStarted(); @@ -328,7 +328,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back() using (var session = theStore.LightweightSession()) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -339,7 +339,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back() session.Events.Append(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -354,7 +354,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back() } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -362,7 +362,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ var id = "Thirteen"; session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -375,7 +375,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ [Fact] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema() + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -385,7 +385,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -397,7 +397,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in } [Fact] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema() + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema() { var id = "Fifteen"; var started = new QuestStarted(); @@ -405,7 +405,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an using (var session = theStore.LightweightSession()) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -415,7 +415,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an session.Events.Append(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); diff --git a/src/EventSourcingTests/QuickAppend/quick_appending_events_workflow_specs.cs b/src/EventSourcingTests/QuickAppend/quick_appending_events_workflow_specs.cs index 59b351b809..a82a3a34ec 100644 --- a/src/EventSourcingTests/QuickAppend/quick_appending_events_workflow_specs.cs +++ b/src/EventSourcingTests/QuickAppend/quick_appending_events_workflow_specs.cs @@ -34,7 +34,7 @@ public class quick_appending_events_workflow_specs public quick_appending_events_workflow_specs(ITestOutputHelper output) { _output = output; - + } public class EventMetadataChecker : DocumentSessionListenerBase @@ -58,7 +58,7 @@ public override Task AfterCommitAsync(IDocumentSession session, IChangeSet commi public async Task can_fetch_stream_async(TestCase @case) { await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); - @case.StartNewStream(new TestOutputMartenLogger(_output)); + await @case.StartNewStream(new TestOutputMartenLogger(_output)); await using var query = @case.Store.QuerySession(); var builder = EventDocumentStorageGenerator.GenerateStorage(@case.Store.Options); @@ -68,21 +68,6 @@ public async Task can_fetch_stream_async(TestCase @case) state.ShouldNotBeNull(); } - [Theory] - [MemberData(nameof(Data))] - public void can_fetch_stream_sync(TestCase @case) - { - @case.Store.Advanced.Clean.CompletelyRemoveAll(); - @case.StartNewStream(); - using var query = @case.Store.QuerySession(); - - var builder = EventDocumentStorageGenerator.GenerateStorage(@case.Store.Options); - var handler = builder.QueryForStream(@case.ToEventStream()); - - var state = query.As().ExecuteHandler(handler); - state.ShouldNotBeNull(); - } - [Theory] [MemberData(nameof(Data))] public async Task can_insert_a_new_stream(TestCase @case) @@ -105,8 +90,8 @@ public async Task can_insert_a_new_stream(TestCase @case) [MemberData(nameof(Data))] public async Task can_update_the_version_of_an_existing_stream_happy_path(TestCase @case) { - @case.Store.Advanced.Clean.CompletelyRemoveAll(); - var stream = @case.StartNewStream(new TestOutputMartenLogger(_output)); + await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); + var stream = await @case.StartNewStream(new TestOutputMartenLogger(_output)); stream.ExpectedVersionOnServer = 4; stream.Version = 10; @@ -130,8 +115,8 @@ public async Task can_update_the_version_of_an_existing_stream_happy_path(TestCa [MemberData(nameof(Data))] public async Task can_update_the_version_of_an_existing_stream_sad_path(TestCase @case) { - @case.Store.Advanced.Clean.CompletelyRemoveAll(); - var stream = @case.StartNewStream(); + await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); + var stream = await @case.StartNewStream(); stream.ExpectedVersionOnServer = 3; // it's actually 4, so this should fail stream.Version = 10; @@ -301,7 +286,7 @@ public TestCase(string description, Action config) internal DocumentStore Store => _store.Value; - public StreamAction StartNewStream(IMartenSessionLogger logger = null) + public async Task StartNewStream(IMartenSessionLogger logger = null) { var events = new object[] {new AEvent(), new BEvent(), new CEvent(), new DEvent()}; using var session = Store.Events.TenancyStyle == TenancyStyle.Conjoined @@ -318,7 +303,7 @@ public StreamAction StartNewStream(IMartenSessionLogger logger = null) if (Store.Events.StreamIdentity == StreamIdentity.AsGuid) { session.Events.StartStream(StreamId, events); - session.SaveChanges(); + await session.SaveChangesAsync(); var stream = StreamAction.Append(Store.Events, StreamId); stream.Version = 4; @@ -329,7 +314,7 @@ public StreamAction StartNewStream(IMartenSessionLogger logger = null) else { session.Events.StartStream(StreamId.ToString(), events); - session.SaveChanges(); + await session.SaveChangesAsync(); var stream = StreamAction.Start(Store.Events, StreamId.ToString(), new AEvent()); stream.Version = 4; diff --git a/src/EventSourcingTests/ScenarioCopyAndReplaceStream.cs b/src/EventSourcingTests/ScenarioCopyAndReplaceStream.cs index 3df7570289..05246b20a3 100644 --- a/src/EventSourcingTests/ScenarioCopyAndReplaceStream.cs +++ b/src/EventSourcingTests/ScenarioCopyAndReplaceStream.cs @@ -26,7 +26,7 @@ public Task DisposeAsync() } [Fact] - public void SampleCopyAndTransformStream() + public async Task SampleCopyAndTransformStream() { #region sample_scenario-copyandtransformstream-setup var started = new QuestStarted { Name = "Find the Orb" }; @@ -37,7 +37,7 @@ public void SampleCopyAndTransformStream() using (var session = theStore.LightweightSession()) { session.Events.StartStream(started.Name,started, joined, slayed1, slayed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion @@ -75,7 +75,7 @@ public void SampleCopyAndTransformStream() }); // Transactionally update the streams. - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion } diff --git a/src/EventSourcingTests/Utils/MultipleActionCheck.cs b/src/EventSourcingTests/Utils/MultipleActionCheck.cs index 684a2a2bec..9d9ab66535 100644 --- a/src/EventSourcingTests/Utils/MultipleActionCheck.cs +++ b/src/EventSourcingTests/Utils/MultipleActionCheck.cs @@ -6,12 +6,9 @@ namespace EventSourcingTests.Utils; +[Obsolete("Gotta be a better way to do this")] internal static class When { - public static MultipleActionCheck CalledForEach(IEnumerable elements, Action action) - { - return new MultipleActionCheck(elements, action); - } public static MultipleActionCheck CalledForEachAsync(IEnumerable elements, Func action) { @@ -22,42 +19,19 @@ public static MultipleActionCheck CalledForEachAsync(IEnumerable elemen internal class MultipleActionCheck { private readonly T[] elements; - private readonly Action action; private readonly Func asyncAction; - internal MultipleActionCheck(IEnumerable elements, Action action) - { - this.elements = elements.ToArray(); - this.action = action; - } - internal MultipleActionCheck(IEnumerable elements, Func asyncAction) { this.elements = elements.ToArray(); this.asyncAction = asyncAction; } - public void ShouldSucceed() - { - PerformAction(); - } - public Task ShouldSucceedAsync() { return PerformActionAsync(); } - public Exception ShouldThrowIf(bool check) - { - if (!check) - { - ShouldSucceed(); - return null; - } - - return Should.Throw(PerformAction); - } - public async Task ShouldThrowIfAsync(bool check) { if (!check) @@ -69,14 +43,6 @@ public async Task ShouldThrowIfAsync(bool check) return await Should.ThrowAsync(PerformActionAsync()); } - private void PerformAction() - { - for (var i = 0; i < elements.Length; i++) - { - action(elements[i], i); - } - } - private async Task PerformActionAsync() { for (var i = 0; i < elements.Length; i++) @@ -84,4 +50,4 @@ private async Task PerformActionAsync() await asyncAction(elements[i], i); } } -} \ No newline at end of file +} diff --git a/src/EventSourcingTests/aggregateto_linq_operator_tests.cs b/src/EventSourcingTests/aggregateto_linq_operator_tests.cs index eb51da5769..91210eec33 100644 --- a/src/EventSourcingTests/aggregateto_linq_operator_tests.cs +++ b/src/EventSourcingTests/aggregateto_linq_operator_tests.cs @@ -19,11 +19,11 @@ public class aggregateTo_linq_operator_tests: DestructiveIntegrationContext private readonly MembersDeparted _departed2 = new() { Members = new[] {"Moiraine"} }; [Fact] - public void can_aggregate_events_to_aggregate_type_synchronously() + public async Task can_aggregate_events_to_aggregate_type_synchronously() { theSession.Events.StartStream(_joined1, _departed1); theSession.Events.StartStream(_joined2, _departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var events = theSession.Events.QueryAllRawEvents().ToList(); @@ -58,12 +58,12 @@ public async Task can_aggregate_events_to_aggregate_type_asynchronously() } [Fact] - public void can_aggregate_with_initial_state_synchronously() + public async Task can_aggregate_with_initial_state_synchronously() { var initialParty = new QuestParty { Members = new List { "Lan" } }; theSession.Events.StartStream(_joined1, _departed1); theSession.Events.StartStream(_joined2, _departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var questParty = theSession.Events.QueryAllRawEvents().AggregateTo(initialParty); diff --git a/src/EventSourcingTests/appending_events_workflow_specs.cs b/src/EventSourcingTests/appending_events_workflow_specs.cs index 85278adb9e..428b4c1921 100644 --- a/src/EventSourcingTests/appending_events_workflow_specs.cs +++ b/src/EventSourcingTests/appending_events_workflow_specs.cs @@ -60,7 +60,7 @@ public override Task AfterCommitAsync(IDocumentSession session, IChangeSet commi public async Task can_fetch_stream_async(TestCase @case) { await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); - @case.StartNewStream(new TestOutputMartenLogger(_output)); + await @case.StartNewStream(new TestOutputMartenLogger(_output)); await using var query = @case.Store.QuerySession(); var builder = EventDocumentStorageGenerator.GenerateStorage(@case.Store.Options); @@ -72,10 +72,10 @@ public async Task can_fetch_stream_async(TestCase @case) [Theory] [MemberData(nameof(Data))] - public void can_fetch_stream_sync(TestCase @case) + public async Task can_fetch_stream_sync(TestCase @case) { - @case.Store.Advanced.Clean.CompletelyRemoveAll(); - @case.StartNewStream(); + await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); + await @case.StartNewStream(); using var query = @case.Store.QuerySession(); var builder = EventDocumentStorageGenerator.GenerateStorage(@case.Store.Options); @@ -91,7 +91,7 @@ public async Task can_insert_a_new_stream(TestCase @case) { // This is just forcing the store to start the event storage await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); - @case.StartNewStream(); + await @case.StartNewStream(); var stream = @case.CreateNewStream(); var builder = EventDocumentStorageGenerator.GenerateStorage(@case.Store.Options); @@ -107,8 +107,8 @@ public async Task can_insert_a_new_stream(TestCase @case) [MemberData(nameof(Data))] public async Task can_update_the_version_of_an_existing_stream_happy_path(TestCase @case) { - @case.Store.Advanced.Clean.CompletelyRemoveAll(); - var stream = @case.StartNewStream(new TestOutputMartenLogger(_output)); + await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); + var stream = await @case.StartNewStream(new TestOutputMartenLogger(_output)); stream.ExpectedVersionOnServer = 4; stream.Version = 10; @@ -132,8 +132,8 @@ public async Task can_update_the_version_of_an_existing_stream_happy_path(TestCa [MemberData(nameof(Data))] public async Task can_update_the_version_of_an_existing_stream_sad_path(TestCase @case) { - @case.Store.Advanced.Clean.CompletelyRemoveAll(); - var stream = @case.StartNewStream(); + await @case.Store.Advanced.Clean.CompletelyRemoveAllAsync(); + var stream = await @case.StartNewStream(); stream.ExpectedVersionOnServer = 3; // it's actually 4, so this should fail stream.Version = 10; @@ -301,7 +301,7 @@ public TestCase(string description, Action config) internal DocumentStore Store => _store.Value; - public StreamAction StartNewStream(IMartenSessionLogger logger = null) + public async Task StartNewStream(IMartenSessionLogger logger = null) { var events = new object[] {new AEvent(), new BEvent(), new CEvent(), new DEvent()}; using var session = Store.Events.TenancyStyle == TenancyStyle.Conjoined @@ -318,7 +318,7 @@ public StreamAction StartNewStream(IMartenSessionLogger logger = null) if (Store.Events.StreamIdentity == StreamIdentity.AsGuid) { session.Events.StartStream(StreamId, events); - session.SaveChanges(); + await session.SaveChangesAsync(); var stream = StreamAction.Append(Store.Events, StreamId); stream.Version = 4; @@ -329,7 +329,7 @@ public StreamAction StartNewStream(IMartenSessionLogger logger = null) else { session.Events.StartStream(StreamId.ToString(), events); - session.SaveChanges(); + await session.SaveChangesAsync(); var stream = StreamAction.Start(Store.Events, StreamId.ToString(), new AEvent()); stream.Version = 4; diff --git a/src/EventSourcingTests/archiving_events.cs b/src/EventSourcingTests/archiving_events.cs index 6854d373c1..177d44cb1a 100644 --- a/src/EventSourcingTests/archiving_events.cs +++ b/src/EventSourcingTests/archiving_events.cs @@ -329,10 +329,11 @@ public async Task prevent_append_operation_for_archived_stream_on_sync_commit(bo await theSession.SaveChangesAsync(); theSession.Events.Append(streamId, new BEvent()); - var thrownException = Should.Throw( () => + var thrownException = await Should.ThrowAsync( async () => { - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); }); + thrownException.Message.ShouldBe($"Attempted to append event to archived stream with Id '{streamId}'."); } diff --git a/src/EventSourcingTests/asserting_on_expected_event_version_on_append.cs b/src/EventSourcingTests/asserting_on_expected_event_version_on_append.cs index 2243488d74..ae75e9b133 100644 --- a/src/EventSourcingTests/asserting_on_expected_event_version_on_append.cs +++ b/src/EventSourcingTests/asserting_on_expected_event_version_on_append.cs @@ -15,7 +15,7 @@ public class asserting_on_expected_event_version_on_append: IntegrationContext private readonly ITestOutputHelper _output; [Fact] - public void should_check_max_event_id_on_append() + public async Task should_check_max_event_id_on_append() { var joined = new MembersJoined { Members = new string[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; @@ -23,7 +23,7 @@ public void should_check_max_event_id_on_append() var stream = theSession.Events.StartStream(joined).Id; theSession.Events.Append(stream, 2, departed); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var state = theSession.Events.FetchStreamState(stream); @@ -32,13 +32,13 @@ public void should_check_max_event_id_on_append() } [Fact] - public void should_not_append_events_when_unexpected_max_version() + public async Task should_not_append_events_when_unexpected_max_version() { var joined = new MembersJoined { Members = new string[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; var stream = theSession.Events.StartStream(joined).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.Append(stream, 2, departed); @@ -48,14 +48,14 @@ public void should_not_append_events_when_unexpected_max_version() var departed3 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(stream, joined3, departed3); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Assert.Throws(() => theSession.SaveChanges()); + await Should.ThrowAsync(() => theSession.SaveChangesAsync()); using (var session = theStore.LightweightSession()) { - var state = session.Events.FetchStreamState(stream); + var state = await session.Events.FetchStreamStateAsync(stream); state.Id.ShouldBe(stream); state.Version.ShouldBe(3); @@ -63,7 +63,7 @@ public void should_not_append_events_when_unexpected_max_version() } [Fact] - public void should_check_max_event_id_on_append_with_string_identifier() + public async Task should_check_max_event_id_on_append_with_string_identifier() { UseStreamIdentity(StreamIdentity.AsString); @@ -75,7 +75,7 @@ public void should_check_max_event_id_on_append_with_string_identifier() theSession.Events.Append(stream, joined); theSession.Events.Append(stream, 2, departed); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var state = theSession.Events.FetchStreamState(stream); @@ -84,7 +84,7 @@ public void should_check_max_event_id_on_append_with_string_identifier() } [Fact] - public void should_not_append_events_when_unexpected_max_version_with_string_identifier() + public async Task should_not_append_events_when_unexpected_max_version_with_string_identifier() { UseStreamIdentity(StreamIdentity.AsString); @@ -93,7 +93,7 @@ public void should_not_append_events_when_unexpected_max_version_with_string_ide var stream = "Another"; theSession.Events.Append(stream, joined); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.Append(stream, 2, departed); @@ -103,14 +103,14 @@ public void should_not_append_events_when_unexpected_max_version_with_string_ide var departed3 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(stream, joined3, departed3); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Assert.Throws(() => theSession.SaveChanges()); + await Should.ThrowAsync(() => theSession.SaveChangesAsync()); using (var session = theStore.LightweightSession()) { - var state = session.Events.FetchStreamState(stream); + var state = await session.Events.FetchStreamStateAsync(stream); state.Key.ShouldBe(stream); state.Version.ShouldBe(3); diff --git a/src/EventSourcingTests/capturing_event_versions_on_existing_streams_after_append.cs b/src/EventSourcingTests/capturing_event_versions_on_existing_streams_after_append.cs index c9faecad2c..a183fcfd0d 100644 --- a/src/EventSourcingTests/capturing_event_versions_on_existing_streams_after_append.cs +++ b/src/EventSourcingTests/capturing_event_versions_on_existing_streams_after_append.cs @@ -57,7 +57,7 @@ public void OnBeforeExecute(NpgsqlBatch batch) } [Fact] - public void running_synchronously() + public async Task running_synchronously() { var logger = new RecordingSessionLogger(); @@ -71,7 +71,7 @@ public void running_synchronously() var departed = new MembersDeparted { Members = new[] { "Thom" } }; session.Events.StartStream(streamId, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var events = logger.LastCommit.GetEvents().ToArray(); events.Select(x => x.Version) @@ -90,7 +90,7 @@ public void running_synchronously() var departed2 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(streamId, joined2, departed2); - session.SaveChanges(); + await session.SaveChangesAsync(); logger.LastCommit.GetEvents().Select(x => x.Version) .ShouldHaveTheSameElementsAs(3, 4); @@ -104,7 +104,7 @@ public void running_synchronously() var departed3 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(streamId, joined3, departed3); - session.SaveChanges(); + await session.SaveChangesAsync(); logger.LastCommit.GetEvents().Select(x => x.Version) .ShouldHaveTheSameElementsAs(5, 6); diff --git a/src/EventSourcingTests/delete_single_event_stream.cs b/src/EventSourcingTests/delete_single_event_stream.cs index fe6783a147..15aad29169 100644 --- a/src/EventSourcingTests/delete_single_event_stream.cs +++ b/src/EventSourcingTests/delete_single_event_stream.cs @@ -12,7 +12,7 @@ namespace EventSourcingTests; public class delete_single_event_stream: OneOffConfigurationsContext { [Fact] - public void delete_stream_by_guid_id() + public async Task delete_stream_by_guid_id() { var stream1 = Guid.NewGuid(); @@ -30,7 +30,7 @@ public void delete_stream_by_guid_id() session.Events.Append(stream2, joined2, departed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } theStore.Advanced.Clean.DeleteSingleEventStream(stream1); @@ -43,7 +43,7 @@ public void delete_stream_by_guid_id() } [Fact] - public void delete_stream_by_guid_id_conjoined_tenancy() + public async Task delete_stream_by_guid_id_conjoined_tenancy() { StoreOptions(opts => opts.Events.TenancyStyle = TenancyStyle.Conjoined); @@ -62,7 +62,7 @@ public void delete_stream_by_guid_id_conjoined_tenancy() session.Events.Append(stream2, joined2, departed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } theStore.Advanced.Clean.DeleteSingleEventStream(stream1, "one"); @@ -138,7 +138,7 @@ public async Task delete_stream_by_guid_id_async_with_multi_tenancy() } [Fact] - public void delete_stream_by_string_key() + public async Task delete_stream_by_string_key() { StoreOptions(_ => { @@ -160,7 +160,7 @@ public void delete_stream_by_string_key() session.Events.Append(stream2, joined2, departed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } theStore.Advanced.Clean.DeleteSingleEventStream(stream1); @@ -173,7 +173,7 @@ public void delete_stream_by_string_key() } [Fact] - public void delete_stream_by_string_key_multi_tenanted() + public async Task delete_stream_by_string_key_multi_tenanted() { StoreOptions(_ => { @@ -196,7 +196,7 @@ public void delete_stream_by_string_key_multi_tenanted() session.Events.Append(stream2, joined2, departed2); - session.SaveChanges(); + await session.SaveChangesAsync(); } theStore.Advanced.Clean.DeleteSingleEventStream(stream1, "one"); diff --git a/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_Tests.cs b/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_Tests.cs index 3fad185f83..68e8703b57 100644 --- a/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_Tests.cs +++ b/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_Tests.cs @@ -39,11 +39,11 @@ public end_to_end_event_capture_and_fetching_the_stream_Tests(ITestOutputHelper [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, string[] tenants) + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, _) => + await When.CalledForEachAsync(tenants, async (tenantId, _) => { using var session = store.LightweightSession(tenantId); session.Logger = new TestOutputMartenLogger(_output); @@ -54,11 +54,11 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyl var departed = new MembersDeparted { Members = new[] { "Thom" } }; var id = session.Events.StartStream(joined, departed).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); #endregion - var streamEvents = session.Events.FetchStream(id); + var streamEvents = await session.Events.FetchStreamAsync(id); streamEvents.Count().ShouldBe(2); streamEvents.ElementAt(0).Data.ShouldBeOfType(); @@ -67,7 +67,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back(TenancyStyl streamEvents.ElementAt(1).Version.ShouldBe(2); streamEvents.Each(e => e.Timestamp.ShouldNotBe(default(DateTimeOffset))); - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] @@ -139,12 +139,12 @@ public Task capture_events_to_a_new_stream_and_fetch_the_events_back_async_with_ [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_linq(TenancyStyle tenancyStyle, + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_linq(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, _) => + await When.CalledForEachAsync(tenants, async (tenantId, _) => { using var session = store.LightweightSession(tenantId); @@ -154,7 +154,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l var departed = new MembersDeparted { Members = new[] { "Thom" } }; var id = session.Events.StartStream(joined, departed).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); #endregion @@ -168,18 +168,18 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l streamEvents.ElementAt(1).Version.ShouldBe(2); streamEvents.Each(e => e.Timestamp.ShouldNotBe(default(DateTimeOffset))); - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(TenancyStyle tenancyStyle, + public async Task live_aggregate_equals_inlined_aggregate_without_hidden_contracts(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var questId = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -192,7 +192,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(Ten var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -202,7 +202,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(Ten liveAggregate.Id.ShouldBe(inlinedAggregate.Id); inlinedAggregate.ToString().ShouldBe(liveAggregate.ToString()); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -210,12 +210,12 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts(Ten [Theory] [MemberData(nameof(SessionParams))] - public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle tenancyStyle, string[] tenants) + public async Task open_persisted_stream_in_new_store_with_same_settings(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var questId = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -224,7 +224,7 @@ public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle t var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } // events-aggregate-on-the-fly - works with same store @@ -286,7 +286,7 @@ public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle t .AggregateStream(questId, timestamp: DateTimeOffset.UtcNow.AddDays(-1)); party_yesterday.ShouldBeNull(); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -294,12 +294,12 @@ public void open_persisted_stream_in_new_store_with_same_settings(TenancyStyle t [Theory] [MemberData(nameof(SessionParams))] - public void query_before_saving(TenancyStyle tenancyStyle, string[] tenants) + public async Task query_before_saving(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var questId = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -314,12 +314,12 @@ public void query_before_saving(TenancyStyle tenancyStyle, string[] tenants) var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); var party = session.Events.AggregateStream(questId); party.Id.ShouldBe(questId); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -365,7 +365,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -376,7 +376,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream var id = Guid.NewGuid(); session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); #endregion @@ -388,7 +388,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] @@ -398,7 +398,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back(Te { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -409,7 +409,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back(Te session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -419,26 +419,26 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back(Te streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var started = new QuestStarted(); using (var session = store.LightweightSession(tenantId)) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -449,7 +449,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back(Tenan session.Events.Append(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -461,7 +461,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back(Tenan streamEvents.ElementAt(2).Data.ShouldBeOfType(); streamEvents.ElementAt(2).Version.ShouldBe(3); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -469,12 +469,12 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back(Tenan [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema( + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -482,7 +482,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ var departed = new MembersDeparted { Members = new[] { "Thom" } }; var id = session.Events.StartStream(joined, departed).Id; - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -492,18 +492,18 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -512,7 +512,7 @@ public void var id = Guid.NewGuid(); session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -524,17 +524,17 @@ public void streamEvents.Each(x => SpecificationExtensions.ShouldBeGreaterThan(x.Sequence, 0L)); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema( + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { using (var session = store.LightweightSession(tenantId)) { @@ -545,7 +545,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -555,26 +555,26 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in streamEvents.ElementAt(1).Data.ShouldBeOfType(); streamEvents.ElementAt(1).Version.ShouldBe(2); } - }).ShouldSucceed(); + }).ShouldSucceedAsync(); } [Theory] [MemberData(nameof(SessionParams))] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema( + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema( TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var started = new QuestStarted(); using (var session = store.LightweightSession(tenantId)) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -586,7 +586,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an session.Events.Append(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); #endregion @@ -600,7 +600,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an streamEvents.ElementAt(2).Data.ShouldBeOfType(); streamEvents.ElementAt(2).Version.ShouldBe(3); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -608,14 +608,14 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an [Theory] [MemberData(nameof(SessionParams))] - public void assert_on_max_event_id_on_event_stream_append( + public async Task assert_on_max_event_id_on_event_stream_append( TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var started = new QuestStarted(); @@ -624,7 +624,7 @@ public void assert_on_max_event_id_on_event_stream_append( #region sample_append-events-assert-on-eventid session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; @@ -633,11 +633,11 @@ public void assert_on_max_event_id_on_event_stream_append( // would be 3 after the append operation. session.Events.Append(id, 3, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); #endregion } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); @@ -645,20 +645,20 @@ public void assert_on_max_event_id_on_event_stream_append( [Theory] [MemberData(nameof(SessionParams))] - public void capture_immutable_events(TenancyStyle tenancyStyle, string[] tenants) + public async Task capture_immutable_events(TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var id = Guid.NewGuid(); - When.CalledForEach(tenants, (tenantId, index) => + await When.CalledForEachAsync(tenants, async (tenantId, index) => { var immutableEvent = new ImmutableEvent(id, "some-name"); using (var session = store.LightweightSession(tenantId)) { session.Events.Append(id, immutableEvent); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession(tenantId)) @@ -671,7 +671,7 @@ public void capture_immutable_events(TenancyStyle tenancyStyle, string[] tenants @event.Id.ShouldBe(id); @event.Name.ShouldBe("some-name"); } - }).ShouldThrowIf( + }).ShouldThrowIfAsync( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); diff --git a/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_with_string_identifiers.cs b/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_with_string_identifiers.cs index b736823db5..e492fe62ce 100644 --- a/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_with_string_identifiers.cs +++ b/src/EventSourcingTests/end_to_end_event_capture_and_fetching_the_stream_with_string_identifiers.cs @@ -23,7 +23,7 @@ public end_to_end_event_capture_and_fetching_the_stream_with_string_identifiers( } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back() { var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; @@ -31,7 +31,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back() var id = "First"; theSession.Events.StartStream(id, joined, departed); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var streamEvents = theSession.Events.FetchStream(id); @@ -96,7 +96,7 @@ public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_async } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_linq() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_linq() { #region sample_start-stream-with-aggregate-type @@ -105,7 +105,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l var id = "Fourth"; theSession.Events.StartStream(id, joined, departed); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #endregion @@ -122,7 +122,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_sync_with_l } [Fact] - public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts() + public async Task live_aggregate_equals_inlined_aggregate_without_hidden_contracts() { var questId = "Fifth"; @@ -137,7 +137,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts() var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -150,7 +150,7 @@ public void live_aggregate_equals_inlined_aggregate_without_hidden_contracts() } [Fact] - public void open_persisted_stream_in_new_store_with_same_settings() + public async Task open_persisted_stream_in_new_store_with_same_settings() { var questId = "Sixth"; @@ -161,7 +161,7 @@ public void open_persisted_stream_in_new_store_with_same_settings() var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream(questId, started, joined1); - session.SaveChanges(); + await session.SaveChangesAsync(); } // events-aggregate-on-the-fly - works with same store @@ -281,7 +281,7 @@ public async Task aggregate_stream_async_has_the_id() } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream_id_provided() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -289,7 +289,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream var id = "Tenth"; session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -301,7 +301,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_with_stream } [Fact] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back() + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -311,7 +311,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back() session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -323,7 +323,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back() } [Fact] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back() + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back() { var id = "Twelth"; var started = new QuestStarted(); @@ -331,7 +331,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back() using (var session = theStore.LightweightSession()) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -342,7 +342,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back() session.Events.Append(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -357,7 +357,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back() } [Fact] - public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema() + public async Task capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_database_schema() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -365,7 +365,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ var id = "Thirteen"; session.Events.StartStream(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -378,7 +378,7 @@ public void capture_events_to_a_new_stream_and_fetch_the_events_back_in_another_ [Fact] - public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema() + public async Task capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in_another_database_schema() { using var session = theStore.LightweightSession(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; @@ -388,7 +388,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in session.Events.StartStream(id, joined); session.Events.Append(id, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -400,7 +400,7 @@ public void capture_events_to_a_non_existing_stream_and_fetch_the_events_back_in } [Fact] - public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema() + public async Task capture_events_to_an_existing_stream_and_fetch_the_events_back_in_another_database_schema() { var id = "Fifteen"; var started = new QuestStarted(); @@ -408,7 +408,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an using (var session = theStore.LightweightSession()) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -418,7 +418,7 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an session.Events.Append(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var streamEvents = session.Events.FetchStream(id); @@ -433,14 +433,14 @@ public void capture_events_to_an_existing_stream_and_fetch_the_events_back_in_an } [Fact] - public void assert_on_max_event_id_on_event_stream_append() + public async Task assert_on_max_event_id_on_event_stream_append() { var id = "Sixteen"; var started = new QuestStarted(); using var session = theStore.LightweightSession(); session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; @@ -449,7 +449,7 @@ public void assert_on_max_event_id_on_event_stream_append() // would be 3 after the append operation. session.Events.Append(id, 3, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/EventSourcingTests/event_store_with_string_identifiers_for_stream.cs b/src/EventSourcingTests/event_store_with_string_identifiers_for_stream.cs index c6cd1c6bd9..bcab50e5db 100644 --- a/src/EventSourcingTests/event_store_with_string_identifiers_for_stream.cs +++ b/src/EventSourcingTests/event_store_with_string_identifiers_for_stream.cs @@ -44,22 +44,22 @@ public void smoke_test_being_able_to_create_database_objects() } [Fact] - public void try_to_insert_event_with_string_identifiers() + public async Task try_to_insert_event_with_string_identifiers() { using (var session = theStore.LightweightSession()) { session.Events.Append("First", new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } [Fact] - public void try_to_insert_event_with_string_identifiers_non_typed() + public async Task try_to_insert_event_with_string_identifiers_non_typed() { using (var session = theStore.LightweightSession()) { session.Events.StartStream("First", new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -69,12 +69,12 @@ public void try_to_insert_event_with_string_identifiers_non_typed() } [Fact] - public void fetch_state() + public async Task fetch_state() { using (var session = theStore.LightweightSession()) { session.Events.Append("First", new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) diff --git a/src/EventSourcingTests/fetch_a_single_event_with_metadata.cs b/src/EventSourcingTests/fetch_a_single_event_with_metadata.cs index df6aafc348..191766fa9d 100644 --- a/src/EventSourcingTests/fetch_a_single_event_with_metadata.cs +++ b/src/EventSourcingTests/fetch_a_single_event_with_metadata.cs @@ -24,7 +24,7 @@ public class fetch_a_single_event_with_metadata: IntegrationContext new MembersJoined { Day = 5, Location = "Sendaria", Members = new string[] { "Silk", "Barak" } }; [Fact] - public void fetch_with_metadata_synchronously() + public async Task fetch_with_metadata_synchronously() { StoreOptions(x => { @@ -40,7 +40,7 @@ public void fetch_with_metadata_synchronously() var streamId = theSession.Events .StartStream(started, joined, slayed1, slayed2, joined2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var events = theSession.Events.FetchStream(streamId); events.Count.ShouldBe(5); @@ -78,11 +78,11 @@ public async Task fetch_with_metadata_asynchronously() } [Fact] - public void fetch_synchronously() + public async Task fetch_synchronously() { var streamId = theSession.Events .StartStream(started, joined, slayed1, slayed2, joined2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var events = theSession.Events.FetchStream(streamId); diff --git a/src/EventSourcingTests/fetching_stream_state.cs b/src/EventSourcingTests/fetching_stream_state.cs index 099aee1a84..d40167f4c7 100644 --- a/src/EventSourcingTests/fetching_stream_state.cs +++ b/src/EventSourcingTests/fetching_stream_state.cs @@ -37,7 +37,7 @@ public async Task bug_705_order_of_operation() } [Fact] - public void other_try() + public async Task other_try() { var store = DocumentStore.For(_ => { @@ -49,7 +49,7 @@ public void other_try() { var aid = Guid.Parse("1442cbbb-a49a-497e-9ee8-715ed2833bf8"); session.Events.StartStream(aid, new FooEvent()); - session.SaveChanges(); + await session.SaveChangesAsync(); } var store2 = DocumentStore.For(_ => diff --git a/src/EventSourcingTests/get_committed_events_from_listener_Tests.cs b/src/EventSourcingTests/get_committed_events_from_listener_Tests.cs index cd522362d6..afb966ff63 100644 --- a/src/EventSourcingTests/get_committed_events_from_listener_Tests.cs +++ b/src/EventSourcingTests/get_committed_events_from_listener_Tests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing; using Marten.Testing.Harness; using Shouldly; @@ -23,7 +24,7 @@ public get_committed_events_from_listener_Tests() } [Fact] - public void get_correct_events_from_single_stream() + public async Task get_correct_events_from_single_stream() { var id = Guid.NewGuid(); var started = new QuestStarted(); @@ -31,7 +32,7 @@ public void get_correct_events_from_single_stream() using (var session = theStore.LightweightSession()) { session.Events.StartStream(id, started); - session.SaveChanges(); + await session.SaveChangesAsync(); var events = listener.LastCommit .GetEvents() @@ -48,7 +49,7 @@ public void get_correct_events_from_single_stream() session.Events.Append(id, joined, departed); - session.SaveChanges(); + await session.SaveChangesAsync(); var events = listener.LastCommit .GetEvents() @@ -61,7 +62,7 @@ public void get_correct_events_from_single_stream() } [Fact] - public void get_correct_events_across_multiple_stream() + public async Task get_correct_events_across_multiple_stream() { var id1 = Guid.NewGuid(); @@ -71,7 +72,7 @@ public void get_correct_events_across_multiple_stream() { session.Events.StartStream(id1, new QuestStarted { Id = id1 }); session.Events.StartStream(id2, new QuestStarted { Id = id2 }); - session.SaveChanges(); + await session.SaveChangesAsync(); var events = listener.LastCommit .GetEvents() @@ -94,7 +95,7 @@ public void get_correct_events_across_multiple_stream() new MembersJoined { Members = new string[] { "Riker" } }, new MembersDeparted { Members = new[] { "Kirk" } }); - session.SaveChanges(); + await session.SaveChangesAsync(); var events = listener.LastCommit .GetEvents() diff --git a/src/EventSourcingTests/multi_tenancy_and_event_capture.cs b/src/EventSourcingTests/multi_tenancy_and_event_capture.cs index dd1b9f07fd..105fab826e 100644 --- a/src/EventSourcingTests/multi_tenancy_and_event_capture.cs +++ b/src/EventSourcingTests/multi_tenancy_and_event_capture.cs @@ -82,7 +82,7 @@ public async Task capture_events_for_multiple_tenants_in_one_session_as_guid_ide [Theory] [MemberData(nameof(TenancyStyles))] - public void capture_events_for_a_tenant(TenancyStyle tenancyStyle) + public async Task capture_events_for_a_tenant(TenancyStyle tenancyStyle) { InitStore(tenancyStyle); @@ -90,7 +90,7 @@ public void capture_events_for_a_tenant(TenancyStyle tenancyStyle) using (var session = theStore.LightweightSession("Green")) { session.Events.Append(stream, new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Green")) @@ -128,7 +128,7 @@ public async Task capture_events_for_a_tenant_async(TenancyStyle tenancyStyle) [Theory] [MemberData(nameof(TenancyStyles))] - public void capture_events_for_a_tenant_with_string_identifier(TenancyStyle tenancyStyle) + public async Task capture_events_for_a_tenant_with_string_identifier(TenancyStyle tenancyStyle) { InitStore(tenancyStyle, StreamIdentity.AsString); @@ -136,7 +136,7 @@ public void capture_events_for_a_tenant_with_string_identifier(TenancyStyle tena using (var session = theStore.LightweightSession("Green")) { session.Events.Append(stream, new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Green")) @@ -174,7 +174,7 @@ public async Task capture_events_for_a_tenant_async_as_string_identifier(Tenancy [Theory] [MemberData(nameof(TenancyStyles))] - public void append_to_events_a_second_time_with_same_tenant_id(TenancyStyle tenancyStyle) + public async Task append_to_events_a_second_time_with_same_tenant_id(TenancyStyle tenancyStyle) { InitStore(tenancyStyle); @@ -183,14 +183,14 @@ public void append_to_events_a_second_time_with_same_tenant_id(TenancyStyle tena { session.Logger = new TestOutputMartenLogger(_output); session.Events.Append(stream, new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Green")) { session.Logger = new TestOutputMartenLogger(_output); session.Events.Append(stream, new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Green")) @@ -205,7 +205,7 @@ public void append_to_events_a_second_time_with_same_tenant_id(TenancyStyle tena [Fact] - public void try_to_append_across_tenants_with_tenancy_style_conjoined() + public async Task try_to_append_across_tenants_with_tenancy_style_conjoined() { InitStore(TenancyStyle.Conjoined); @@ -213,21 +213,21 @@ public void try_to_append_across_tenants_with_tenancy_style_conjoined() using (var session = theStore.LightweightSession("Green")) { session.Events.Append(stream, new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } - Should.NotThrow(() => + await Should.NotThrowAsync(async () => { using (var session = theStore.LightweightSession("Red")) { session.Events.Append(stream, new MembersJoined(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } }); } [Fact] - public void tenanted_session_should_not_see_other_tenants_events() + public async Task tenanted_session_should_not_see_other_tenants_events() { InitStore(TenancyStyle.Conjoined); @@ -236,13 +236,13 @@ public void tenanted_session_should_not_see_other_tenants_events() using (var session = theStore.LightweightSession("Green")) { session.Events.Append(Guid.NewGuid(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Red")) { session.Events.Append(Guid.NewGuid(), new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession("Green")) @@ -345,7 +345,7 @@ public multi_tenancy_and_event_capture(ITestOutputHelper output) [Theory] [MemberData(nameof(WillParameterizeTenantId))] - public void will_parameterize_tenant_id_when_checking_stream_version(StreamIdentity streamIdentity, Func LightweightSession, Action startStream, Action append) + public async Task will_parameterize_tenant_id_when_checking_stream_version(StreamIdentity streamIdentity, Func LightweightSession, Action startStream, Action append) { InitStore(TenancyStyle.Conjoined, streamIdentity); theStore.Advanced.Clean.DeleteAllEventData(); @@ -354,25 +354,25 @@ public void will_parameterize_tenant_id_when_checking_stream_version(StreamIdent using (var session = LightweightSession(theStore)) { startStream(session); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = LightweightSession(theStore)) { append(session); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Red")) { startStream(session); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Red")) { append(session); - session.SaveChanges(); + await session.SaveChangesAsync(); } } } diff --git a/src/EventSourcingTests/no_prior_registration_of_the_event_types.cs b/src/EventSourcingTests/no_prior_registration_of_the_event_types.cs index 493ac1e380..8e1d30da90 100644 --- a/src/EventSourcingTests/no_prior_registration_of_the_event_types.cs +++ b/src/EventSourcingTests/no_prior_registration_of_the_event_types.cs @@ -11,13 +11,13 @@ namespace EventSourcingTests; public class no_prior_registration_of_the_event_types: OneOffConfigurationsContext { [Fact] - public void can_fetch_sync_with_guids() + public async Task can_fetch_sync_with_guids() { var stream = Guid.NewGuid(); using (var session = theStore.LightweightSession()) { session.Events.StartStream(stream, new MembersJoined(), new MembersDeparted()); - session.SaveChanges(); + await session.SaveChangesAsync(); } // Needs to be an isolated, separate document store to the same db @@ -33,7 +33,7 @@ public void can_fetch_sync_with_guids() } [Fact] - public void can_fetch_sync_with_strings() + public async Task can_fetch_sync_with_strings() { StoreOptions(opts => opts.Events.StreamIdentity = StreamIdentity.AsString); @@ -41,7 +41,7 @@ public void can_fetch_sync_with_strings() using (var session = theStore.LightweightSession()) { session.Events.StartStream(stream, new MembersJoined(), new MembersDeparted()); - session.SaveChanges(); + await session.SaveChangesAsync(); } // Needs to be an isolated, separate document store to the same db diff --git a/src/EventSourcingTests/querying_event_data_with_linq.cs b/src/EventSourcingTests/querying_event_data_with_linq.cs index c1e935a646..0304f5501a 100644 --- a/src/EventSourcingTests/querying_event_data_with_linq.cs +++ b/src/EventSourcingTests/querying_event_data_with_linq.cs @@ -24,12 +24,12 @@ public class querying_event_data_with_linq: OneOffConfigurationsContext #region sample_query-against-event-data [Fact] - public void can_query_against_event_type() + public async Task can_query_against_event_type() { theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryRawEventDataOnly().Count().ShouldBe(2); theSession.Events.QueryRawEventDataOnly().ToArray().SelectMany(x => x.Members).Distinct() @@ -43,14 +43,14 @@ public void can_query_against_event_type() #endregion [Fact] - public void can_query_against_event_type_with_camel_casing() + public async Task can_query_against_event_type_with_camel_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryRawEventDataOnly().Count().ShouldBe(2); theSession.Events.QueryRawEventDataOnly().ToArray().SelectMany(x => x.Members).Distinct() @@ -78,14 +78,14 @@ public async Task can_query_against_event_metadata() } [Fact] - public void can_query_against_event_type_with_snake_casing() + public async Task can_query_against_event_type_with_snake_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryRawEventDataOnly().Count().ShouldBe(2); theSession.Events.QueryRawEventDataOnly().ToArray().SelectMany(x => x.Members).Distinct() @@ -104,7 +104,7 @@ public void will_not_blow_up_if_searching_for_events_before_event_store_is_warme [Fact] - public void can_query_against_event_type_with_different_schema_name_with_camel_casing() + public async Task can_query_against_event_type_with_different_schema_name_with_camel_casing() { StoreOptions(_ => { @@ -124,7 +124,7 @@ public void can_query_against_event_type_with_different_schema_name_with_camel_c theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryRawEventDataOnly().Count().ShouldBe(2); theSession.Events.QueryRawEventDataOnly().ToArray().SelectMany(x => x.Members).Distinct() @@ -136,12 +136,12 @@ public void can_query_against_event_type_with_different_schema_name_with_camel_c } [Fact] - public void can_fetch_all_events() + public async Task can_fetch_all_events() { theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Events.QueryAllRawEvents().ToList(); @@ -160,14 +160,14 @@ public void example_of_querying_for_event_data(IDocumentSession session, Guid st #endregion [Fact] - public void can_fetch_all_events_after_now() + public async Task can_fetch_all_events_after_now() { var now = DateTimeOffset.UtcNow; theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var past = now.AddSeconds(-1); @@ -177,12 +177,12 @@ public void can_fetch_all_events_after_now() } [Fact] - public void can_fetch_all_events_before_now() + public async Task can_fetch_all_events_before_now() { theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var dbNow = (DateTime)theSession.Connection.CreateCommand().Sql("select now();").ExecuteScalar(); var now = new DateTimeOffset(dbNow).AddSeconds(5); @@ -196,36 +196,36 @@ public void can_fetch_all_events_before_now() } [Fact] - public void can_fetch_events_by_sequence() + public async Task can_fetch_events_by_sequence() { theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryAllRawEvents() .Count(x => x.Sequence <= 2).ShouldBe(2); } [Fact] - public void can_fetch_by_version() + public async Task can_fetch_by_version() { theSession.Events.StartStream(joined1, departed1); theSession.Events.StartStream(joined2, departed2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryAllRawEvents() .Count(x => x.Version == 1).ShouldBe(2); } [Fact] - public void can_search_by_stream() + public async Task can_search_by_stream() { var stream1 = theSession.Events.StartStream(joined1, departed1).Id; var stream2 = theSession.Events.StartStream(joined2, departed2).Id; - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Events.QueryAllRawEvents() .Count(x => x.StreamId == stream1).ShouldBe(2); diff --git a/src/EventSourcingTests/start_stream_should_enforce_that_it_is_a_new_stream.cs b/src/EventSourcingTests/start_stream_should_enforce_that_it_is_a_new_stream.cs index 0ebbf5a422..9351719a26 100644 --- a/src/EventSourcingTests/start_stream_should_enforce_that_it_is_a_new_stream.cs +++ b/src/EventSourcingTests/start_stream_should_enforce_that_it_is_a_new_stream.cs @@ -1,6 +1,8 @@ using System; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace EventSourcingTests; @@ -8,28 +10,29 @@ namespace EventSourcingTests; public class start_stream_should_enforce_that_it_is_a_new_stream: OneOffConfigurationsContext { [Fact] - public void throw_exception_if_start_stream_is_called_on_existing_stream() + public async Task throw_exception_if_start_stream_is_called_on_existing_stream() { var stream = Guid.NewGuid(); using (var session = theStore.LightweightSession()) { session.Events.StartStream(stream, new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { session.Events.StartStream(stream, new MembersJoined()); - Exception.ShouldBeThrownBy(() => + + await Should.ThrowAsync(async () => { - session.SaveChanges(); + await session.SaveChangesAsync(); }); } } [Fact] - public void throw_exception_if_start_stream_is_called_on_existing_stream_with_the_same_tenant() + public async Task throw_exception_if_start_stream_is_called_on_existing_stream_with_the_same_tenant() { var stream = Guid.NewGuid(); const string tenantName = "Tenant"; @@ -37,21 +40,22 @@ public void throw_exception_if_start_stream_is_called_on_existing_stream_with_th using (var session = theStore.LightweightSession(tenantName)) { session.Events.StartStream(stream, new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("Tenant")) { session.Events.StartStream(stream, new MembersJoined()); - Exception.ShouldBeThrownBy(() => + + await Should.ThrowAsync(async () => { - session.SaveChanges(); + await session.SaveChangesAsync(); }); } } [Fact] - public void does_not_throw_exception_if_start_stream_is_called_on_existing_stream_with_the_same_tenant_and_tenancy_style_conjoined() + public async Task does_not_throw_exception_if_start_stream_is_called_on_existing_stream_with_the_same_tenant_and_tenancy_style_conjoined() { StoreOptions(_ => _.Events.TenancyStyle = Marten.Storage.TenancyStyle.Conjoined); @@ -61,21 +65,22 @@ public void does_not_throw_exception_if_start_stream_is_called_on_existing_strea using (var session = theStore.LightweightSession(tenantName)) { session.Events.StartStream(stream, new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession(tenantName)) { session.Events.StartStream(stream, new MembersJoined()); - Exception.ShouldBeThrownBy(() => + + await Should.ThrowAsync(async () => { - session.SaveChanges(); + await session.SaveChangesAsync(); }); } } [Fact] - public void does_not_throw_exception_if_start_stream_is_called_on_existing_stream_with_different_tenant_and_tenancy_style_conjoined() + public async Task does_not_throw_exception_if_start_stream_is_called_on_existing_stream_with_different_tenant_and_tenancy_style_conjoined() { StoreOptions(_ => _.Events.TenancyStyle = Marten.Storage.TenancyStyle.Conjoined); @@ -84,13 +89,13 @@ public void does_not_throw_exception_if_start_stream_is_called_on_existing_strea using (var session = theStore.LightweightSession("Tenant")) { session.Events.StartStream(stream, new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession("OtherTenant")) { session.Events.StartStream(stream, new MembersJoined()); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/EventSourcingTests/using_the_schema_objects_Tests.cs b/src/EventSourcingTests/using_the_schema_objects_Tests.cs index 83f614f569..bde1ed1b6f 100644 --- a/src/EventSourcingTests/using_the_schema_objects_Tests.cs +++ b/src/EventSourcingTests/using_the_schema_objects_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using EventSourcingTests.Projections; using Marten; using Marten.Testing.Harness; @@ -11,7 +12,7 @@ namespace EventSourcingTests; public class using_the_schema_objects_Tests : OneOffConfigurationsContext { [Fact] - public void can_build_schema_with_auto_create_none() + public async Task can_build_schema_with_auto_create_none() { var id = Guid.NewGuid(); @@ -25,7 +26,7 @@ public void can_build_schema_with_auto_create_none() { session.Events.StartStream(id, new QuestStarted { Name = "Destroy the Orb" }, new MonsterSlayed { Name = "Troll" }, new MonsterSlayed { Name = "Dragon" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/LinqTests/Acceptance/chained_where_clauses.cs b/src/LinqTests/Acceptance/chained_where_clauses.cs index 5dab8962e6..854fd4aed6 100644 --- a/src/LinqTests/Acceptance/chained_where_clauses.cs +++ b/src/LinqTests/Acceptance/chained_where_clauses.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -7,7 +8,7 @@ namespace LinqTests.Acceptance; public class chained_where_clauses : IntegrationContext { [Fact] - public void two_where_clauses() + public async Task two_where_clauses() { var target1 = new Target{Number = 1, String = "Foo"}; var target2 = new Target{Number = 2, String = "Foo"}; @@ -19,7 +20,7 @@ public void two_where_clauses() theSession.Store(target3); theSession.Store(target4); theSession.Store(target5); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number == 1).Where(x => x.String == "Foo").ToArray() .Select(x => x.Id) @@ -27,7 +28,7 @@ public void two_where_clauses() } [Fact] - public void three_where_clauses() + public async Task three_where_clauses() { var target1 = new Target { Number = 1, String = "Foo", Long = 5}; var target2 = new Target { Number = 2, String = "Foo" }; @@ -39,7 +40,7 @@ public void three_where_clauses() theSession.Store(target3); theSession.Store(target4); theSession.Store(target5); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number == 1).Where(x => x.String == "Foo").Where(x => x.Long == 5).ToArray() .Select(x => x.Id) diff --git a/src/LinqTests/Acceptance/date_type_usage.cs b/src/LinqTests/Acceptance/date_type_usage.cs index f2a9e1ef4d..0144cf7a4f 100644 --- a/src/LinqTests/Acceptance/date_type_usage.cs +++ b/src/LinqTests/Acceptance/date_type_usage.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ namespace LinqTests.Acceptance; public class date_type_usage : OneOffConfigurationsContext { [Fact] - public void query() + public async Task query() { theSession.Store(new Target{Number = 1, DateOffset = DateTimeOffset.UtcNow.AddMinutes(30)}); theSession.Store(new Target{Number = 2, DateOffset = DateTimeOffset.UtcNow.AddDays(1)}); @@ -16,7 +17,7 @@ public void query() theSession.Store(new Target{Number = 4, DateOffset = DateTimeOffset.UtcNow.AddHours(-2)}); theSession.Store(new Target{Number = 5, DateOffset = DateTimeOffset.UtcNow.AddHours(-3)}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.DateOffset > DateTimeOffset.UtcNow).ToArray() .Select(x => x.Number) @@ -24,7 +25,7 @@ public void query() } [Fact] - public void can_index_against_datetime_offset() + public async Task can_index_against_datetime_offset() { StoreOptions(_ => { @@ -37,7 +38,7 @@ public void can_index_against_datetime_offset() theSession.Store(new Target { Number = 4, DateOffset = DateTimeOffset.UtcNow.AddHours(-2) }); theSession.Store(new Target { Number = 5, DateOffset = DateTimeOffset.UtcNow.AddHours(-3) }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.DateOffset > DateTimeOffset.UtcNow).OrderBy(x => x.DateOffset).ToArray() @@ -46,7 +47,7 @@ public void can_index_against_datetime_offset() } [Fact] - public void can_select_DateTimeOffset_and_will_return_localtime() + public async Task can_select_DateTimeOffset_and_will_return_localtime() { var document = Target.Random(); document.DateOffset = DateTimeOffset.UtcNow; @@ -54,7 +55,7 @@ public void can_select_DateTimeOffset_and_will_return_localtime() using (var session = theStore.LightweightSession()) { session.Insert(document); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/LinqTests/Acceptance/deep_searches.cs b/src/LinqTests/Acceptance/deep_searches.cs index 235ad692ab..f09ff91b48 100644 --- a/src/LinqTests/Acceptance/deep_searches.cs +++ b/src/LinqTests/Acceptance/deep_searches.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Schema; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ namespace LinqTests.Acceptance; public class deep_searches: OneOffConfigurationsContext { [Fact] - public void query_two_deep() + public async Task query_two_deep() { theSession.Store(new Target { Inner = new Target { Number = 1, String = "Jeremy" } }); theSession.Store(new Target { Inner = new Target { Number = 2, String = "Max" } }); @@ -16,7 +17,7 @@ public void query_two_deep() theSession.Store(new Target { Inner = new Target { Number = 2, String = "Lindsey" } }); theSession.Store(new Target { String = "Russell" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Inner.Number == 2).ToArray().OrderBy(x => x.Inner.String) .Select(x => x.Inner.String) @@ -24,21 +25,21 @@ public void query_two_deep() } [Fact] - public void query_three_deep() + public async Task query_three_deep() { theSession.Store(new Target { Number = 1, Inner = new Target { Inner = new Target { Long = 1 } } }); theSession.Store(new Target { Number = 2, Inner = new Target { Inner = new Target { Long = 2 } } }); theSession.Store(new Target { Number = 3, Inner = new Target { Inner = new Target { Long = 1 } } }); theSession.Store(new Target { Number = 4, Inner = new Target { Inner = new Target { Long = 2 } } }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Inner.Inner.Long == 1).ToArray().Select(x => x.Number) .ShouldHaveTheSameElementsAs(1, 3); } [Fact] - public void order_by_2_deep() + public async Task order_by_2_deep() { theSession.Store(new Target { Inner = new Target { Number = 1, String = "Jeremy" } }); theSession.Store(new Target { Inner = new Target { Number = 2, String = "Max" } }); @@ -46,7 +47,7 @@ public void order_by_2_deep() theSession.Store(new Target { Inner = new Target { Number = 2, String = "Lindsey" } }); theSession.Store(new Target { String = "Russell" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Inner.Number == 2).OrderBy(x => x.Inner.String).ToArray() .Select(x => x.Inner.String) @@ -54,7 +55,7 @@ public void order_by_2_deep() } [Fact] - public void query_two_deep_with_containment_operator() + public async Task query_two_deep_with_containment_operator() { StoreOptions(opts => { @@ -68,7 +69,7 @@ public void query_two_deep_with_containment_operator() theSession.Store(new Target { Inner = new Target { Number = 2, String = "Lindsey" } }); theSession.Store(new Target { String = "Russell" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Inner.Number == 2).ToArray().OrderBy(x => x.Inner.String) .Select(x => x.Inner.String) @@ -76,7 +77,7 @@ public void query_two_deep_with_containment_operator() } [Fact] - public void query_three_deep_with_containment_operator() + public async Task query_three_deep_with_containment_operator() { StoreOptions(opts => { @@ -88,14 +89,14 @@ public void query_three_deep_with_containment_operator() theSession.Store(new Target { Number = 3, Inner = new Target { Inner = new Target { Long = 1 } } }); theSession.Store(new Target { Number = 4, Inner = new Target { Inner = new Target { Long = 2 } } }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Inner.Inner.Long == 1).ToArray().Select(x => x.Number) .ShouldHaveTheSameElementsAs(1, 3); } [Fact] - public void order_by_2_deep_with_containment_operator() + public async Task order_by_2_deep_with_containment_operator() { StoreOptions(opts => { @@ -108,7 +109,7 @@ public void order_by_2_deep_with_containment_operator() theSession.Store(new Target { Inner = new Target { Number = 2, String = "Lindsey" } }); theSession.Store(new Target { String = "Russell" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Inner.Number == 2).OrderBy(x => x.Inner.String).ToArray() .Select(x => x.Inner.String) diff --git a/src/LinqTests/Acceptance/diagnostic_methods.cs b/src/LinqTests/Acceptance/diagnostic_methods.cs index a3715b0cba..4c579c1c17 100644 --- a/src/LinqTests/Acceptance/diagnostic_methods.cs +++ b/src/LinqTests/Acceptance/diagnostic_methods.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Linq; using Marten.Testing.Documents; @@ -14,7 +15,7 @@ public class diagnostic_methods: OneOffConfigurationsContext private readonly ITestOutputHelper _output; [Fact] - public void retrieves_query_plan() + public async Task retrieves_query_plan() { var user1 = new SimpleUser { @@ -31,7 +32,7 @@ public void retrieves_query_plan() Address = new SimpleAddress { HouseNumber = "12bis", Street = "rue de la martre" } }; theSession.Store(user1, user2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var plan = theSession.Query().Explain(); SpecificationExtensions.ShouldNotBeNull(plan); @@ -41,7 +42,7 @@ public void retrieves_query_plan() } [Fact] - public void retrieves_query_plan_with_where() + public async Task retrieves_query_plan_with_where() { var user1 = new SimpleUser { @@ -58,7 +59,7 @@ public void retrieves_query_plan_with_where() Address = new SimpleAddress { HouseNumber = "12bis", Street = "rue de la martre" } }; theSession.Store(user1, user2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var plan = theSession.Query().Where(u => u.Number > 5).Explain(); SpecificationExtensions.ShouldNotBeNull(plan); @@ -68,7 +69,7 @@ public void retrieves_query_plan_with_where() } [Fact] - public void retrieves_query_plan_with_where_and_all_options_enabled() + public async Task retrieves_query_plan_with_where_and_all_options_enabled() { var user1 = new SimpleUser { @@ -85,7 +86,7 @@ public void retrieves_query_plan_with_where_and_all_options_enabled() Address = new SimpleAddress { HouseNumber = "12bis", Street = "rue de la martre" } }; theSession.Store(user1, user2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var plan = theSession.Query().Where(u => u.Number > 5) .OrderBy(x => x.Number) diff --git a/src/LinqTests/Acceptance/enum_usage.cs b/src/LinqTests/Acceptance/enum_usage.cs index c147a85579..6cac7f6426 100644 --- a/src/LinqTests/Acceptance/enum_usage.cs +++ b/src/LinqTests/Acceptance/enum_usage.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Services; using Marten.Testing.Documents; @@ -19,7 +20,7 @@ public enum_usage(ITestOutputHelper output) } [Fact] - public void use_enum_values_with_jil_that_are_not_duplicated() + public async Task use_enum_values_with_jil_that_are_not_duplicated() { theSession.Store(new Target{Color = Colors.Blue, Number = 1}); theSession.Store(new Target{Color = Colors.Red, Number = 2}); @@ -29,7 +30,7 @@ public void use_enum_values_with_jil_that_are_not_duplicated() theSession.Store(new Target{Color = Colors.Green, Number = 6}); theSession.Store(new Target{Color = Colors.Blue, Number = 7}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Color == Colors.Blue).ToArray() .Select(x => x.Number) @@ -37,7 +38,7 @@ public void use_enum_values_with_jil_that_are_not_duplicated() } [Fact] - public void use_enum_values_with_newtonsoft_that_are_not_duplicated() + public async Task use_enum_values_with_newtonsoft_that_are_not_duplicated() { StoreOptions(_ => _.Serializer()); @@ -49,7 +50,7 @@ public void use_enum_values_with_newtonsoft_that_are_not_duplicated() theSession.Store(new Target { Color = Colors.Green, Number = 6 }); theSession.Store(new Target { Color = Colors.Blue, Number = 7 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Color == Colors.Blue).ToArray() .Select(x => x.Number) @@ -57,7 +58,7 @@ public void use_enum_values_with_newtonsoft_that_are_not_duplicated() } [Fact] - public void use_enum_values_with_newtonsoft_that_are_not_duplicated_and_stored_as_strings() + public async Task use_enum_values_with_newtonsoft_that_are_not_duplicated_and_stored_as_strings() { StoreOptions(_ => _.Serializer(new JsonNetSerializer {EnumStorage = EnumStorage.AsString})); @@ -69,7 +70,7 @@ public void use_enum_values_with_newtonsoft_that_are_not_duplicated_and_stored_a theSession.Store(new Target { Color = Colors.Green, Number = 6 }); theSession.Store(new Target { Color = Colors.Blue, Number = 7 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Color == Colors.Blue).ToArray() .Select(x => x.Number) @@ -78,7 +79,7 @@ public void use_enum_values_with_newtonsoft_that_are_not_duplicated_and_stored_a [Fact] - public void use_enum_values_with_jil_that_are_duplicated() + public async Task use_enum_values_with_jil_that_are_duplicated() { StoreOptions(_ => { @@ -93,7 +94,7 @@ public void use_enum_values_with_jil_that_are_duplicated() theSession.Store(new Target { Color = Colors.Green, Number = 6 }); theSession.Store(new Target { Color = Colors.Blue, Number = 7 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Color == Colors.Blue).ToArray() .Select(x => x.Number) @@ -101,7 +102,7 @@ public void use_enum_values_with_jil_that_are_duplicated() } [Fact] - public void use_enum_values_with_newtonsoft_that_are_duplicated() + public async Task use_enum_values_with_newtonsoft_that_are_duplicated() { StoreOptions(_ => { @@ -117,7 +118,7 @@ public void use_enum_values_with_newtonsoft_that_are_duplicated() theSession.Store(new Target { Color = Colors.Green, Number = 6 }); theSession.Store(new Target { Color = Colors.Blue, Number = 7 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Color == Colors.Blue).ToArray() .Select(x => x.Number) @@ -125,7 +126,7 @@ public void use_enum_values_with_newtonsoft_that_are_duplicated() } [Fact] - public void use_enum_values_with_newtonsoft_that_are_duplicated_as_string_storage() + public async Task use_enum_values_with_newtonsoft_that_are_duplicated_as_string_storage() { StoreOptions(_ => { @@ -141,7 +142,7 @@ public void use_enum_values_with_newtonsoft_that_are_duplicated_as_string_storag theSession.Store(new Target { Color = Colors.Green, Number = 6 }); theSession.Store(new Target { Color = Colors.Blue, Number = 7 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Color == Colors.Blue).ToArray() .Select(x => x.Number) @@ -205,14 +206,14 @@ public void use_enum_values_with_newtonsoft_that_are_duplicated_with_bulk_import } [Fact] - public void use_nullable_enum_values_as_part_of_in_query() + public async Task use_nullable_enum_values_as_part_of_in_query() { theSession.Store(new Target{NullableEnum = Colors.Green, Number = 1}); theSession.Store(new Target{NullableEnum = Colors.Blue, Number = 2}); theSession.Store(new Target{NullableEnum = Colors.Red, Number = 3}); theSession.Store(new Target{NullableEnum = Colors.Green, Number = 4}); theSession.Store(new Target{NullableEnum = null, Number = 5}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query().Where(x => x.NullableEnum.In(null, Colors.Green)) .ToList(); @@ -221,14 +222,14 @@ public void use_nullable_enum_values_as_part_of_in_query() } [Fact] - public void use_nullable_enum_values_as_part_of_notin_query() + public async Task use_nullable_enum_values_as_part_of_notin_query() { theSession.Store(new Target{NullableEnum = Colors.Green, Number = 1}); theSession.Store(new Target{NullableEnum = Colors.Blue, Number = 2}); theSession.Store(new Target{NullableEnum = Colors.Red, Number = 3}); theSession.Store(new Target{NullableEnum = Colors.Green, Number = 4}); theSession.Store(new Target{NullableEnum = null, Number = 5}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query().Where(x => !x.NullableEnum.In(null, Colors.Green)) .ToList(); diff --git a/src/LinqTests/Acceptance/equals_method_usage_validation.cs b/src/LinqTests/Acceptance/equals_method_usage_validation.cs index d86a144807..5fcb92fc04 100644 --- a/src/LinqTests/Acceptance/equals_method_usage_validation.cs +++ b/src/LinqTests/Acceptance/equals_method_usage_validation.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Linq.Expressions; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Linq; using Marten.Testing.Harness; @@ -25,7 +26,7 @@ public class QueryTarget } [Fact] - public void when_wrong_types_are_compared() + public async Task when_wrong_types_are_compared() { var queryTarget = new QueryTarget { @@ -33,7 +34,7 @@ public void when_wrong_types_are_compared() }; theSession.Store(queryTarget); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); object notInt = "not int"; @@ -46,7 +47,7 @@ public void when_wrong_types_are_compared() } [Fact] - public void when_wrong_types_are_compared_inside_a_negation() + public async Task when_wrong_types_are_compared_inside_a_negation() { var queryTarget = new QueryTarget { @@ -54,7 +55,7 @@ public void when_wrong_types_are_compared_inside_a_negation() }; theSession.Store(queryTarget); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); object notInt = "not int"; @@ -67,7 +68,7 @@ public void when_wrong_types_are_compared_inside_a_negation() } [Fact] - public void can_use_inside_of_compiled_query() + public async Task can_use_inside_of_compiled_query() { var queryTarget = new QueryTarget { @@ -80,7 +81,7 @@ public void can_use_inside_of_compiled_query() theSession.Store(queryTarget); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var itemFromDb = theSession.Query(new CompiledQueryTarget() {IdProp = queryTarget.Id, IntProp = queryTarget.IntProp}); diff --git a/src/LinqTests/Acceptance/matches_sql_queries.cs b/src/LinqTests/Acceptance/matches_sql_queries.cs index d5ac78b693..05b18946fb 100644 --- a/src/LinqTests/Acceptance/matches_sql_queries.cs +++ b/src/LinqTests/Acceptance/matches_sql_queries.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Linq.MatchesSql; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -11,7 +12,7 @@ namespace LinqTests.Acceptance; public class matches_sql_queries: IntegrationContext { [Fact] - public void query_using_matches_sql() + public async Task query_using_matches_sql() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -20,7 +21,7 @@ public void query_using_matches_sql() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); // no where clause session.Query().Where(x => x.MatchesSql("d.data ->> 'UserName' = ? or d.data ->> 'UserName' = ?", "baz", "jack")).OrderBy(x => x.UserName).Select(x => x.UserName) @@ -35,7 +36,7 @@ public void query_using_matches_sql() } [Fact] - public void query_using_where_fragment() + public async Task query_using_where_fragment() { var user1 = new User { UserName = "foo" }; var user2 = new User { UserName = "bar" }; @@ -44,7 +45,7 @@ public void query_using_where_fragment() using var session = theStore.LightweightSession(); session.Store(user1, user2, user3, user4); - session.SaveChanges(); + await session.SaveChangesAsync(); var whereFragment = CompoundWhereFragment.And(); whereFragment.Add(new WhereFragment("d.data ->> 'UserName' != ?", "baz")); diff --git a/src/LinqTests/Acceptance/nested_boolean_logic.cs b/src/LinqTests/Acceptance/nested_boolean_logic.cs index 5ad52d6968..42aa219ba0 100644 --- a/src/LinqTests/Acceptance/nested_boolean_logic.cs +++ b/src/LinqTests/Acceptance/nested_boolean_logic.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -12,13 +13,13 @@ public class nested_boolean_logic : IntegrationContext private readonly ITestOutputHelper _output; [Fact] - public void TestModalOrQuery() + public async Task TestModalOrQuery() { var target1 = new Target { String = "Bert", Date = new DateTime(2016, 03, 10) }; var target2 = new Target { String = null, Date = new DateTime(2016, 03, 10) }; theSession.Store(target1, target2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var startDate = new DateTime(2016, 03, 01); var endDate = new DateTime(2016, 04, 01); diff --git a/src/LinqTests/Acceptance/null_or_not_null_querying.cs b/src/LinqTests/Acceptance/null_or_not_null_querying.cs index 361a79d398..97af37894e 100644 --- a/src/LinqTests/Acceptance/null_or_not_null_querying.cs +++ b/src/LinqTests/Acceptance/null_or_not_null_querying.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Linq; using Marten.Linq.Parsing; @@ -18,7 +19,7 @@ public class UserNested : User } [Fact] - public void CanQueryNullNotNullAtArbitraryDepth() + public async Task CanQueryNullNotNullAtArbitraryDepth() { var user = new UserNested { @@ -33,7 +34,7 @@ public void CanQueryNullNotNullAtArbitraryDepth() theSession.Store(user); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var s = theStore.QuerySession()) { diff --git a/src/LinqTests/Acceptance/nullable_types.cs b/src/LinqTests/Acceptance/nullable_types.cs index 9fa4aa4aaa..bcd8bb5339 100644 --- a/src/LinqTests/Acceptance/nullable_types.cs +++ b/src/LinqTests/Acceptance/nullable_types.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -12,7 +13,7 @@ public class nullable_types : IntegrationContext private readonly ITestOutputHelper _output; [Fact] - public void query_against_non_null() + public async Task query_against_non_null() { theSession.Store(new Target {NullableNumber = 3}); theSession.Store(new Target {NullableNumber = 6}); @@ -20,14 +21,14 @@ public void query_against_non_null() theSession.Store(new Target {NullableNumber = 3}); theSession.Store(new Target {NullableNumber = 5}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.NullableNumber > 4).Count() .ShouldBe(3); } [Fact] - public void query_against_null_1() + public async Task query_against_null_1() { theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = null }); @@ -35,14 +36,14 @@ public void query_against_null_1() theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = null }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.NullableNumber == null).Count() .ShouldBe(3); } [Fact] - public void query_against_null_2() + public async Task query_against_null_2() { theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = null }); @@ -50,7 +51,7 @@ public void query_against_null_2() theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = null }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => !x.NullableNumber.HasValue).Count() .ShouldBe(3); @@ -58,19 +59,19 @@ public void query_against_null_2() } [Fact] - public void query_against_null_3() + public async Task query_against_null_3() { theSession.Store(new Target { NullableBoolean = null }); theSession.Store(new Target { NullableBoolean = true }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => !x.NullableBoolean.HasValue).Count() .ShouldBe(1); } [Fact] - public void query_against_null_4() + public async Task query_against_null_4() { theSession.Store(new Target { NullableDateTime = new DateTime(2526,1,1) }); theSession.Store(new Target { NullableDateTime = null }); @@ -78,26 +79,26 @@ public void query_against_null_4() theSession.Store(new Target { NullableDateTime = DateTime.MinValue }); theSession.Store(new Target { NullableDateTime = null }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => !x.NullableDateTime.HasValue || x.NullableDateTime > new DateTime(2525,1,1)).Count() .ShouldBe(4); } [Fact] - public void query_against_null_6() + public async Task query_against_null_6() { theSession.Store(new Target { NullableBoolean = null }); theSession.Store(new Target { NullableBoolean = true }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(x => x.NullableBoolean.HasValue == false) .ShouldBe(1); } [Fact] - public void query_against_not_null() + public async Task query_against_not_null() { theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = null }); @@ -105,7 +106,7 @@ public void query_against_not_null() theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = null }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(x => x.NullableNumber.HasValue) .ShouldBe(2); diff --git a/src/LinqTests/Acceptance/query_with_inheritance.cs b/src/LinqTests/Acceptance/query_with_inheritance.cs index 6fb6ff41af..06ef1fd495 100644 --- a/src/LinqTests/Acceptance/query_with_inheritance.cs +++ b/src/LinqTests/Acceptance/query_with_inheritance.cs @@ -71,14 +71,14 @@ public sub_class_hierarchies(ITestOutputHelper output) } [Fact] - public void get_all_subclasses_of_a_subclass() + public async Task get_all_subclasses_of_a_subclass() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(3); } @@ -116,7 +116,7 @@ public query_with_inheritance(ITestOutputHelper output) #endregion [Fact] - public void get_all_subclasses_of_an_interface_and_instantiate_them() + public async Task get_all_subclasses_of_an_interface_and_instantiate_them() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; @@ -124,7 +124,7 @@ public void get_all_subclasses_of_an_interface_and_instantiate_them() var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy, papy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var list = theSession.Query().ToList(); list.Count().ShouldBe(3); @@ -150,27 +150,27 @@ public async Task get_all_subclasses_of_an_interface_and_instantiate_them_async( #region sample_query-subclass-hierarchy [Fact] - public void get_all_subclasses_of_a_subclass() + public async Task get_all_subclasses_of_a_subclass() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(3); } [Fact] - public void get_all_subclasses_of_a_subclass2() + public async Task get_all_subclasses_of_a_subclass2() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -178,20 +178,20 @@ public void get_all_subclasses_of_a_subclass2() } [Fact] - public void get_all_subclasses_of_a_subclass_with_where() + public async Task get_all_subclasses_of_a_subclass_with_where() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(s => s.Ability == "Invent").ShouldBe(1); } [Fact] - public void get_all_subclasses_of_a_subclass_with_where_with_camel_casing() + public async Task get_all_subclasses_of_a_subclass_with_where_with_camel_casing() { StoreOptions(_ => { @@ -219,14 +219,14 @@ public void get_all_subclasses_of_a_subclass_with_where_with_camel_casing() var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(s => s.Ability == "Invent").ShouldBe(1); } [Fact] - public void get_all_subclasses_of_an_interface() + public async Task get_all_subclasses_of_an_interface() { var smurf = new Smurf {Ability = "Follow the herd"}; var papa = new PapaSmurf {Ability = "Lead"}; @@ -234,7 +234,7 @@ public void get_all_subclasses_of_an_interface() var brainy = new BrainySmurf {Ability = "Invent"}; theSession.Store(smurf, papa, brainy, papy); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(3); } diff --git a/src/LinqTests/Acceptance/select_clause_usage.cs b/src/LinqTests/Acceptance/select_clause_usage.cs index d2bfdc5144..58dabafb37 100644 --- a/src/LinqTests/Acceptance/select_clause_usage.cs +++ b/src/LinqTests/Acceptance/select_clause_usage.cs @@ -15,14 +15,14 @@ public class select_clause_usage: IntegrationContext { #region sample_one_field_projection [Fact] - public void use_select_in_query_for_one_field() + public async Task use_select_in_query_for_one_field() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => x.FirstName) .ShouldHaveTheSameElementsAs("Bill", "Hank", "Sam", "Tom"); @@ -31,14 +31,14 @@ public void use_select_in_query_for_one_field() #endregion [Fact] - public void use_select_in_query_for_one_field_and_first() + public async Task use_select_in_query_for_one_field_and_first() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => x.FirstName) .First().ShouldBe("Bill"); @@ -78,14 +78,14 @@ public async Task use_select_in_query_for_one_field_async() } [Fact] - public void use_select_to_another_type() + public async Task use_select_to_another_type() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => new UserName { Name = x.FirstName }) .ToArray() @@ -96,14 +96,14 @@ public void use_select_to_another_type() #region sample_get_first_projection [Fact] - public void use_select_to_another_type_with_first() + public async Task use_select_to_another_type_with_first() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => new UserName { Name = x.FirstName }) .FirstOrDefault() @@ -168,14 +168,14 @@ public async Task use_select_to_another_type_as_to_json_array() #region sample_anonymous_type_projection [Fact] - public void use_select_to_transform_to_an_anonymous_type() + public async Task use_select_to_transform_to_an_anonymous_type() { theSession.Store(new User { FirstName = "Hank" }); theSession.Store(new User { FirstName = "Bill" }); theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().OrderBy(x => x.FirstName).Select(x => new { Name = x.FirstName }) .ToArray() @@ -186,14 +186,14 @@ public void use_select_to_transform_to_an_anonymous_type() #endregion [Fact] - public void use_select_with_multiple_fields_in_anonymous() + public async Task use_select_with_multiple_fields_in_anonymous() { theSession.Store(new User { FirstName = "Hank", LastName = "Aaron" }); theSession.Store(new User { FirstName = "Bill", LastName = "Laimbeer" }); theSession.Store(new User { FirstName = "Sam", LastName = "Mitchell" }); theSession.Store(new User { FirstName = "Tom", LastName = "Chambers" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var users = theSession.Query().Select(x => new { First = x.FirstName, Last = x.LastName }).ToList(); @@ -208,14 +208,14 @@ public void use_select_with_multiple_fields_in_anonymous() #region sample_other_type_projection [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void use_select_with_multiple_fields_to_other_type() + public async Task use_select_with_multiple_fields_to_other_type() { theSession.Store(new User { FirstName = "Hank", LastName = "Aaron" }); theSession.Store(new User { FirstName = "Bill", LastName = "Laimbeer" }); theSession.Store(new User { FirstName = "Sam", LastName = "Mitchell" }); theSession.Store(new User { FirstName = "Tom", LastName = "Chambers" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var users = theSession.Query().Select(x => new User2 { First = x.FirstName, Last = x.LastName }).ToList(); @@ -238,14 +238,14 @@ public class User2 [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void use_select_with_multiple_fields_to_other_type_using_constructor() + public async Task use_select_with_multiple_fields_to_other_type_using_constructor() { theSession.Store(new User { FirstName = "Hank", LastName = "Aaron" }); theSession.Store(new User { FirstName = "Bill", LastName = "Laimbeer" }); theSession.Store(new User { FirstName = "Sam", LastName = "Mitchell" }); theSession.Store(new User { FirstName = "Tom", LastName = "Chambers" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var users = theSession.Query() .Select(x => new UserDto(x.FirstName, x.LastName)) @@ -261,14 +261,14 @@ public void use_select_with_multiple_fields_to_other_type_using_constructor() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void use_select_with_multiple_fields_to_other_type_using_constructor_and_properties() + public async Task use_select_with_multiple_fields_to_other_type_using_constructor_and_properties() { theSession.Store(new User { FirstName = "Hank", LastName = "Aaron", Age = 20 }); theSession.Store(new User { FirstName = "Bill", LastName = "Laimbeer", Age = 40 }); theSession.Store(new User { FirstName = "Sam", LastName = "Mitchell", Age = 60 }); theSession.Store(new User { FirstName = "Tom", LastName = "Chambers", Age = 80 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var users = theSession.Query() .Select(x => new UserDto(x.FirstName, x.LastName) { YearsOld = x.Age }) @@ -305,7 +305,7 @@ public async Task use_select_to_transform_to_an_anonymous_type_async() theSession.Store(new User { FirstName = "Sam" }); theSession.Store(new User { FirstName = "Tom" }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var users = await theSession .Query() @@ -337,12 +337,12 @@ public void transform_with_deep_properties() [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void transform_with_deep_properties_to_anonymous_type() + public async Task transform_with_deep_properties_to_anonymous_type() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var actual = theSession.Query() .Where(x => x.Id == target.Id) @@ -355,12 +355,12 @@ public void transform_with_deep_properties_to_anonymous_type() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void transform_with_deep_properties_to_type_using_constructor() + public async Task transform_with_deep_properties_to_type_using_constructor() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var actual = theSession.Query() .Where(x => x.Id == target.Id) @@ -373,12 +373,12 @@ public void transform_with_deep_properties_to_type_using_constructor() } [Fact] - public void use_select_in_query_for_one_object_property() + public async Task use_select_in_query_for_one_object_property() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var actual = theSession.Query() .Where(x => x.Id == target.Id) diff --git a/src/LinqTests/Acceptance/select_many.cs b/src/LinqTests/Acceptance/select_many.cs index 895cff245e..f20ff91799 100644 --- a/src/LinqTests/Acceptance/select_many.cs +++ b/src/LinqTests/Acceptance/select_many.cs @@ -19,7 +19,7 @@ public class select_many : IntegrationContext #region sample_can_do_simple_select_many_against_simple_array [Fact] - public void can_do_simple_select_many_against_simple_array() + public async Task can_do_simple_select_many_against_simple_array() { var product1 = new Product {Tags = new[] {"a", "b", "c"}}; var product2 = new Product {Tags = new[] {"b", "c", "d"}}; @@ -28,7 +28,7 @@ public void can_do_simple_select_many_against_simple_array() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -45,7 +45,7 @@ public void can_do_simple_select_many_against_simple_array() #endregion [Fact] - public void distinct_and_count() + public async Task distinct_and_count() { var product1 = new ProductWithList { Tags = new List { "a", "b", "c" } }; var product2 = new ProductWithList { Tags = new List { "b", "c", "d" } }; @@ -54,7 +54,7 @@ public void distinct_and_count() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -70,7 +70,7 @@ public void distinct_and_count() } [Fact] - public void distinct_and_count_long() + public async Task distinct_and_count_long() { var product1 = new ProductWithList { Tags = new List { "a", "b", "c" } }; var product2 = new ProductWithList { Tags = new List { "b", "c", "d" } }; @@ -79,7 +79,7 @@ public void distinct_and_count_long() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -96,7 +96,7 @@ public void distinct_and_count_long() [Fact] - public void can_do_simple_select_many_against_generic_list() + public async Task can_do_simple_select_many_against_generic_list() { var product1 = new ProductWithList { Tags = new List { "a", "b", "c" } }; var product2 = new ProductWithList { Tags = new List { "b", "c", "d" } }; @@ -105,7 +105,7 @@ public void can_do_simple_select_many_against_generic_list() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -122,7 +122,7 @@ public void can_do_simple_select_many_against_generic_list() } [Fact] - public void select_many_against_complex_type_with_count() + public async Task select_many_against_complex_type_with_count() { var product1 = new Product {Tags = new[] {"a", "b", "c"}}; var product2 = new Product {Tags = new[] {"b", "c", "d"}}; @@ -131,7 +131,7 @@ public void select_many_against_complex_type_with_count() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -142,7 +142,7 @@ public void select_many_against_complex_type_with_count() } [Fact] - public void select_many_with_count_when_none_match_does_not_throw() + public async Task select_many_with_count_when_none_match_does_not_throw() { var product1 = new Product { Tags = new[] { "a", "b", "c" } }; var product2 = new Product { Tags = new[] { "b", "c", "d" } }; @@ -151,7 +151,7 @@ public void select_many_with_count_when_none_match_does_not_throw() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -208,7 +208,7 @@ public async Task select_many_with_count_when_none_match_does_not_throw_async() } [Fact] - public void select_many_against_complex_type_without_transformation() + public async Task select_many_against_complex_type_without_transformation() { var targets = Target.GenerateRandomData(10).ToArray(); var expectedCount = targets.SelectMany(x => x.Children).Count(); @@ -218,7 +218,7 @@ public void select_many_against_complex_type_without_transformation() using (var session = theStore.LightweightSession()) { session.Store(targets); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -229,7 +229,7 @@ public void select_many_against_complex_type_without_transformation() } [Fact] - public void select_many_against_integer_array() + public async Task select_many_against_integer_array() { var product1 = new ProductWithNumbers {Tags = new[] {1, 2, 3}}; var product2 = new ProductWithNumbers {Tags = new[] {2, 3, 4}}; @@ -238,7 +238,7 @@ public void select_many_against_integer_array() using (var session = theStore.LightweightSession()) { session.Store(product1, product2, product3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -279,7 +279,7 @@ public async Task select_many_against_integer_array_async() } [Fact] - public void select_many_with_any() + public async Task select_many_with_any() { var product1 = new Product {Tags = new[] {"a", "b", "c"}}; var product2 = new Product {Tags = new[] {"b", "c", "d"}}; @@ -292,7 +292,7 @@ public void select_many_with_any() // Some Target docs w/ no children session.Store(Target.Random(), Target.Random(), Target.Random()); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -570,7 +570,7 @@ public class TargetGroup } [Fact] - public void select_many_2_deep() + public async Task select_many_2_deep() { var group1 = new TargetGroup { @@ -592,7 +592,7 @@ public void select_many_2_deep() using (var session = theStore.LightweightSession()) { session.Store(groups); - session.SaveChanges(); + await session.SaveChangesAsync(); } using var query = theStore.QuerySession(); diff --git a/src/LinqTests/Acceptance/statistics_and_paged_list.cs b/src/LinqTests/Acceptance/statistics_and_paged_list.cs index 10060681bb..e16461ce2d 100644 --- a/src/LinqTests/Acceptance/statistics_and_paged_list.cs +++ b/src/LinqTests/Acceptance/statistics_and_paged_list.cs @@ -237,16 +237,16 @@ public async Task can_get_the_total_in_results_async() stats.TotalResults.ShouldBe(count); } - private void BuildUpDocumentWithZeroRecords() + private async Task BuildUpDocumentWithZeroRecords() { var doc = new PaginationTestDocument(); doc.Id = "test"; theSession.Store(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Delete(doc); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } [Fact] @@ -491,7 +491,7 @@ public async Task zero_records_document_should_return_pagedlist_gracefully(Func< // Test failure bomb if (DateTime.Today < new DateTime(2023, 9, 5)) return; - BuildUpDocumentWithZeroRecords(); + await BuildUpDocumentWithZeroRecords(); var pageNumber = 1; diff --git a/src/LinqTests/Acceptance/string_filtering.cs b/src/LinqTests/Acceptance/string_filtering.cs index 492d85919a..a0bed28101 100644 --- a/src/LinqTests/Acceptance/string_filtering.cs +++ b/src/LinqTests/Acceptance/string_filtering.cs @@ -209,7 +209,7 @@ public void CanMixStartsWithAndIsNullOrWhiteSpace(string search, StringCompariso } [Fact] - public void can_search_case_insensitive() + public async Task can_search_case_insensitive() { var user1 = new User { UserName = "Abc" }; var user2 = new User { UserName = "DeF" }; @@ -217,7 +217,7 @@ public void can_search_case_insensitive() using (var session = theStore.LightweightSession()) { session.Store(user1, user2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -236,14 +236,14 @@ public void can_search_case_insensitive() } [Fact] - public void can_search_case_insensitive_with_StringComparison() + public async Task can_search_case_insensitive_with_StringComparison() { var user = new User { UserName = "TEST_USER" }; using (var session = theStore.LightweightSession()) { session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -254,14 +254,14 @@ public void can_search_case_insensitive_with_StringComparison() } [Fact] - public void can_search_string_with_back_slash_case_insensitive_with_StringComparison() + public async Task can_search_string_with_back_slash_case_insensitive_with_StringComparison() { var user = new User { UserName = @"DOMAIN\TEST_USER" }; using (var session = theStore.LightweightSession()) { session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs b/src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs index 7c69a3a08b..41a374302a 100644 --- a/src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs +++ b/src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten.Services.Json; using Marten.Testing.Harness; using Shouldly; @@ -26,7 +27,7 @@ public class Car } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_order_by_string_string_dictionaries() + public async Task can_order_by_string_string_dictionaries() { var car1 = new Car {Attributes = {{"one", "5"},{"anumber", "5"},{"color", "red"}}}; var car2 = new Car {Attributes = {{"anumber", "3"}, {"color", "green"}}}; @@ -34,7 +35,7 @@ public void can_order_by_string_string_dictionaries() var car4 = new Car {Attributes = {{"anumber", "4"}, {"color", "purple"}}}; theSession.Store(car1, car2, car3, car4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); @@ -58,4 +59,4 @@ public void smoke_test_can_order_by_not_string_values_in_dictionary() query.Query().OrderBy(x => x.Numbers[2]).ToList(); } -} \ No newline at end of file +} diff --git a/src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs b/src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs index 2b6146d4f1..60076969b9 100644 --- a/src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs +++ b/src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs @@ -36,7 +36,7 @@ public Bug1245User(Guid id, string name) } [PgVersionTargetedFact(MinimumVersion = "10.0")] - public void can_do_include_with_full_text_search() + public async Task can_do_include_with_full_text_search() { var term = "content"; var userDictionary = new Dictionary(); @@ -50,7 +50,7 @@ public void can_do_include_with_full_text_search() session.Store(newEmail); } - session.SaveChanges(); + await session.SaveChangesAsync(); var query = session.Query() .Include(x => x.UserId, userDictionary) diff --git a/src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs b/src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs index fe2c0efd0e..05a91623b3 100644 --- a/src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs +++ b/src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Harness; using Shouldly; @@ -14,7 +15,7 @@ public class DocWithUint } [Fact] - public void can_use_in_where_clauses() + public async Task can_use_in_where_clauses() { var doc1 = new DocWithUint { Number = 1 }; var doc2 = new DocWithUint { Number = 2 }; @@ -25,7 +26,7 @@ public void can_use_in_where_clauses() using (var session = theStore.LightweightSession()) { session.Store(doc1, doc2, doc3, doc4, doc5); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Count(x => x.Number > 3).ShouldBe(2); } @@ -34,4 +35,4 @@ public void can_use_in_where_clauses() public Bug_1256_querying_against_a_uint_type(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs b/src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs index c8e05fc3bb..f7d2ef470d 100644 --- a/src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs +++ b/src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; using Shouldly; @@ -10,7 +11,7 @@ namespace LinqTests.Bugs; public class Bug_1325_Any_with_contains_on_IList_of_string: BugIntegrationContext { [Fact] - public void can_do_any_with_contains_against_IList() + public async Task can_do_any_with_contains_against_IList() { var doc1 = new DocWithLists { Names = new List { "Jeremy", "Josh", "Corey" } }; var doc2 = new DocWithLists { Names = new List { "Jeremy", "Lindsey", "Max" } }; @@ -18,7 +19,7 @@ public void can_do_any_with_contains_against_IList() using var session = theStore.LightweightSession(); session.Store(doc1, doc2, doc3); - session.SaveChanges(); + await session.SaveChangesAsync(); var searchNames = new[] { "Jeremy", "Josh" }; @@ -34,7 +35,7 @@ public void can_do_any_with_contains_against_IList() } [Fact] - public void can_do_any_with_contains_against_IList_with_camel_casing() + public async Task can_do_any_with_contains_against_IList_with_camel_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); @@ -44,7 +45,7 @@ public void can_do_any_with_contains_against_IList_with_camel_casing() using var session = theStore.LightweightSession(); session.Store(doc1, doc2, doc3); - session.SaveChanges(); + await session.SaveChangesAsync(); var searchNames = new[] { "Jeremy", "Josh" }; diff --git a/src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs b/src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs index 5c78d66b1a..f4124894ca 100644 --- a/src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs +++ b/src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs @@ -18,14 +18,14 @@ public Bug_1703_Equality_Not_Symmetric(DefaultStoreFixture fixture, ITestOutputH } [Fact] - public void string_equality_equals_operator_should_be_symmetric() + public async Task string_equality_equals_operator_should_be_symmetric() { var random = Target.Random(); var theString = random.String; using (var session = theStore.LightweightSession()) { session.Insert(random); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs b/src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs index 334bc43bba..8c35022006 100644 --- a/src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs +++ b/src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -9,7 +10,7 @@ namespace LinqTests.Bugs; public class Bug_1875_duplicated_array_field_test : BugIntegrationContext { [Fact] - public void query_on_duplicated_number_array_field_test() + public async Task query_on_duplicated_number_array_field_test() { StoreOptions(_ => { @@ -23,7 +24,7 @@ public void query_on_duplicated_number_array_field_test() NumberArray = new []{ 1, 2 } }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -34,7 +35,7 @@ public void query_on_duplicated_number_array_field_test() } [Fact] - public void query_on_duplicated_guid_array_field_test() + public async Task query_on_duplicated_guid_array_field_test() { StoreOptions(_ => { @@ -46,7 +47,7 @@ public void query_on_duplicated_guid_array_field_test() using (var session = theStore.LightweightSession()) { session.Store(target); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs b/src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs index 5ebf3e0810..f332102137 100644 --- a/src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs +++ b/src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs @@ -60,7 +60,7 @@ public async Task any_filter_honors_tenancy() } [Fact] - public void will_isolate_tenants_when_using_any_and_tenants_use_unique_ids() + public async Task will_isolate_tenants_when_using_any_and_tenants_use_unique_ids() { #region sample_tenancy-scoping-session-write @@ -69,7 +69,7 @@ public void will_isolate_tenants_when_using_any_and_tenants_use_unique_ids() { session.Store(new User { Id = "u1", UserName = "Bill", Roles = new[] { "admin" } }); session.Store(new User { Id = "u2", UserName = "Lindsey", Roles = new string[0] }); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion sample_tenancy-scoping-session-write @@ -79,7 +79,7 @@ public void will_isolate_tenants_when_using_any_and_tenants_use_unique_ids() { session.Store(new User { Id = "u3", UserName = "Frank", Roles = new string[0] }); session.Store(new User { Id = "u4", UserName = "Jill", Roles = new[] { "admin", "user" } }); - session.SaveChanges(); + await session.SaveChangesAsync(); } // When you query for data from the "tenant1" tenant, @@ -107,7 +107,7 @@ public void will_isolate_tenants_when_using_any_and_tenants_use_unique_ids() } [Fact] - public void can_query_with_AnyTenant() + public async Task can_query_with_AnyTenant() { #region sample_tenancy-scoping-session-write @@ -116,7 +116,7 @@ public void can_query_with_AnyTenant() { session.Store(new User { Id = "u1", UserName = "Bill", Roles = new[] { "admin" } }); session.Store(new User { Id = "u2", UserName = "Lindsey", Roles = new string[0] }); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion sample_tenancy-scoping-session-write @@ -126,7 +126,7 @@ public void can_query_with_AnyTenant() { session.Store(new User { Id = "u3", UserName = "Frank", Roles = new string[0] }); session.Store(new User { Id = "u4", UserName = "Jill", Roles = new[] { "admin", "user" } }); - session.SaveChanges(); + await session.SaveChangesAsync(); } // When you query for data from the "tenant1" tenant, diff --git a/src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs b/src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs index 39455b6f2a..73cc6fd1aa 100644 --- a/src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs +++ b/src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Exceptions; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -10,7 +11,7 @@ namespace LinqTests.Bugs; public class Bug_2198_querying_against_UTC_DateTime_with_Npgsql : BugIntegrationContext { [Fact] - public void query() + public async Task query() { theSession.Store(new Target{Number = 1, Date = DateTime.UtcNow.AddMinutes(30)}); theSession.Store(new Target{Number = 2, Date = DateTime.UtcNow.AddDays(1)}); @@ -18,7 +19,7 @@ public void query() theSession.Store(new Target{Number = 4, Date = DateTime.UtcNow.AddHours(-2)}); theSession.Store(new Target{Number = 5, Date = DateTime.UtcNow.AddHours(-3)}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Should.Throw(() => { @@ -31,7 +32,7 @@ public void query() } [Fact] - public void can_index_against_datetime_offset() + public async Task can_index_against_datetime_offset() { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); @@ -46,7 +47,7 @@ public void can_index_against_datetime_offset() theSession.Store(new Target { Number = 4, DateOffset = DateTimeOffset.UtcNow.AddHours(-2) }); theSession.Store(new Target { Number = 5, DateOffset = DateTimeOffset.UtcNow.AddHours(-3) }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query() diff --git a/src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs b/src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs index c1ec535eb0..dce9fcc86f 100644 --- a/src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs +++ b/src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Testing.Harness; namespace LinqTests.Bugs; @@ -37,7 +38,7 @@ public override string Type } [Fact] - public void persist_and_load_subclass_with_abstract_parent() + public async Task persist_and_load_subclass_with_abstract_parent() { var activity = new StatusActivity() { @@ -48,7 +49,7 @@ public void persist_and_load_subclass_with_abstract_parent() using (var session = theStore.IdentitySession()) { session.Store(activity); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Load(activity.Id).ShouldBeTheSameAs(activity); session.Load(activity.Id).ShouldBeTheSameAs(activity); diff --git a/src/LinqTests/Bugs/Bug_3031_querying_using_soft_deletes.cs b/src/LinqTests/Bugs/Bug_3031_querying_using_soft_deletes.cs index fe2c042983..512891a331 100644 --- a/src/LinqTests/Bugs/Bug_3031_querying_using_soft_deletes.cs +++ b/src/LinqTests/Bugs/Bug_3031_querying_using_soft_deletes.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Linq.SoftDeletes; using Marten.Metadata; using Marten.Testing.Harness; @@ -30,14 +31,14 @@ public static IQueryable AddWhereNonGeneric(IQueryable q) // Fails with "System.InvalidOperationException": // "Document type object is not configured as soft deleted" [Fact] - public void test_any_maybe_deleted_in_generic_method() + public async Task test_any_maybe_deleted_in_generic_method() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -50,14 +51,14 @@ public void test_any_maybe_deleted_in_generic_method() // Works fine [Fact] - public void test_any_maybe_deleted_in_non_generic_method() + public async Task test_any_maybe_deleted_in_non_generic_method() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -71,14 +72,14 @@ public void test_any_maybe_deleted_in_non_generic_method() // Fails with "System.InvalidOperationException": // "Document type object is not configured as soft deleted" [Fact] - public void test_any_maybe_deleted_in_generic_extension_method() + public async Task test_any_maybe_deleted_in_generic_extension_method() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -96,14 +97,14 @@ public void test_any_maybe_deleted_in_generic_extension_method() // Fails with "System.InvalidOperationException": // "Document type object is not configured as soft deleted" [Fact] - public void test_list_maybe_deleted_in_generic_extension_method() + public async Task test_list_maybe_deleted_in_generic_extension_method() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -117,14 +118,14 @@ public void test_list_maybe_deleted_in_generic_extension_method() // Working fine [Fact] - public void test_any_maybe_deleted_in_extension_method() + public async Task test_any_maybe_deleted_in_extension_method() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -138,14 +139,14 @@ public void test_any_maybe_deleted_in_extension_method() // Working fine [Fact] - public void test_list_maybe_deleted_in_extension_method() + public async Task test_list_maybe_deleted_in_extension_method() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -159,14 +160,14 @@ public void test_list_maybe_deleted_in_extension_method() // Working fine [Fact] - public void test_any() + public async Task test_any() { var entity = new Entity { Id = Guid.NewGuid() }; using (var sessionX = theStore.LightweightSession()) { sessionX.Store(entity, entity); - sessionX.SaveChanges(); + await sessionX.SaveChangesAsync(); } using var session = theStore.QuerySession(); @@ -180,7 +181,7 @@ public void test_any() // Working fine [Fact] - public void test_list() + public async Task test_list() { var entity = new Entity { Id = Guid.NewGuid() }; var entityDeleted = new Entity { Id = Guid.NewGuid() }; @@ -188,13 +189,13 @@ public void test_list() using (var session = theStore.LightweightSession()) { session.Store(entity, entityDeleted); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { session.Delete(entityDeleted.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); } using var query = theStore.QuerySession(); diff --git a/src/LinqTests/Bugs/Bug_3096_include_where_select.cs b/src/LinqTests/Bugs/Bug_3096_include_where_select.cs index 47615cb98c..26b994db7f 100644 --- a/src/LinqTests/Bugs/Bug_3096_include_where_select.cs +++ b/src/LinqTests/Bugs/Bug_3096_include_where_select.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -19,7 +20,7 @@ public Bug_3096_include_where_select(DefaultStoreFixture fixture, ITestOutputHel } [Fact] - public void include_to_dictionary_with_where_and_projection() + public async Task include_to_dictionary_with_where_and_projection() { var user1 = new User(); var user2 = new User(); @@ -31,7 +32,7 @@ public void include_to_dictionary_with_where_and_projection() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); query.Logger = new TestOutputMartenLogger(_output); diff --git a/src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs b/src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs index 93effcc814..9d58b752d7 100644 --- a/src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs +++ b/src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading.Tasks; using Marten.Linq; using Marten.Testing.Harness; using Shouldly; @@ -62,9 +63,9 @@ public Expression, IEnumerable>> QueryIs() } [Fact] - public void Index_was_outside_the_bounds_of_the_array() + public async Task Index_was_outside_the_bounds_of_the_array() { - AddRoutes(30); + await AddRoutes(30); var from = DateTime.Today.AddDays(5); @@ -77,7 +78,7 @@ public void Index_was_outside_the_bounds_of_the_array() } } - private void AddRoutes(int number) + private async Task AddRoutes(int number) { using var session = theStore.LightweightSession(); for (var index = 0; index < number; index++) @@ -91,6 +92,6 @@ private void AddRoutes(int number) session.Store(route); } - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs b/src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs index ea5729034c..23565210f3 100644 --- a/src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs +++ b/src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using JasperFx.Core; using Marten; using Marten.Testing.Harness; @@ -19,7 +20,7 @@ public Bug_432_querying_with_UTC_times_with_offset(ITestOutputHelper output) } [Fact] - public void can_issue_queries_against_DateTime() + public async Task can_issue_queries_against_DateTime() { using (var session = theStore.LightweightSession()) { @@ -43,7 +44,7 @@ public void can_issue_queries_against_DateTime() DateTimeField = now.Add(-5.Minutes()) }); - session.SaveChanges(); + await session.SaveChangesAsync(); var cmd = session.Query().Where(x => now >= x.DateTimeField) .ToCommand(); @@ -71,7 +72,7 @@ public void can_issue_queries_against_DateTime() } [Fact] - public void can_issue_queries_against_DateTime_with_camel_casing() + public async Task can_issue_queries_against_DateTime_with_camel_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); @@ -97,7 +98,7 @@ public void can_issue_queries_against_DateTime_with_camel_casing() DateTimeField = now.Add(-5.Minutes()) }); - session.SaveChanges(); + await session.SaveChangesAsync(); var cmd = session.Query().Where(x => now >= x.DateTimeField) .ToCommand(); @@ -125,7 +126,7 @@ public void can_issue_queries_against_DateTime_with_camel_casing() } [Fact] - public void can_issue_queries_against_DateTime_with_snake_casing() + public async Task can_issue_queries_against_DateTime_with_snake_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.SnakeCase)); @@ -151,7 +152,7 @@ public void can_issue_queries_against_DateTime_with_snake_casing() DateTimeField = now.Add(-5.Minutes()) }); - session.SaveChanges(); + await session.SaveChangesAsync(); var cmd = session.Query().Where(x => now >= x.DateTimeField) .ToCommand(); @@ -179,7 +180,7 @@ public void can_issue_queries_against_DateTime_with_snake_casing() } [Fact] - public void can_issue_queries_against_DateTime_as_duplicated_column() + public async Task can_issue_queries_against_DateTime_as_duplicated_column() { StoreOptions(_ => _.Schema.For().Duplicate(x => x.DateTimeField)); @@ -205,7 +206,7 @@ public void can_issue_queries_against_DateTime_as_duplicated_column() DateTimeField = now.Add(-5.Minutes()) }); - session.SaveChanges(); + await session.SaveChangesAsync(); var cmd = session.Query().Where(x => now >= x.DateTimeField) .ToCommand(); @@ -223,7 +224,7 @@ public void can_issue_queries_against_DateTime_as_duplicated_column() } [Fact] - public void can_issue_queries_against_the_datetime_offset() + public async Task can_issue_queries_against_the_datetime_offset() { using (var session = theStore.LightweightSession()) { @@ -247,7 +248,7 @@ public void can_issue_queries_against_the_datetime_offset() DateTimeOffsetField = now.Add(-5.Minutes()) }); - session.SaveChanges(); + await session.SaveChangesAsync(); var cmd = session.Query().Where(x => now >= x.DateTimeOffsetField) .ToCommand(); @@ -265,7 +266,7 @@ public void can_issue_queries_against_the_datetime_offset() } [Fact] - public void can_issue_queries_against_the_datetime_offset_as_duplicate_field() + public async Task can_issue_queries_against_the_datetime_offset_as_duplicate_field() { StoreOptions(_ => _.Schema.For().Duplicate(x => x.DateTimeOffsetField)); @@ -291,7 +292,7 @@ public void can_issue_queries_against_the_datetime_offset_as_duplicate_field() DateTimeOffsetField = now.Add(-5.Minutes()) }); - session.SaveChanges(); + await session.SaveChangesAsync(); var cmd = session.Query().Where(x => now >= x.DateTimeOffsetField) .ToCommand(); diff --git a/src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs b/src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs index cbb3aae40a..f378c0b36c 100644 --- a/src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs +++ b/src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Services; using Marten.Testing.Documents; @@ -10,7 +11,7 @@ namespace LinqTests.Bugs; public class Bug_449_IsOneOf_query_with_enum_types: BugIntegrationContext { [Fact] - public void can_query_with_is_one_of_on_an_enum_type_with_jil() + public async Task can_query_with_is_one_of_on_an_enum_type_with_jil() { var blue = new Target { Color = Colors.Blue }; var red = new Target { Color = Colors.Red }; @@ -19,7 +20,7 @@ public void can_query_with_is_one_of_on_an_enum_type_with_jil() using (var session = theStore.LightweightSession()) { session.Store(blue, red, green); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -33,7 +34,7 @@ public void can_query_with_is_one_of_on_an_enum_type_with_jil() } [Fact] - public void can_query_with_is_one_of_on_an_enum_type_with_newtonsoft() + public async Task can_query_with_is_one_of_on_an_enum_type_with_newtonsoft() { StoreOptions(_ => _.Serializer(new JsonNetSerializer())); @@ -44,7 +45,7 @@ public void can_query_with_is_one_of_on_an_enum_type_with_newtonsoft() using (var session = theStore.LightweightSession()) { session.Store(blue, red, green); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs b/src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs index 5df9076718..5e19488eb7 100644 --- a/src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs +++ b/src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using JasperFx.Core; using Marten.Testing.Harness; using Shouldly; @@ -15,7 +16,7 @@ public Bug_479_select_datetime_fields() } [Fact] - public void select_date_time_as_utc() + public async Task select_date_time_as_utc() { var doc = new DocWithDates { @@ -24,7 +25,7 @@ public void select_date_time_as_utc() using var session = theStore.LightweightSession(); session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); var date = session.Query().Where(x => x.Id == doc.Id).Select(x => new { Date = x.DateTime }).Single(); @@ -32,7 +33,7 @@ public void select_date_time_as_utc() } [Fact] - public void select_date_time_offset() + public async Task select_date_time_offset() { var doc = new DocWithDates { @@ -41,7 +42,7 @@ public void select_date_time_offset() using var session = theStore.LightweightSession(); session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); var date = session.Query().Where(x => x.Id == doc.Id).Select(x => new { Date = x.DateTimeOffset }).Single(); diff --git a/src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs b/src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs index 048daedb15..05b292cbf2 100644 --- a/src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs +++ b/src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; using Shouldly; @@ -24,7 +25,7 @@ public class DocWithLists2 } [Fact] - public void can_do_contains_against_IList() + public async Task can_do_contains_against_IList() { var doc1 = new DocWithLists {Names = new List {"Jeremy", "Josh", "Corey"}}; var doc2 = new DocWithLists {Names = new List {"Jeremy", "Lindsey", "Max"}}; @@ -32,7 +33,7 @@ public void can_do_contains_against_IList() using var session = theStore.LightweightSession(); session.Store(doc1, doc2, doc3); - session.SaveChanges(); + await session.SaveChangesAsync(); var ids = session.Query().Where(x => x.Names.Contains("Jeremy")).Select(x => x.Id) .ToList(); @@ -43,7 +44,7 @@ public void can_do_contains_against_IList() } [Fact] - public void can_do_contains_against_IList_with_camel_casing() + public async Task can_do_contains_against_IList_with_camel_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); @@ -53,7 +54,7 @@ public void can_do_contains_against_IList_with_camel_casing() using var session = theStore.LightweightSession(); session.Store(doc1, doc2, doc3); - session.SaveChanges(); + await session.SaveChangesAsync(); var ids = session.Query().Where(x => x.Names.Contains("Jeremy")).Select(x => x.Id) .ToList(); diff --git a/src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs b/src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs index d6c768844f..110e5cced2 100644 --- a/src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs +++ b/src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs @@ -46,7 +46,7 @@ public class StatusActivity: Activity } [Fact] - public void load_abstract_type_with_include() + public async Task load_abstract_type_with_include() { var account = new Account() { @@ -64,7 +64,7 @@ public void load_abstract_type_with_include() }; theSession.Store(activity); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.QuerySession()) { diff --git a/src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs b/src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs index 465b1da7db..c1d9e89d54 100644 --- a/src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs +++ b/src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -11,14 +12,14 @@ public class Bug_503_query_on_null_complex_object: IntegrationContext private readonly ITestOutputHelper _output; [Fact] - public void should_not_blow_up_when_querying_for_null_object() + public async Task should_not_blow_up_when_querying_for_null_object() { using (var sessionOne = theStore.LightweightSession()) { sessionOne.Store(new Target { String = "Something", Inner = new Target(), AnotherString = "first" }); sessionOne.Store(new Target { String = "Something", Inner = null, AnotherString = "second" }); - sessionOne.SaveChanges(); + await sessionOne.SaveChangesAsync(); } using (var querySession = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs b/src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs index d9f01740d2..4a15b020d5 100644 --- a/src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs +++ b/src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs @@ -50,12 +50,15 @@ public void ExpressionWithNotContainsReturnsCorrectResults() } } -public class Bug_561_negation_of_query_on_contains_with_camel_casing: BugIntegrationContext +public class Bug_561_negation_of_query_on_contains_with_camel_casing: BugIntegrationContext, IAsyncLifetime { public Bug_561_negation_of_query_on_contains_with_camel_casing() { - StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); + StoreOptions(opts => opts.UseDefaultSerialization(casing: Casing.CamelCase)); + } + public async Task InitializeAsync() + { var doc1 = new DocWithArrays { Strings = new string[] { "a", "b", "c" } }; var doc2 = new DocWithArrays { Strings = new string[] { "c", "d", "e" } }; var doc3 = new DocWithArrays { Strings = new string[] { "d", "e", "f" } }; @@ -63,7 +66,12 @@ public Bug_561_negation_of_query_on_contains_with_camel_casing() theSession.Store(doc1, doc2, doc3, doc4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; } [Fact] @@ -99,4 +107,4 @@ public class DocWithArrays public string[] Strings { get; set; } public DateTime[] Dates { get; set; } -} \ No newline at end of file +} diff --git a/src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs b/src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs index 31d86e537f..3821b9cf58 100644 --- a/src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs +++ b/src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Xunit.Abstractions; @@ -20,7 +21,7 @@ public Bug_634_include_against_soft_deleted_docs(ITestOutputHelper output) } [Fact] - public void correctly_use_include_when_not_deleted() + public async Task correctly_use_include_when_not_deleted() { var user = new User(); var issue = new Issue @@ -32,7 +33,7 @@ public void correctly_use_include_when_not_deleted() { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -49,7 +50,7 @@ public void correctly_use_include_when_not_deleted() } [Fact] - public void include_finds_nothing_when_it_is_soft_deleted() + public async Task include_finds_nothing_when_it_is_soft_deleted() { // Test failure bomb if (DateTime.Today < new DateTime(2023, 9, 5)) return; @@ -64,13 +65,13 @@ public void include_finds_nothing_when_it_is_soft_deleted() { session.Store(user); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) { session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs b/src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs index 6d3bce4dd0..ee818271eb 100644 --- a/src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs +++ b/src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -38,7 +39,7 @@ public void query_where_with_multiple_or_expressions_against_single_tenant() } [Fact] - public void query_where_with_multiple_or_expresions_against_soft_Deletes() + public async Task query_where_with_multiple_or_expresions_against_soft_Deletes() { StoreOptions(_ => _.Schema.For().SoftDeleted()); @@ -51,7 +52,7 @@ public void query_where_with_multiple_or_expresions_against_soft_Deletes() using (var session = theStore.LightweightSession()) { session.Store(item1, item2, item3); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs b/src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs index b56c334862..22382f2652 100644 --- a/src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs +++ b/src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Marten.Testing.Harness; namespace LinqTests.Bugs; @@ -6,7 +7,7 @@ namespace LinqTests.Bugs; public class Bug_899_operations_out_of_order_when_types_use_inheritance: BugIntegrationContext { [Fact] - public void performs_soft_delete_then_store_operations_in_order() + public async Task performs_soft_delete_then_store_operations_in_order() { // Test failure bomb if (DateTime.Today < new DateTime(2023, 9, 5)) return; @@ -29,7 +30,7 @@ public void performs_soft_delete_then_store_operations_in_order() using (var session = theStore.LightweightSession()) { session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -41,7 +42,7 @@ public void performs_soft_delete_then_store_operations_in_order() doc.Name = "Skimbleshanks"; session.Store(doc); - session.SaveChanges(); + await session.SaveChangesAsync(); } } diff --git a/src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs b/src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs index 948973d67d..be8b05bd59 100644 --- a/src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs +++ b/src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading.Tasks; using Marten; using Marten.Linq; using Marten.Testing.Documents; @@ -40,7 +41,7 @@ public Expression, IEnumerable>> QueryIs() } [Fact] - public void can_get_includes_with_compiled_queries() + public async Task can_get_includes_with_compiled_queries() { var user1 = new User(); var user2 = new User(); @@ -51,7 +52,7 @@ public void can_get_includes_with_compiled_queries() theSession.Store(user1, user2); theSession.Store(issue1, issue2, issue3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); // Issue first query using (var session = theStore.QuerySession()) @@ -84,7 +85,7 @@ public void can_get_includes_with_compiled_queries() } [Fact] - public void can_get_includes_with_multiple_instances_of_same_compiled_query_in_a_session() + public async Task can_get_includes_with_multiple_instances_of_same_compiled_query_in_a_session() { var user1 = new User(); var user2 = new User(); @@ -95,7 +96,7 @@ public void can_get_includes_with_multiple_instances_of_same_compiled_query_in_a theSession.Store(user1, user2); theSession.Store(issue1, issue2, issue3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var session = theStore.QuerySession(); @@ -114,4 +115,4 @@ public void can_get_includes_with_multiple_instances_of_same_compiled_query_in_a issuesWithUsersQry2.Users.Any(x => x.Id == user2.Id).ShouldBeTrue(); issuesWithUsersQry2.Users.Any(x => x.Id == user1.Id).ShouldBeFalse(); } -} \ No newline at end of file +} diff --git a/src/LinqTests/Bugs/query_with_order_by.cs b/src/LinqTests/Bugs/query_with_order_by.cs index 1679a775d9..4903cf950a 100644 --- a/src/LinqTests/Bugs/query_with_order_by.cs +++ b/src/LinqTests/Bugs/query_with_order_by.cs @@ -15,9 +15,9 @@ public query_with_order_by(DefaultStoreFixture fixture): base(fixture) } [Fact] - public void query_with_order_by_for_string_property_with_comparer() + public async Task query_with_order_by_for_string_property_with_comparer() { - CreateTestData(); + await CreateTestData(); RunTest(StringComparer.InvariantCultureIgnoreCase, true); RunTest(StringComparer.OrdinalIgnoreCase, true); @@ -50,9 +50,9 @@ void RunTest(StringComparer comparer, bool shouldBeCaseInsensitive) } [Fact] - public void query_with_order_by_descending_for_string_property_with_comparer() + public async Task query_with_order_by_descending_for_string_property_with_comparer() { - CreateTestData(); + await CreateTestData(); RunTest(StringComparer.InvariantCultureIgnoreCase, true); RunTest(StringComparer.OrdinalIgnoreCase, true); @@ -137,9 +137,9 @@ void RunTest(StringComparer comparer, bool shouldBeCaseInsensitive) } [Fact] - public void query_with_then_by_descending_for_string_property_with_comparer() + public async Task query_with_then_by_descending_for_string_property_with_comparer() { - CreateTestData(true); + await CreateTestData(true); RunTest(StringComparer.InvariantCultureIgnoreCase, true); RunTest(StringComparer.OrdinalIgnoreCase, true); @@ -176,7 +176,7 @@ void RunTest(StringComparer comparer, bool shouldBeCaseInsensitive) } } - private void CreateTestData(bool createTargetsWithNumberTwo = false) + private async Task CreateTestData(bool createTargetsWithNumberTwo = false) { theSession.Store(new Target { @@ -217,6 +217,6 @@ private void CreateTestData(bool createTargetsWithNumberTwo = false) }); } - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } } diff --git a/src/LinqTests/ChildCollections/count_for_child_collections.cs b/src/LinqTests/ChildCollections/count_for_child_collections.cs index c7a9cbf343..b7b0fa4d00 100644 --- a/src/LinqTests/ChildCollections/count_for_child_collections.cs +++ b/src/LinqTests/ChildCollections/count_for_child_collections.cs @@ -16,11 +16,11 @@ public class count_for_child_collections : OneOffConfigurationsContext private readonly ITestOutputHelper _output; [Fact] - public void GivenTwoLevelsOfChildCollections_WhenCountCalled_ThenReturnsProperCount() + public async Task GivenTwoLevelsOfChildCollections_WhenCountCalled_ThenReturnsProperCount() { StoreOptions(op => op.UseDefaultSerialization(collectionStorage: CollectionStorage.AsArray)); - SetupTestData(); + await SetupTestData(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -37,7 +37,7 @@ public async Task two_levels_of_child_collections_in_compiled_query() { StoreOptions(op => op.UseDefaultSerialization(collectionStorage: CollectionStorage.AsArray)); - SetupTestData(); + await SetupTestData(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -62,7 +62,7 @@ public Expression, IEnumerable>> QueryIs() } - private void SetupTestData() + private async Task SetupTestData() { var product1 = new Root { @@ -138,7 +138,7 @@ private void SetupTestData() theSession.Store(product1); theSession.Store(product2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } public count_for_child_collections(ITestOutputHelper output) diff --git a/src/LinqTests/ChildCollections/query_against_child_collections.cs b/src/LinqTests/ChildCollections/query_against_child_collections.cs index c0f993bc63..15a5d16c63 100644 --- a/src/LinqTests/ChildCollections/query_against_child_collections.cs +++ b/src/LinqTests/ChildCollections/query_against_child_collections.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading.Tasks; using JasperFx.Core; using Marten.Exceptions; using Marten.Linq; @@ -25,7 +26,7 @@ public query_against_child_collections(ITestOutputHelper output) private Target[] targets; - private void buildUpTargetData() + private async Task buildUpTargetData() { targets = Target.GenerateRandomData(20).ToArray(); targets.SelectMany(x => x.Children).Each(x => x.Number = 5); @@ -49,13 +50,13 @@ private void buildUpTargetData() theSession.Store(targets); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } [Fact] - public void can_query_with_containment_operator() + public async Task can_query_with_containment_operator() { - buildUpTargetData(); + await buildUpTargetData(); var expected = new[] { targets[5].Id, targets[9].Id, targets[12].Id }.OrderBy(x => x); @@ -66,9 +67,9 @@ public void can_query_with_containment_operator() } [Fact] - public void can_query_with_an_any_operator() + public async Task can_query_with_an_any_operator() { - buildUpTargetData(); + await buildUpTargetData(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -87,9 +88,9 @@ public void can_query_with_an_any_operator() } [Fact] - public void can_query_with_an_any_operator_and_string_NotIsNullOrEmpty() + public async Task can_query_with_an_any_operator_and_string_NotIsNullOrEmpty() { - buildUpTargetData(); + await buildUpTargetData(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -104,9 +105,9 @@ public void can_query_with_an_any_operator_and_string_NotIsNullOrEmpty() } [Fact] - public void can_query_with_an_any_operator_and_string_IsNullOrWhitespace() + public async Task can_query_with_an_any_operator_and_string_IsNullOrWhitespace() { - buildUpTargetData(); + await buildUpTargetData(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -121,9 +122,9 @@ public void can_query_with_an_any_operator_and_string_IsNullOrWhitespace() } [Fact] - public void can_query_with_an_any_operator_that_does_a_multiple_search_within_the_collection() + public async Task can_query_with_an_any_operator_that_does_a_multiple_search_within_the_collection() { - buildUpTargetData(); + await buildUpTargetData(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -143,9 +144,9 @@ public void can_query_with_an_any_operator_that_does_a_multiple_search_within_th } [Fact] - public void can_query_on_deep_properties() + public async Task can_query_on_deep_properties() { - buildUpTargetData(); + await buildUpTargetData(); theSession.Query() .Single(x => Enumerable.Any(x.Children, _ => _.Inner.Number == -2)) @@ -155,10 +156,10 @@ public void can_query_on_deep_properties() [Theory] [InlineData(EnumStorage.AsInteger)] [InlineData(EnumStorage.AsString)] - public void can_query_on_enum_properties(EnumStorage enumStorage) + public async Task can_query_on_enum_properties(EnumStorage enumStorage) { StoreOptions(_ => _.UseDefaultSerialization(enumStorage)); - buildUpTargetData(); + await buildUpTargetData(); theSession.Query() .Count(x => x.Children.Any(_ => _.Color == Colors.Green)) @@ -168,10 +169,10 @@ public void can_query_on_enum_properties(EnumStorage enumStorage) [Theory] [InlineData(EnumStorage.AsInteger)] [InlineData(EnumStorage.AsString)] - public void can_query_on_deep_enum_properties(EnumStorage enumStorage) + public async Task can_query_on_deep_enum_properties(EnumStorage enumStorage) { StoreOptions(_ => _.UseDefaultSerialization(enumStorage)); - buildUpTargetData(); + await buildUpTargetData(); theSession.Query() .Count(x => x.Children.Any(_ => _.Inner.Color == Colors.Blue)) @@ -179,7 +180,7 @@ public void can_query_on_deep_enum_properties(EnumStorage enumStorage) } [Fact] - public void Bug_503_child_collection_query_in_compiled_query() + public async Task Bug_503_child_collection_query_in_compiled_query() { // Test failure bomb if (DateTime.Today < new DateTime(2023, 9, 12)) return; @@ -192,7 +193,7 @@ public void Bug_503_child_collection_query_in_compiled_query() outer.Inners.Add(new Inner { Type = "T2", Value = "V21" }); session.Store(outer); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session2 = theStore.LightweightSession()) @@ -277,7 +278,7 @@ public class Source private readonly Guid[] favAuthors = new Guid[] { Guid.NewGuid(), Guid.NewGuid() }; - private void buildAuthorData() + private async Task buildAuthorData() { // test fixtures theSession.Store(new Article @@ -323,13 +324,13 @@ private void buildAuthorData() AuthorArray = new Guid[] { favAuthors[0], Guid.NewGuid() }, ReferencedArticle = new Article { CategoryArray = new[] { "nested" }, } }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); } [Fact] - public void query_string_array_intersects_array() + public async Task query_string_array_intersects_array() { - buildAuthorData(); + await buildAuthorData(); var interests = new[] { "finance", "astrology" }; var res = theSession.Query
() @@ -376,9 +377,9 @@ public void query_nested_string_array_intersects_array() } [Fact] - public void query_string_array_intersects_array_with_boolean_and() + public async Task query_string_array_intersects_array_with_boolean_and() { - buildAuthorData(); + await buildAuthorData(); var interests = new[] { "finance", "astrology" }; var res = theSession.Query
() @@ -423,9 +424,9 @@ public void query_array_with_Intersect_should_blow_up() } [Fact] - public void query_guid_list_intersects_array() + public async Task query_guid_list_intersects_array() { - buildAuthorData(); + await buildAuthorData(); var res = theSession.Query
() .Where(x => x.AuthorList.Any(s => favAuthors.Contains(s))) @@ -438,7 +439,7 @@ public void query_guid_list_intersects_array() [Fact] - public void query_against_number_array() + public async Task query_against_number_array() { var doc1 = new DocWithArrays { Numbers = new[] { 1, 2, 3 } }; var doc2 = new DocWithArrays { Numbers = new[] { 3, 4, 5 } }; @@ -446,14 +447,14 @@ public void query_against_number_array() theSession.Store(doc1, doc2, doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Numbers.Contains(3)).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } [Fact] - public void query_against_number_array_count() + public async Task query_against_number_array_count() { var doc1 = new DocWithArrays { Numbers = new[] { 1, 2, 3 } }; var doc2 = new DocWithArrays { Numbers = new[] { 3, 4, 5 } }; @@ -461,7 +462,7 @@ public void query_against_number_array_count() theSession.Store(doc1, doc2, doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Numbers.Length == 4).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc3.Id); @@ -471,7 +472,7 @@ public void query_against_number_array_count() #region sample_query_against_string_array - public void query_against_string_array() + public async Task query_against_string_array() { var doc1 = new DocWithArrays { Strings = new[] { "a", "b", "c" } }; var doc2 = new DocWithArrays { Strings = new[] { "c", "d", "e" } }; @@ -481,7 +482,7 @@ public void query_against_string_array() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Strings.Contains("c")).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); @@ -490,7 +491,7 @@ public void query_against_string_array() #endregion [Fact] - public void query_against_string_array_with_Any() + public async Task query_against_string_array_with_Any() { var doc1 = new DocWithArrays { Strings = new[] { "a", "b", "c" } }; var doc2 = new DocWithArrays { Strings = new[] { "c", "d", "e" } }; @@ -500,14 +501,14 @@ public void query_against_string_array_with_Any() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Strings.Any(_ => _ == "c")).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } [Fact] - public void query_against_string_array_with_Length() + public async Task query_against_string_array_with_Length() { var doc1 = new DocWithArrays { Strings = new[] { "a", "b", "c" } }; var doc2 = new DocWithArrays { Strings = new[] { "c", "d", "e" } }; @@ -517,7 +518,7 @@ public void query_against_string_array_with_Length() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -526,7 +527,7 @@ public void query_against_string_array_with_Length() } [Fact] - public void query_against_string_array_with_Count_method() + public async Task query_against_string_array_with_Count_method() { var doc1 = new DocWithArrays { Strings = new[] { "a", "b", "c" } }; var doc2 = new DocWithArrays { Strings = new[] { "c", "d", "e" } }; @@ -536,14 +537,14 @@ public void query_against_string_array_with_Count_method() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Strings.Count() == 4).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc3.Id); } [Fact] - public void query_against_date_array() + public async Task query_against_date_array() { var doc1 = new DocWithArrays { @@ -562,14 +563,14 @@ public void query_against_date_array() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Dates.Contains(DateTime.Today.AddDays(2))).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } [Fact] - public void query_against_number_list() + public async Task query_against_number_list() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -579,7 +580,7 @@ public void query_against_number_list() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Numbers.Contains(3)).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); @@ -588,7 +589,7 @@ public void query_against_number_list() #region sample_query_any_string_array [Fact] - public void query_against_number_list_with_any() + public async Task query_against_number_list_with_any() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -597,7 +598,7 @@ public void query_against_number_list_with_any() theSession.Store(doc1, doc2, doc3, doc4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -614,7 +615,7 @@ public void query_against_number_list_with_any() #region sample_query_against_number_list_with_count_method [Fact] - public void query_against_number_list_with_count_method() + public async Task query_against_number_list_with_count_method() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -624,7 +625,7 @@ public void query_against_number_list_with_count_method() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); @@ -635,7 +636,7 @@ public void query_against_number_list_with_count_method() #endregion [Fact] - public void query_against_number_list_with_count_property() + public async Task query_against_number_list_with_count_property() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -645,14 +646,14 @@ public void query_against_number_list_with_count_property() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query() .Single(x => x.Numbers.Count == 4).Id.ShouldBe(doc3.Id); } [Fact] - public void query_against_number_list_with_count_property_and_other_operators() + public async Task query_against_number_list_with_count_property_and_other_operators() { var doc1 = new DocWithLists { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists { Numbers = new List { 3, 4, 5 } }; @@ -662,14 +663,14 @@ public void query_against_number_list_with_count_property_and_other_operators() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query() .Single(x => x.Numbers.Count > 3).Id.ShouldBe(doc3.Id); } [Fact] - public void query_against_number_IList() + public async Task query_against_number_IList() { var doc1 = new DocWithLists2 { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists2 { Numbers = new List { 3, 4, 5 } }; @@ -679,14 +680,14 @@ public void query_against_number_IList() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Numbers.Contains(3)).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } [Fact] - public void query_against_number_IEnumerable() + public async Task query_against_number_IEnumerable() { var doc1 = new DocWithLists3 { Numbers = new List { 1, 2, 3 } }; var doc2 = new DocWithLists3 { Numbers = new List { 3, 4, 5 } }; @@ -696,14 +697,14 @@ public void query_against_number_IEnumerable() theSession.Store(doc2); theSession.Store(doc3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Numbers.Contains(3)).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } [Fact] - public void naked_any_hit_without_predicate() + public async Task naked_any_hit_without_predicate() { var targetithchildren = new Target { Number = 1 }; targetithchildren.Children = new[] { new Target(), }; @@ -713,7 +714,7 @@ public void naked_any_hit_without_predicate() theSession.Store(nochildrennullarray); theSession.Store(nochildrenemptyarray); theSession.Store(targetithchildren); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var items = theSession.Query().Where(x => x.Children.Any()).ToList(); diff --git a/src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs b/src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs index e1ba81d887..562f6c0e0c 100644 --- a/src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs +++ b/src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs @@ -105,7 +105,11 @@ public class query_with_inner_query_with_CollectionToArrayJsonConverter_onProper [MemberData(nameof(Predicates))] public async Task having_type_with_CollectionToArrayJsonConverter_can_query_against_array_of_string(Expression> predicate) { - SetupTestData(); + using (var session = theStore.LightweightSession()) + { + session.Store(TestData); + await session.SaveChangesAsync(); + } await using var query = theStore.QuerySession(); query.Logger = new TestOutputMartenLogger(_output); @@ -117,13 +121,6 @@ public async Task having_type_with_CollectionToArrayJsonConverter_can_query_agai results.All(e => e.Enumerable.Contains(SearchPhrase)).ShouldBeTrue(); } - private void SetupTestData() - { - using var session = theStore.LightweightSession(); - session.Store(TestData); - session.SaveChanges(); - } - public query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { _output = output; diff --git a/src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs b/src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs index c9258252ec..bed740d5a3 100644 --- a/src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs +++ b/src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs @@ -139,7 +139,7 @@ public async Task having_store_options_with_CollectionStorage_AsArray_can_query_ { options.UseDefaultSerialization(collectionStorage: CollectionStorage.AsArray); }); - SetupTestData(); + await SetupTestData(); await using (var query = theStore.QuerySession()) { @@ -152,11 +152,11 @@ public async Task having_store_options_with_CollectionStorage_AsArray_can_query_ } } - private void SetupTestData() + private async Task SetupTestData() { using var session = theStore.LightweightSession(); session.Store(TestData); - session.SaveChanges(); + await session.SaveChangesAsync(); } public query_with_inner_query_with_global_CollectionStorage_WithArray() diff --git a/src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs b/src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs index 78286d7bde..3dfff6a825 100644 --- a/src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs +++ b/src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading.Tasks; using Marten.Linq; using Marten.Testing.Harness; using Shouldly; @@ -18,14 +19,14 @@ public class end_to_end_query_with_compiled_include_Tests: IntegrationContext #region sample_compiled_include [Fact] - public void simple_compiled_include_for_a_single_document() + public async Task simple_compiled_include_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var issueQuery = new IssueByTitleWithAssignee { Title = issue.Title }; @@ -67,7 +68,7 @@ public Expression, IEnumerable>> QueryIs() } [Fact] - public void compiled_include_to_list() + public async Task compiled_include_to_list() { var user1 = new User(); var user2 = new User(); @@ -79,7 +80,7 @@ public void compiled_include_to_list() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = theStore.QuerySession(); var compiledQuery = new IssueWithUsers(); @@ -111,7 +112,7 @@ public Expression, IEnumerable>> QueryIs() } [Fact] - public void compiled_include_to_dictionary() + public async Task compiled_include_to_dictionary() { var user1 = new User(); var user2 = new User(); @@ -123,7 +124,7 @@ public void compiled_include_to_dictionary() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var querySession = theStore.QuerySession(); var compiledQuery = new IssueWithUsersById(); diff --git a/src/LinqTests/Includes/end_to_end_query_with_include.cs b/src/LinqTests/Includes/end_to_end_query_with_include.cs index c9a390bb5b..3a7348019d 100644 --- a/src/LinqTests/Includes/end_to_end_query_with_include.cs +++ b/src/LinqTests/Includes/end_to_end_query_with_include.cs @@ -80,14 +80,14 @@ public async Task include_within_batch_query() #region sample_simple_include [Fact] - public void simple_include_for_a_single_document() + public async Task simple_include_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); query.Logger = new TestOutputMartenLogger(_output); @@ -107,14 +107,14 @@ public void simple_include_for_a_single_document() #endregion [Fact] - public void include_with_containment_where_for_a_single_document() + public async Task include_with_containment_where_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Tags = new[] { "DIY" }, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -131,7 +131,7 @@ public void include_with_containment_where_for_a_single_document() [Fact] - public void include_with_containment_where_for_a_single_document_with_camel_casing() + public async Task include_with_containment_where_for_a_single_document_with_camel_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); @@ -140,7 +140,7 @@ public void include_with_containment_where_for_a_single_document_with_camel_casi using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -156,14 +156,14 @@ public void include_with_containment_where_for_a_single_document_with_camel_casi } [Fact] - public void include_with_any_containment_where_for_a_single_document() + public async Task include_with_any_containment_where_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Tags = new[] { "DIY" }, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -179,7 +179,7 @@ public void include_with_any_containment_where_for_a_single_document() } [Fact] - public void include_with_any_containment_where_for_a_single_document_with_camel_casing_2() + public async Task include_with_any_containment_where_for_a_single_document_with_camel_casing_2() { StoreOptions(_ => _.UseDefaultSerialization(EnumStorage.AsString, Casing.CamelCase)); @@ -188,7 +188,7 @@ public void include_with_any_containment_where_for_a_single_document_with_camel_ using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -204,7 +204,7 @@ public void include_with_any_containment_where_for_a_single_document_with_camel_ } [Fact] - public void include_with_any_containment_where_for_a_single_document_with_snake_casing_2() + public async Task include_with_any_containment_where_for_a_single_document_with_snake_casing_2() { StoreOptions(_ => _.UseDefaultSerialization(EnumStorage.AsString, Casing.SnakeCase)); @@ -213,7 +213,7 @@ public void include_with_any_containment_where_for_a_single_document_with_snake_ using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -229,7 +229,7 @@ public void include_with_any_containment_where_for_a_single_document_with_snake_ } [Fact] - public void include_with_any_containment_where_for_a_single_document_with_camel_casing() + public async Task include_with_any_containment_where_for_a_single_document_with_camel_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.CamelCase)); @@ -238,7 +238,7 @@ public void include_with_any_containment_where_for_a_single_document_with_camel_ using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -254,7 +254,7 @@ public void include_with_any_containment_where_for_a_single_document_with_camel_ } [Fact] - public void include_with_any_containment_where_for_a_single_document_with_snake_casing() + public async Task include_with_any_containment_where_for_a_single_document_with_snake_casing() { StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.SnakeCase)); @@ -263,7 +263,7 @@ public void include_with_any_containment_where_for_a_single_document_with_snake_ using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -279,7 +279,7 @@ public void include_with_any_containment_where_for_a_single_document_with_snake_ } [Fact] - public void include_with_any_array_containment_where_for_a_single_document() + public async Task include_with_any_array_containment_where_for_a_single_document() { var user = new User(); var issue1 = new Issue { AssigneeId = user.Id, Tags = new[] { "DIY" }, Title = "Garage Door is busted" }; @@ -291,7 +291,7 @@ public void include_with_any_array_containment_where_for_a_single_document() using var session = theStore.IdentitySession(); session.Store(user); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var users = new List(); @@ -309,14 +309,14 @@ public void include_with_any_array_containment_where_for_a_single_document() } [Fact] - public void include_with_generic_type() + public async Task include_with_generic_type() { var user = new UserWithInterface { Id = Guid.NewGuid(), UserName = "Jens" }; var issue = new Issue { AssigneeId = user.Id, Tags = new[] { "DIY" }, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); IncludeGeneric(user); } @@ -337,13 +337,13 @@ private void IncludeGeneric(UserWithInterface userToCompareAgainst) where T : } [Fact] - public void simple_include_for_a_single_document_using_outer_join() + public async Task simple_include_for_a_single_document_using_outer_join() { var issue = new Issue { AssigneeId = null, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -358,7 +358,7 @@ public void simple_include_for_a_single_document_using_outer_join() } [Fact] - public void include_to_list() + public async Task include_to_list() { var user1 = new User { FirstName = "Travis", LastName = "Kelce" }; var user2 = new User { FirstName = "Tyrann", LastName = "Mathieu" }; @@ -370,7 +370,7 @@ public void include_to_list() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var list = new List(); @@ -384,7 +384,7 @@ public void include_to_list() } [Fact] - public void include_to_list_using_inner_join() + public async Task include_to_list_using_inner_join() { var user1 = new User(); var user2 = new User(); @@ -397,7 +397,7 @@ public void include_to_list_using_inner_join() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3, issue4); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var list = new List(); @@ -416,7 +416,7 @@ public void include_to_list_using_inner_join() } [Fact] - public void include_to_list_using_outer_join() + public async Task include_to_list_using_outer_join() { var user1 = new User(); var user2 = new User(); @@ -429,7 +429,7 @@ public void include_to_list_using_outer_join() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3, issue4); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var list = new List(); @@ -446,7 +446,7 @@ public void include_to_list_using_outer_join() } [Fact] - public void include_is_running_through_identitymap() + public async Task include_is_running_through_identitymap() { var user1 = new User(); var user2 = new User(); @@ -458,7 +458,7 @@ public void include_is_running_through_identitymap() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); // This will only work with a non-NulloIdentityMap using var query = theStore.IdentitySession(); @@ -473,7 +473,7 @@ public void include_is_running_through_identitymap() #region sample_dictionary_include [Fact] - public void include_to_dictionary() + public async Task include_to_dictionary() { var user1 = new User(); var user2 = new User(); @@ -485,7 +485,7 @@ public void include_to_dictionary() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary(); @@ -500,7 +500,7 @@ public void include_to_dictionary() #endregion [Fact] - public void include_to_dictionary_with_select() + public async Task include_to_dictionary_with_select() { var user1 = new User(); var user2 = new User(); @@ -515,7 +515,7 @@ public void include_to_dictionary_with_select() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary(); @@ -536,7 +536,7 @@ public void include_to_dictionary_with_select() } [Fact] - public void include_to_dictionary_using_inner_join() + public async Task include_to_dictionary_using_inner_join() { var user1 = new User(); var user2 = new User(); @@ -549,7 +549,7 @@ public void include_to_dictionary_using_inner_join() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3, issue4); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary(); @@ -567,7 +567,7 @@ public void include_to_dictionary_using_inner_join() } [Fact] - public void include_to_dictionary_using_outer_join() + public async Task include_to_dictionary_using_outer_join() { var user1 = new User(); var user2 = new User(); @@ -580,7 +580,7 @@ public void include_to_dictionary_using_outer_join() using var session = theStore.IdentitySession(); session.Store(user1, user2); session.Store(issue1, issue2, issue3, issue4); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary(); @@ -730,7 +730,7 @@ public async Task include_to_dictionary_async() #region sample_multiple_include [Fact] - public void multiple_includes() + public async Task multiple_includes() { var assignee = new User{FirstName = "Assignee"}; var reporter = new User{FirstName = "Reporter"}; @@ -740,7 +740,7 @@ public void multiple_includes() using var session = theStore.IdentitySession(); session.Store(assignee, reporter); session.Store(issue1); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User assignee2 = null; @@ -761,7 +761,7 @@ public void multiple_includes() #endregion [Fact] - public void include_many_to_list() + public async Task include_many_to_list() { var user1 = new User { }; var user2 = new User { }; @@ -780,7 +780,7 @@ public void include_many_to_list() using (var session = theStore.LightweightSession()) { session.Store(group1, group2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -805,14 +805,14 @@ public void include_many_to_list() } [Fact] - public void Bug_1751_Include_with_select() + public async Task Bug_1751_Include_with_select() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -873,14 +873,14 @@ public async Task Bug_1715_simple_include_for_a_single_document_async() } [Fact] - public void Bug_1752_simple_include_for_a_single_document() + public async Task Bug_1752_simple_include_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; using var session = theStore.IdentitySession(); session.Store(user, issue); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); User included = null; @@ -894,7 +894,7 @@ public void Bug_1752_simple_include_for_a_single_document() } [Fact] - public void include_many_to_list_with_empty_parent_collection() + public async Task include_many_to_list_with_empty_parent_collection() { var user1 = new User(); var user2 = new User(); @@ -908,7 +908,7 @@ public void include_many_to_list_with_empty_parent_collection() using (var session = theStore.LightweightSession()) { session.Store(group1, group2); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -935,14 +935,14 @@ public void include_many_to_list_with_empty_parent_collection() #region sample_include_using_custom_map [Fact] - public void include_using_custom_map() + public async Task include_using_custom_map() { var classroom = new Classroom(Id: Guid.NewGuid(), RoomCode: "Classroom-1A"); var user = new SchoolUser(Id: Guid.NewGuid(), Name: "Student #1", HomeRoom: "Classroom-1A"); using var session = theStore.IdentitySession(); session.Store(classroom, user); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); Classroom? included = null; @@ -962,7 +962,7 @@ public void include_using_custom_map() #region sample_dictionary_list_include [Fact] - public void include_to_dictionary_list() + public async Task include_to_dictionary_list() { var class1 = new Classroom(Id: Guid.NewGuid(), RoomCode: "Classroom-1A"); var class2 = new Classroom(Id: Guid.NewGuid(), RoomCode: "Classroom-2B"); @@ -974,7 +974,7 @@ public void include_to_dictionary_list() using var session = theStore.IdentitySession(); session.Store(class1, class2); session.Store(user1, user2, user3); - session.SaveChanges(); + await session.SaveChangesAsync(); using var query = theStore.QuerySession(); var dict = new Dictionary>(); diff --git a/src/LinqTests/Internals/BoolNotVisitorTests.cs b/src/LinqTests/Internals/BoolNotVisitorTests.cs index af1af47221..2d8d839bf1 100644 --- a/src/LinqTests/Internals/BoolNotVisitorTests.cs +++ b/src/LinqTests/Internals/BoolNotVisitorTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Services; using Marten.Testing.Harness; using Xunit.Abstractions; @@ -22,12 +23,12 @@ public TestClass() } [Fact] - public void when_doc_with_bool_false_should_return_records() + public async Task when_doc_with_bool_false_should_return_records() { var docWithFlagFalse = new TestClass(); theSession.Store(docWithFlagFalse); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var s = theStore.QuerySession(); var items = s.Query().Where(x => !x.Flag).ToList(); @@ -37,7 +38,7 @@ public void when_doc_with_bool_false_should_return_records() } [Fact] - public void when_doc_with_bool_false_with_serializer_default_value_handling_null_should_return_records() + public async Task when_doc_with_bool_false_with_serializer_default_value_handling_null_should_return_records() { var serializer = new JsonNetSerializer(); serializer.Customize(s => @@ -51,7 +52,7 @@ public void when_doc_with_bool_false_with_serializer_default_value_handling_null var docWithFlagFalse = new TestClass(); theSession.Store(docWithFlagFalse); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var s = theStore.QuerySession()) { diff --git a/src/LinqTests/Operators/aggregate_functions.cs b/src/LinqTests/Operators/aggregate_functions.cs index 52f937bcb9..38640a5dde 100644 --- a/src/LinqTests/Operators/aggregate_functions.cs +++ b/src/LinqTests/Operators/aggregate_functions.cs @@ -12,14 +12,14 @@ public class aggregate_functions : IntegrationContext { #region sample_using_max [Fact] - public void get_max() + public async Task get_max() { theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); theSession.Store(new Target { Color = Colors.Red, Number = 42 }); theSession.Store(new Target { Color = Colors.Green, Number = 3 }); theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var maxNumber = theSession.Query().Max(t => t.Number); maxNumber.ShouldBe(42); } @@ -40,14 +40,14 @@ public async Task get_max_async() #region sample_using_min [Fact] - public void get_min() + public async Task get_min() { theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); theSession.Store(new Target { Color = Colors.Red, Number = 2 }); theSession.Store(new Target { Color = Colors.Green, Number = -5 }); theSession.Store(new Target { Color = Colors.Blue, Number = 42 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var minNumber = theSession.Query().Min(t => t.Number); minNumber.ShouldBe(-5); } @@ -68,14 +68,14 @@ public async Task get_min_async() #region sample_using_average [Fact] - public void get_average() + public async Task get_average() { theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); theSession.Store(new Target { Color = Colors.Red, Number = 2 }); theSession.Store(new Target { Color = Colors.Green, Number = -5 }); theSession.Store(new Target { Color = Colors.Blue, Number = 42 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var average = theSession.Query().Average(t => t.Number); average.ShouldBe(10); } @@ -95,26 +95,26 @@ public async Task get_average_async() } [Fact] - public void sum_without_any_where() + public async Task sum_without_any_where() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var result = theSession.Query().Sum(x => x.Number); result.ShouldBe(10); } [Fact] - public void sum_with_nullable() + public async Task sum_with_nullable() { theSession.Store(new Target { NullableNumber = 1 }); theSession.Store(new Target { NullableNumber = 2 }); theSession.Store(new Target { NullableNumber = 3 }); theSession.Store(new Target { NullableNumber = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var result = theSession.Query().Sum(x => x.NullableNumber); result.ShouldBe(10); @@ -149,14 +149,14 @@ public async Task sum_with_nullable_async() #region sample_using_sum [Fact] - public void get_sum_of_integers() + public async Task get_sum_of_integers() { theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); theSession.Store(new Target { Color = Colors.Red, Number = 2 }); theSession.Store(new Target { Color = Colors.Green, Number = 3 }); theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Sum(x => x.Number) .ShouldBe(10); } @@ -164,13 +164,13 @@ public void get_sum_of_integers() #endregion [Fact] - public void get_sum_of_decimals() + public async Task get_sum_of_decimals() { theSession.Store(new Target { Color = Colors.Blue, Decimal = 1.1m }); theSession.Store(new Target { Color = Colors.Red, Decimal = 2.2m }); theSession.Store(new Target { Color = Colors.Green, Decimal = 3.3m }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Sum(x => x.Decimal) .ShouldBe(6.6m); } @@ -183,14 +183,14 @@ public void get_sum_of_empty_table() } [Fact] - public void get_sum_of_integers_with_where() + public async Task get_sum_of_integers_with_where() { theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); theSession.Store(new Target { Color = Colors.Red, Number = 2 }); theSession.Store(new Target { Color = Colors.Green, Number = 3 }); theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number < 4).Sum(x => x.Number) .ShouldBe(6); } @@ -211,7 +211,7 @@ public async Task get_sum_of_integers_with_where_async() [Theory] [InlineData(EnumStorage.AsString)] [InlineData(EnumStorage.AsInteger)] - public void get_sum_of_integers_with_where_with_nullable_enum(EnumStorage enumStorage) + public async Task get_sum_of_integers_with_where_with_nullable_enum(EnumStorage enumStorage) { StoreOptions(o => o.UseDefaultSerialization(enumStorage)); @@ -220,7 +220,7 @@ public void get_sum_of_integers_with_where_with_nullable_enum(EnumStorage enumSt theSession.Store(new Target { NullableColor = Colors.Green, Number = 3 }); theSession.Store(new Target { NullableColor = null, Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query() .Where(x => x.NullableColor != null) .Sum(x => x.Number) diff --git a/src/LinqTests/Operators/all_operator.cs b/src/LinqTests/Operators/all_operator.cs index 22740d95fc..72bf3bf318 100644 --- a/src/LinqTests/Operators/all_operator.cs +++ b/src/LinqTests/Operators/all_operator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; @@ -16,7 +17,7 @@ public all_operator(DefaultStoreFixture fixture, ITestOutputHelper output) : bas } [Fact] - public void invoking_queryable_all_operation_test1() + public async Task invoking_queryable_all_operation_test1() { theSession.Store(new User { FirstName = "Hank" , Roles = new []{ "R1", default(string)}}); theSession.Store(new User { FirstName = "Bill" , Roles = new []{ "R3", "R5"} }); @@ -25,7 +26,7 @@ public void invoking_queryable_all_operation_test1() theSession.Store(new User { FirstName = "Joe" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Tom" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Joe" , Roles = new []{ default(string), default(string)} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.Roles.All(r => r == "R1")) @@ -35,7 +36,7 @@ public void invoking_queryable_all_operation_test1() } [Fact] - public void invoking_queryable_all_operation_test2() + public async Task invoking_queryable_all_operation_test2() { theSession.Store(new User { FirstName = "Hank" , Roles = new []{ "R1", default(string)}}); theSession.Store(new User { FirstName = "Bill" , Roles = new []{ "R3", "R5"} }); @@ -44,7 +45,7 @@ public void invoking_queryable_all_operation_test2() theSession.Store(new User { FirstName = "Joe" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Tom" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Joe" , Roles = new []{ default(string), default(string)} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.FirstName == "Joe" && u.Roles.All(r => r == "R1")) @@ -54,7 +55,7 @@ public void invoking_queryable_all_operation_test2() } [Fact] - public void invoking_queryable_all_operation_test3() + public async Task invoking_queryable_all_operation_test3() { theSession.Store(new User { FirstName = "Hank" , Roles = new []{ "R1", default(string)}}); theSession.Store(new User { FirstName = "Bill" , Roles = new []{ "R3", "R5"} }); @@ -63,7 +64,7 @@ public void invoking_queryable_all_operation_test3() theSession.Store(new User { FirstName = "Joe" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Tom" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Joe" , Roles = new []{ default(string), default(string)} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.FirstName == "Jean" && u.Roles.All(r => r == "R1")) @@ -73,7 +74,7 @@ public void invoking_queryable_all_operation_test3() } [Fact] - public void invoking_queryable_all_operation_test4() + public async Task invoking_queryable_all_operation_test4() { theSession.Store(new User { FirstName = "Hank" , Roles = new []{ "R1", default(string)}}); theSession.Store(new User { FirstName = "Bill" , Roles = new []{ "R3", "R5"} }); @@ -82,7 +83,7 @@ public void invoking_queryable_all_operation_test4() theSession.Store(new User { FirstName = "Joe" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Tom" , Roles = new []{ "R1", "R1"} }); theSession.Store(new User { FirstName = "Joe" , Roles = new []{ default(string), default(string)} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); /* SHOULD BE WITH mt_temp_id_list1CTE as ( @@ -109,7 +110,7 @@ WITH mt_temp_id_list1CTE as ( } [Fact] - public void invoking_queryable_all_operation_test5() + public async Task invoking_queryable_all_operation_test5() { theSession.Store(new User { @@ -131,7 +132,7 @@ public void invoking_queryable_all_operation_test5() FirstName = "Joe" , Roles = new []{ "R1", default(string)}, Friends = new List { new(){ Name = default}, new(){ Name = default}} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.Friends.All(f => f.Name == "F1")) @@ -141,7 +142,7 @@ public void invoking_queryable_all_operation_test5() } [Fact] - public void invoking_queryable_all_operation_test6() + public async Task invoking_queryable_all_operation_test6() { theSession.Store(new User { @@ -163,7 +164,7 @@ public void invoking_queryable_all_operation_test6() FirstName = "Joe" , Roles = new []{ "R1", default(string)}, Friends = new List { new(){ Name = default}, new(){ Name = default}} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.FirstName == "Joe" && u.Friends.All(f => f.Name == "F1")) @@ -173,7 +174,7 @@ public void invoking_queryable_all_operation_test6() } [Fact] - public void invoking_queryable_all_operation_test7() + public async Task invoking_queryable_all_operation_test7() { theSession.Store(new User { @@ -195,7 +196,7 @@ public void invoking_queryable_all_operation_test7() FirstName = "Joe" , Roles = new []{ "R1", default(string)}, Friends = new List { new(){ Name = default}, new(){ Name = default}} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.Friends.All(f => f.Name == null)) @@ -205,7 +206,7 @@ public void invoking_queryable_all_operation_test7() } [Fact] - public void invoking_queryable_all_operation_test8() + public async Task invoking_queryable_all_operation_test8() { theSession.Store(new User { @@ -227,7 +228,7 @@ public void invoking_queryable_all_operation_test8() FirstName = "Joe" , Roles = new []{ "R1", default(string)}, Friends = new List { new(){ Name = default}, new(){ Name = default}} }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var results = theSession.Query() .Where(u => u.FirstName == "Bill" && u.Friends.All(f => f.Name == null)) diff --git a/src/LinqTests/Operators/any_operator.cs b/src/LinqTests/Operators/any_operator.cs index 942f3664ea..e0c6648224 100644 --- a/src/LinqTests/Operators/any_operator.cs +++ b/src/LinqTests/Operators/any_operator.cs @@ -10,13 +10,13 @@ namespace LinqTests.Operators; public class any_operator: IntegrationContext { [Fact] - public void any_miss_with_query() + public async Task any_miss_with_query() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Any(x => x.Number == 11) .ShouldBeFalse(); @@ -30,13 +30,13 @@ public void naked_any_miss() } [Fact] - public void naked_any_hit() + public async Task naked_any_hit() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Any().ShouldBeTrue(); } @@ -54,26 +54,26 @@ public async Task any_should_ignore_order() } [Fact] - public void any_hit_with_only_one_document() + public async Task any_hit_with_only_one_document() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Any(x => x.Number == 3) .ShouldBeTrue(); } [Fact] - public void any_hit_with_more_than_one_match() + public async Task any_hit_with_more_than_one_match() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number == 2).Any() .ShouldBeTrue(); @@ -106,7 +106,7 @@ public async Task naked_any_hit_async() theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var result = await theSession.Query().AnyAsync(); result.ShouldBeTrue(); @@ -119,7 +119,7 @@ public async Task any_hit_with_only_one_document_async() theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var result = await theSession.Query().AnyAsync(x => x.Number == 3); result.ShouldBeTrue(); @@ -132,7 +132,7 @@ public async Task any_hit_with_more_than_one_match_async() theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var result = await theSession.Query().Where(x => x.Number == 2).AnyAsync(); result.ShouldBeTrue(); diff --git a/src/LinqTests/Operators/count_operator.cs b/src/LinqTests/Operators/count_operator.cs index ce63dfb070..f68eb536c0 100644 --- a/src/LinqTests/Operators/count_operator.cs +++ b/src/LinqTests/Operators/count_operator.cs @@ -10,13 +10,13 @@ namespace LinqTests.Operators; public class count_operator: IntegrationContext { [Fact] - public void count_without_any_where() + public async Task count_without_any_where() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count().ShouldBe(4); } @@ -34,19 +34,19 @@ public async Task count_ignores_order_by() } [Fact] - public void long_count_without_any_where() + public async Task long_count_without_any_where() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().LongCount().ShouldBe(4); } [Fact] - public void count_matching_properties_within_type() + public async Task count_matching_properties_within_type() { var t1 = new Target(); t1.OtherGuid = t1.Id; @@ -57,12 +57,12 @@ public void count_matching_properties_within_type() theSession.Store(t2); theSession.Store(new Target()); theSession.Store(new Target()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(x => x.Id == x.OtherGuid).ShouldBe(2); } [Fact] - public void count_matching_properties_within_type_notequals() + public async Task count_matching_properties_within_type_notequals() { var t1 = new Target(); t1.OtherGuid = t1.Id; @@ -73,7 +73,7 @@ public void count_matching_properties_within_type_notequals() theSession.Store(t2); theSession.Store(new Target()); theSession.Store(new Target()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(x => x.Id != x.OtherGuid).ShouldBe(2); } @@ -96,7 +96,7 @@ public async Task count_matching_properties_within_type_async() } [Fact] - public void long_count_with_a_where_clause() + public async Task long_count_with_a_where_clause() { // theSession is an IDocumentSession in this test theSession.Store(new Target { Number = 1 }); @@ -105,14 +105,14 @@ public void long_count_with_a_where_clause() theSession.Store(new Target { Number = 4 }); theSession.Store(new Target { Number = 5 }); theSession.Store(new Target { Number = 6 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().LongCount(x => x.Number > 3).ShouldBe(3); } [Fact] #region sample_using_count - public void count_with_a_where_clause() + public async Task count_with_a_where_clause() { // theSession is an IDocumentSession in this test theSession.Store(new Target { Number = 1 }); @@ -121,7 +121,7 @@ public void count_with_a_where_clause() theSession.Store(new Target { Number = 4 }); theSession.Store(new Target { Number = 5 }); theSession.Store(new Target { Number = 6 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Count(x => x.Number > 3).ShouldBe(3); } diff --git a/src/LinqTests/Operators/distinct_operator.cs b/src/LinqTests/Operators/distinct_operator.cs index c697aee582..fe7c1f43ca 100644 --- a/src/LinqTests/Operators/distinct_operator.cs +++ b/src/LinqTests/Operators/distinct_operator.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Services.Json; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -12,7 +13,7 @@ public class distinct_operator : IntegrationContext private readonly ITestOutputHelper _output; [Fact] - public void get_distinct_number() + public async Task get_distinct_number() { theSession.Store(new Target {Number = 1}); theSession.Store(new Target {Number = 1}); @@ -21,7 +22,7 @@ public void get_distinct_number() theSession.Store(new Target {Number = 3}); theSession.Store(new Target {Number = 3}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); var queryable = theSession.Query().Select(x => x.Number).Distinct(); @@ -31,7 +32,7 @@ public void get_distinct_number() #region sample_get_distinct_numbers [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void get_distinct_numbers() + public async Task get_distinct_numbers() { theSession.Store(new Target {Number = 1, Decimal = 1.0M}); theSession.Store(new Target {Number = 1, Decimal = 2.0M}); @@ -40,7 +41,7 @@ public void get_distinct_numbers() theSession.Store(new Target {Number = 2, Decimal = 2.0M}); theSession.Store(new Target {Number = 2, Decimal = 1.0M}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var queryable = theSession.Query().Select(x => new { @@ -54,7 +55,7 @@ public void get_distinct_numbers() #region sample_get_distinct_strings [Fact] - public void get_distinct_string() + public async Task get_distinct_string() { theSession.Store(new Target {String = "one"}); theSession.Store(new Target {String = "one"}); @@ -63,7 +64,7 @@ public void get_distinct_string() theSession.Store(new Target {String = "three"}); theSession.Store(new Target {String = "three"}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var queryable = theSession.Query().Select(x => x.String).Distinct(); @@ -73,7 +74,7 @@ public void get_distinct_string() #endregion [Fact] - public void get_distinct_strings() + public async Task get_distinct_strings() { theSession.Store(new Target {String = "one", AnotherString = "one"}); theSession.Store(new Target {String = "one", AnotherString = "two"}); @@ -82,7 +83,7 @@ public void get_distinct_strings() theSession.Store(new Target {String = "two", AnotherString = "two"}); theSession.Store(new Target {String = "two", AnotherString = "two"}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Logger = new TestOutputMartenLogger(_output); var queryable = theSession.Query().Select(x => new diff --git a/src/LinqTests/Operators/first_operator.cs b/src/LinqTests/Operators/first_operator.cs index 7ec6c67703..42a4dae2ac 100644 --- a/src/LinqTests/Operators/first_operator.cs +++ b/src/LinqTests/Operators/first_operator.cs @@ -17,31 +17,31 @@ public class first_operator: IntegrationContext [Fact] - public void first_hit_with_only_one_document() + public async Task first_hit_with_only_one_document() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); SpecificationExtensions.ShouldNotBeNull(theSession.Query().First(x => x.Number == 3)); } [Fact] - public void first_or_default_hit_with_only_one_document() + public async Task first_or_default_hit_with_only_one_document() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().FirstOrDefault(x => x.Number == 3).ShouldNotBeNull(); } [Fact] - public void first_or_default_miss() + public async Task first_or_default_miss() { theSession.Logger = new TestOutputMartenLogger(_output); @@ -49,45 +49,45 @@ public void first_or_default_miss() theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().FirstOrDefault(x => x.Number == 11).ShouldBeNull(); } [Fact] - public void first_correct_hit_with_more_than_one_match() + public async Task first_correct_hit_with_more_than_one_match() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2, Flag = true }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number == 2).First().Flag .ShouldBeTrue(); } [Fact] - public void first_or_default_correct_hit_with_more_than_one_match() + public async Task first_or_default_correct_hit_with_more_than_one_match() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2, Flag = true }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number == 2).First().Flag .ShouldBeTrue(); } [Fact] - public void first_miss() + public async Task first_miss() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Exception.ShouldBeThrownBy(() => { diff --git a/src/LinqTests/Operators/is_empty_operator.cs b/src/LinqTests/Operators/is_empty_operator.cs index d045854f95..eb35aa09d6 100644 --- a/src/LinqTests/Operators/is_empty_operator.cs +++ b/src/LinqTests/Operators/is_empty_operator.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ namespace LinqTests.Operators; public class is_empty_operator : IntegrationContext { [Fact] - public void use_is_empty() + public async Task use_is_empty() { var doc1 = Target.Random(false); var doc2 = Target.Random(true); @@ -20,7 +21,7 @@ public void use_is_empty() using (var session = theStore.LightweightSession()) { session.Store(doc1, doc2, doc3, doc4); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/LinqTests/Operators/last_operator.cs b/src/LinqTests/Operators/last_operator.cs index 8978124eb6..6f9de3bdbe 100644 --- a/src/LinqTests/Operators/last_operator.cs +++ b/src/LinqTests/Operators/last_operator.cs @@ -9,13 +9,13 @@ namespace LinqTests.Operators; public class last_operator: IntegrationContext { [Fact] - public void last_throws_an_exception() + public async Task last_throws_an_exception() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Exception.ShouldBeThrownBy(() => { @@ -25,13 +25,13 @@ public void last_throws_an_exception() } [Fact] - public void last_or_default_throws_an_exception() + public async Task last_or_default_throws_an_exception() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Exception.ShouldBeThrownBy(() => { diff --git a/src/LinqTests/Operators/modulo_operator.cs b/src/LinqTests/Operators/modulo_operator.cs index c473c5a1a4..97eda1105a 100644 --- a/src/LinqTests/Operators/modulo_operator.cs +++ b/src/LinqTests/Operators/modulo_operator.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -8,7 +9,7 @@ public class query_with_modulo_Tests : IntegrationContext { #region sample_querying-with-modulo [Fact] - public void use_modulo() + public async Task use_modulo() { theSession.Store(new Target{Color = Colors.Blue, Number = 1}); theSession.Store(new Target{Color = Colors.Blue, Number = 2}); @@ -17,7 +18,7 @@ public void use_modulo() theSession.Store(new Target{Color = Colors.Blue, Number = 5}); theSession.Store(new Target{Color = Colors.Green, Number = 6}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number % 2 == 0 && x.Color < Colors.Green).ToArray() .Select(x => x.Number) @@ -26,7 +27,7 @@ public void use_modulo() #endregion [Fact] - public void use_modulo_operands_reversed() + public async Task use_modulo_operands_reversed() { theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); theSession.Store(new Target { Color = Colors.Blue, Number = 2 }); @@ -35,7 +36,7 @@ public void use_modulo_operands_reversed() theSession.Store(new Target { Color = Colors.Blue, Number = 5 }); theSession.Store(new Target { Color = Colors.Green, Number = 6 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => 0 == x.Number % 2 && Colors.Green > x.Color).ToArray() .Select(x => x.Number) diff --git a/src/LinqTests/Operators/negation_operator.cs b/src/LinqTests/Operators/negation_operator.cs index 824e5e6db3..374ae47637 100644 --- a/src/LinqTests/Operators/negation_operator.cs +++ b/src/LinqTests/Operators/negation_operator.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Harness; using Shouldly; @@ -8,7 +9,7 @@ namespace LinqTests.Operators; public class negation_operator : IntegrationContext { [Fact] - public void negating_predicate_with_an_and_operator_results_in_a_correct_query() + public async Task negating_predicate_with_an_and_operator_results_in_a_correct_query() { var player1 = new Player {Name = "Tony", Level = 10}; var player2 = new Player {Name = "Mark", Level = 20}; @@ -16,7 +17,7 @@ public void negating_predicate_with_an_and_operator_results_in_a_correct_query() var player4 = new Player {Name = "Leeroy", Level = 20}; theSession.Store(player1, player2, player3, player4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); @@ -28,7 +29,7 @@ public void negating_predicate_with_an_and_operator_results_in_a_correct_query() } [Fact] - public void negating_predicate_with_an_or_operator_results_in_a_correct_query() + public async Task negating_predicate_with_an_or_operator_results_in_a_correct_query() { var player1 = new Player { Name = "Tony", Level = 10}; var player2 = new Player { Name = "Mark", Level = 20}; @@ -36,7 +37,7 @@ public void negating_predicate_with_an_or_operator_results_in_a_correct_query() var player4 = new Player { Name = "Leeroy", Level = 20}; theSession.Store(player1, player2, player3, player4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using var query = theStore.QuerySession(); diff --git a/src/LinqTests/Operators/single_operator.cs b/src/LinqTests/Operators/single_operator.cs index a48e3b78b7..b315ddf28d 100644 --- a/src/LinqTests/Operators/single_operator.cs +++ b/src/LinqTests/Operators/single_operator.cs @@ -15,50 +15,50 @@ public class single_operator : IntegrationContext #region sample_single_and_single_or_default [Fact] - public void single_hit_with_only_one_document() + public async Task single_hit_with_only_one_document() { theSession.Store(new Target{Number = 1}); theSession.Store(new Target{Number = 2}); theSession.Store(new Target{Number = 3}); theSession.Store(new Target{Number = 4}); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); SpecificationExtensions.ShouldNotBeNull(theSession.Query().Single(x => x.Number == 3)); } [Fact] - public void single_or_default_hit_with_only_one_document() + public async Task single_or_default_hit_with_only_one_document() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); SpecificationExtensions.ShouldNotBeNull(theSession.Query().SingleOrDefault(x => x.Number == 3)); } #endregion [Fact] - public void single_or_default_miss() + public async Task single_or_default_miss() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); SpecificationExtensions.ShouldBeNull(theSession.Query().SingleOrDefault(x => x.Number == 11)); } [Fact] - public void single_hit_with_more_than_one_match() + public async Task single_hit_with_more_than_one_match() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Exception.ShouldBeThrownBy(() => { @@ -67,7 +67,7 @@ public void single_hit_with_more_than_one_match() } [Fact] - public void single_hit_with_more_than_one_match_and_take_one_should_not_throw() + public async Task single_hit_with_more_than_one_match_and_take_one_should_not_throw() { theSession.Logger = new TestOutputMartenLogger(_output); @@ -75,19 +75,19 @@ public void single_hit_with_more_than_one_match_and_take_one_should_not_throw() theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Query().Where(x => x.Number == 2).Take(1).Single().ShouldNotBeNull(); } [Fact] - public void single_or_default_hit_with_more_than_one_match() + public async Task single_or_default_hit_with_more_than_one_match() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Exception.ShouldBeThrownBy(() => { @@ -96,13 +96,13 @@ public void single_or_default_hit_with_more_than_one_match() } [Fact] - public void single_miss() + public async Task single_miss() { theSession.Store(new Target { Number = 1 }); theSession.Store(new Target { Number = 2 }); theSession.Store(new Target { Number = 3 }); theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); Exception.ShouldBeThrownBy(() => { diff --git a/src/LinqTests/using_containment_operator_in_linq_Tests.cs b/src/LinqTests/using_containment_operator_in_linq_Tests.cs index 3252a0d315..a3bb2a77f3 100644 --- a/src/LinqTests/using_containment_operator_in_linq_Tests.cs +++ b/src/LinqTests/using_containment_operator_in_linq_Tests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -15,13 +16,13 @@ public using_containment_operator_in_linq_Tests() } [Fact] - public void query_by_date() + public async Task query_by_date() { var targets = Target.GenerateRandomData(6).ToArray(); using var session = theStore.IdentitySession(); session.Store(targets); - session.SaveChanges(); + await session.SaveChangesAsync(); var actual = session.Query().Where(x => x.Date == targets.ElementAt(2).Date) .ToArray(); @@ -33,7 +34,7 @@ public void query_by_date() } [Fact] - public void query_by_number() + public async Task query_by_number() { using var session = theStore.IdentitySession(); session.Store(new Target { Number = 1 }); @@ -43,14 +44,14 @@ public void query_by_number() session.Store(new Target { Number = 5 }); session.Store(new Target { Number = 6 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.Number == 3).Single().Number.ShouldBe(3); } [Fact] - public void query_by_string() + public async Task query_by_string() { using var session = theStore.IdentitySession(); session.Store(new Target { String = "Python" }); @@ -59,7 +60,7 @@ public void query_by_string() session.Store(new Target { String = "C#" }); session.Store(new Target { String = "Scala" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.String == "Python").Single().String.ShouldBe("Python"); } @@ -78,14 +79,14 @@ public using_containment_operator_in_linq_with_camel_casing_Tests() } [Fact] - public void query_by_date() + public async Task query_by_date() { using var session = theStore.IdentitySession(); var targets = Target.GenerateRandomData(6).ToArray(); session.Store(targets); - session.SaveChanges(); + await session.SaveChangesAsync(); var actual = session.Query().Where(x => x.Date == targets.ElementAt(2).Date) .ToArray(); @@ -96,7 +97,7 @@ public void query_by_date() } [Fact] - public void query_by_number() + public async Task query_by_number() { using var session = theStore.IdentitySession(); session.Store(new Target { Number = 1 }); @@ -106,14 +107,14 @@ public void query_by_number() session.Store(new Target { Number = 5 }); session.Store(new Target { Number = 6 }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.Number == 3).Single().Number.ShouldBe(3); } [Fact] - public void query_by_string() + public async Task query_by_string() { using var session = theStore.IdentitySession(); session.Store(new Target { String = "Python" }); @@ -122,7 +123,7 @@ public void query_by_string() session.Store(new Target { String = "C#" }); session.Store(new Target { String = "Scala" }); - session.SaveChanges(); + await session.SaveChangesAsync(); session.Query().Where(x => x.String == "Python").Single().String.ShouldBe("Python"); } diff --git a/src/Marten.NodaTime.Testing/Acceptance/noda_time_acceptance.cs b/src/Marten.NodaTime.Testing/Acceptance/noda_time_acceptance.cs index c7a76e8f9f..22f148431f 100644 --- a/src/Marten.NodaTime.Testing/Acceptance/noda_time_acceptance.cs +++ b/src/Marten.NodaTime.Testing/Acceptance/noda_time_acceptance.cs @@ -86,43 +86,38 @@ public void throws_on_unsupported_serializer() [Theory] [InlineData(SerializerType.SystemTextJson)] [InlineData(SerializerType.Newtonsoft)] - public void can_insert_document(SerializerType serializerType) + public async Task can_insert_document(SerializerType serializerType) { - StoreOptions(_ => + StoreOptions(opts => { - _.UseDefaultSerialization(serializerType: serializerType); - _.UseNodaTime(); + opts.UseDefaultSerialization(serializerType: serializerType); + opts.UseNodaTime(); }); var testDoc = TargetWithDates.Generate(); - using (var session = theStore.LightweightSession()) - { - session.Insert(testDoc); - session.SaveChanges(); - } - - using (var query = theStore.QuerySession()) - { - var docFromDb = query.Query().FirstOrDefault(d => d.Id == testDoc.Id); + await using var session = theStore.LightweightSession(); + session.Insert(testDoc); + await session.SaveChangesAsync(); - docFromDb.ShouldNotBeNull(); - docFromDb.Equals(testDoc).ShouldBeTrue(); - } + await using var query = theStore.QuerySession(); + var docFromDb = query.Query().FirstOrDefault(d => d.Id == testDoc.Id); + docFromDb.ShouldNotBeNull(); + docFromDb.Equals(testDoc).ShouldBeTrue(); } [Theory] [InlineData(SerializerType.SystemTextJson)] [InlineData(SerializerType.Newtonsoft)] - public void can_query_document_with_noda_time_types(SerializerType serializerType) + public async Task can_query_document_with_noda_time_types(SerializerType serializerType) { - StoreOptions(_ => + StoreOptions(opts => { - _.UseDefaultSerialization(serializerType: serializerType); - _.UseNodaTime(); - _.DatabaseSchemaName = "NodaTime"; - _.Schema.For() + opts.UseDefaultSerialization(serializerType: serializerType); + opts.UseNodaTime(); + opts.DatabaseSchemaName = "NodaTime"; + opts.Schema.For() .Duplicate(x => x.NullableLocalDate); }, true); @@ -133,62 +128,58 @@ public void can_query_document_with_noda_time_types(SerializerType serializerTyp var instantUTC = Instant.FromDateTimeUtc(dateTime.ToUniversalTime()); var testDoc = TargetWithDates.Generate(dateTime); - using (var session = theStore.LightweightSession()) - { - session.Insert(testDoc); - session.SaveChanges(); - } + await using var session = theStore.LightweightSession(); + session.Insert(testDoc); + await session.SaveChangesAsync(); - using (var query = theStore.QuerySession()) + await using var query = theStore.QuerySession(); + var results = new List { - var results = new List - { - // LocalDate - query.Query().FirstOrDefault(d => d.LocalDate == localDateTime.Date), - query.Query().FirstOrDefault(d => d.LocalDate < localDateTime.Date.PlusDays(1)), - query.Query().FirstOrDefault(d => d.LocalDate <= localDateTime.Date.PlusDays(1)), - query.Query().FirstOrDefault(d => d.LocalDate > localDateTime.Date.PlusDays(-1)), - query.Query().FirstOrDefault(d => d.LocalDate >= localDateTime.Date.PlusDays(-1)), - - //// Nullable LocalDate - query.Query().FirstOrDefault(d => d.NullableLocalDate == localDateTime.Date), - query.Query().FirstOrDefault(d => d.NullableLocalDate < localDateTime.Date.PlusDays(1)), - query.Query().FirstOrDefault(d => d.NullableLocalDate <= localDateTime.Date.PlusDays(1)), - query.Query().FirstOrDefault(d => d.NullableLocalDate > localDateTime.Date.PlusDays(-1)), - query.Query().FirstOrDefault(d => d.NullableLocalDate >= localDateTime.Date.PlusDays(-1)), - - //// LocalDateTime - //query.Query().FirstOrDefault(d => d.LocalDateTime == localDateTime), - query.Query().FirstOrDefault(d => d.LocalDateTime < localDateTime.PlusSeconds(1)), - query.Query().FirstOrDefault(d => d.LocalDateTime <= localDateTime.PlusSeconds(1)), - query.Query().FirstOrDefault(d => d.LocalDateTime > localDateTime.PlusSeconds(-1)), - query.Query().FirstOrDefault(d => d.LocalDateTime >= localDateTime.PlusSeconds(-1)), - - //// Nullable LocalDateTime - //query.Query().FirstOrDefault(d => d.NullableLocalDateTime == localDateTime), - query.Query().FirstOrDefault(d => d.NullableLocalDateTime < localDateTime.PlusSeconds(1)), - query.Query().FirstOrDefault(d => d.NullableLocalDateTime <= localDateTime.PlusSeconds(1)), - query.Query().FirstOrDefault(d => d.NullableLocalDateTime > localDateTime.PlusSeconds(-1)), - query.Query().FirstOrDefault(d => d.NullableLocalDateTime >= localDateTime.PlusSeconds(-1)), - - //// Instant UTC - //query.Query().FirstOrDefault(d => d.InstantUTC == instantUTC), - query.Query().FirstOrDefault(d => d.InstantUTC < instantUTC.PlusTicks(1000)), - query.Query().FirstOrDefault(d => d.InstantUTC <= instantUTC.PlusTicks(1000)), - query.Query().FirstOrDefault(d => d.InstantUTC > instantUTC.PlusTicks(-1000)), - query.Query().FirstOrDefault(d => d.InstantUTC >= instantUTC.PlusTicks(-1000)), - - // Nullable Instant UTC - //query.Query().FirstOrDefault(d => d.NullableInstantUTC == instantUTC), - query.Query().FirstOrDefault(d => d.NullableInstantUTC < instantUTC.PlusTicks(1000)), - query.Query().FirstOrDefault(d => d.NullableInstantUTC <= instantUTC.PlusTicks(1000)), - query.Query().FirstOrDefault(d => d.NullableInstantUTC > instantUTC.PlusTicks(-1000)), - query.Query().FirstOrDefault(d => d.NullableInstantUTC >= instantUTC.PlusTicks(-1000)) - - }; - - results.ToArray().ShouldAllBe(x => x.Equals(testDoc)); - } + // LocalDate + query.Query().FirstOrDefault(d => d.LocalDate == localDateTime.Date), + query.Query().FirstOrDefault(d => d.LocalDate < localDateTime.Date.PlusDays(1)), + query.Query().FirstOrDefault(d => d.LocalDate <= localDateTime.Date.PlusDays(1)), + query.Query().FirstOrDefault(d => d.LocalDate > localDateTime.Date.PlusDays(-1)), + query.Query().FirstOrDefault(d => d.LocalDate >= localDateTime.Date.PlusDays(-1)), + + //// Nullable LocalDate + query.Query().FirstOrDefault(d => d.NullableLocalDate == localDateTime.Date), + query.Query().FirstOrDefault(d => d.NullableLocalDate < localDateTime.Date.PlusDays(1)), + query.Query().FirstOrDefault(d => d.NullableLocalDate <= localDateTime.Date.PlusDays(1)), + query.Query().FirstOrDefault(d => d.NullableLocalDate > localDateTime.Date.PlusDays(-1)), + query.Query().FirstOrDefault(d => d.NullableLocalDate >= localDateTime.Date.PlusDays(-1)), + + //// LocalDateTime + //query.Query().FirstOrDefault(d => d.LocalDateTime == localDateTime), + query.Query().FirstOrDefault(d => d.LocalDateTime < localDateTime.PlusSeconds(1)), + query.Query().FirstOrDefault(d => d.LocalDateTime <= localDateTime.PlusSeconds(1)), + query.Query().FirstOrDefault(d => d.LocalDateTime > localDateTime.PlusSeconds(-1)), + query.Query().FirstOrDefault(d => d.LocalDateTime >= localDateTime.PlusSeconds(-1)), + + //// Nullable LocalDateTime + //query.Query().FirstOrDefault(d => d.NullableLocalDateTime == localDateTime), + query.Query().FirstOrDefault(d => d.NullableLocalDateTime < localDateTime.PlusSeconds(1)), + query.Query().FirstOrDefault(d => d.NullableLocalDateTime <= localDateTime.PlusSeconds(1)), + query.Query().FirstOrDefault(d => d.NullableLocalDateTime > localDateTime.PlusSeconds(-1)), + query.Query().FirstOrDefault(d => d.NullableLocalDateTime >= localDateTime.PlusSeconds(-1)), + + //// Instant UTC + //query.Query().FirstOrDefault(d => d.InstantUTC == instantUTC), + query.Query().FirstOrDefault(d => d.InstantUTC < instantUTC.PlusTicks(1000)), + query.Query().FirstOrDefault(d => d.InstantUTC <= instantUTC.PlusTicks(1000)), + query.Query().FirstOrDefault(d => d.InstantUTC > instantUTC.PlusTicks(-1000)), + query.Query().FirstOrDefault(d => d.InstantUTC >= instantUTC.PlusTicks(-1000)), + + // Nullable Instant UTC + //query.Query().FirstOrDefault(d => d.NullableInstantUTC == instantUTC), + query.Query().FirstOrDefault(d => d.NullableInstantUTC < instantUTC.PlusTicks(1000)), + query.Query().FirstOrDefault(d => d.NullableInstantUTC <= instantUTC.PlusTicks(1000)), + query.Query().FirstOrDefault(d => d.NullableInstantUTC > instantUTC.PlusTicks(-1000)), + query.Query().FirstOrDefault(d => d.NullableInstantUTC >= instantUTC.PlusTicks(-1000)) + + }; + + results.ToArray().ShouldAllBe(x => x.Equals(testDoc)); } [Theory] @@ -196,10 +187,10 @@ public void can_query_document_with_noda_time_types(SerializerType serializerTyp [InlineData(SerializerType.Newtonsoft)] public async Task can_append_and_query_events(SerializerType serializerType) { - StoreOptions(_ => + StoreOptions(opts => { - _.UseDefaultSerialization(serializerType: serializerType); - _.UseNodaTime(); + opts.UseDefaultSerialization(serializerType: serializerType); + opts.UseNodaTime(); }, true); var startDate = DateTime.UtcNow; @@ -224,7 +215,7 @@ public async Task can_append_and_query_events(SerializerType serializerType) [Theory] [InlineData(SerializerType.SystemTextJson)] [InlineData(SerializerType.Newtonsoft)] - public void bug_1276_can_select_instant(SerializerType serializerType) + public async Task bug_1276_can_select_instant(SerializerType serializerType) { return; // TODO -- FIX THIS @@ -237,7 +228,7 @@ public void bug_1276_can_select_instant(SerializerType serializerType) using (var session = theStore.LightweightSession()) { session.Insert(testDoc); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/Marten.PLv8.Testing/Patching/Bug_1173_patch_typenamehandling_bug.cs b/src/Marten.PLv8.Testing/Patching/Bug_1173_patch_typenamehandling_bug.cs index ad57fb8714..1588d70bd9 100644 --- a/src/Marten.PLv8.Testing/Patching/Bug_1173_patch_typenamehandling_bug.cs +++ b/src/Marten.PLv8.Testing/Patching/Bug_1173_patch_typenamehandling_bug.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten.PLv8.Patching; using Marten.Services; using Marten.Testing.Harness; @@ -21,20 +22,21 @@ public class PatchTypeB public class Bug_1173_patch_typenamehandling_bug: BugIntegrationContext { [Fact] - public void can_support_typenamehandling() + public async Task can_support_typenamehandling() { - using var store = SeparateStore(_ => + using var store = SeparateStore(opts => { var serializer = new JsonNetSerializer(); serializer.Customize(config => { config.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects; }); - _.Serializer(serializer); - _.AutoCreateSchemaObjects = AutoCreate.All; + opts.Serializer(serializer); + opts.AutoCreateSchemaObjects = AutoCreate.All; - _.UseJavascriptTransformsAndPatching(); + opts.UseJavascriptTransformsAndPatching(); }); + using (var session = store.LightweightSession()) { var obj = new PatchTypeA @@ -48,8 +50,9 @@ public void can_support_typenamehandling() }; session.Store(obj); - session.SaveChanges(); + await session.SaveChangesAsync(); } + using (var session = store.LightweightSession()) { var newObj = new PatchTypeB @@ -58,12 +61,12 @@ public void can_support_typenamehandling() }; session.Patch("1").Set(set => set.TypeB, newObj); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession()) { - var result = session.Json.FindById("1"); + var result = await session.Json.FindByIdAsync("1"); var expected = "{\"Id\": \"1\", \"$type\": \"Marten.PLv8.Testing.Patching.PatchTypeA, Marten.PLv8.Testing\", \"TypeB\": {\"Name\": \"test2\", \"$type\": \"Marten.PLv8.Testing.Patching.PatchTypeB, Marten.PLv8.Testing\"}}"; Assert.Equal(expected, result); } diff --git a/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs b/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs index 8d7b6644b6..45ba73e829 100644 --- a/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs +++ b/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs @@ -481,23 +481,23 @@ public class ItemGroup } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_append_with_sub_types_in_collection() + public async Task can_append_with_sub_types_in_collection() { var group = new ItemGroup(); theSession.Store(group); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Patch(group.Id).Append(x => x.Items, new Item{Name = "One"}); session.Patch(group.Id).Append(x => x.Items, new ColoredItem{Name = "Two", Color = "Blue"}); session.Patch(group.Id).Append(x => x.Items, new NumberedItem(){Name = "Three", Number = 3}); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) { - var group2 = query.Load(group.Id); + var group2 = await query.LoadAsync(group.Id); group2.Items.Count.ShouldBe(3); group2.Items[0].ShouldBeOfType(); @@ -507,18 +507,18 @@ public void can_append_with_sub_types_in_collection() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_append_if_not_exists_with_sub_types_in_collection() + public async Task can_append_if_not_exists_with_sub_types_in_collection() { var group = new ItemGroup(); theSession.Store(group); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Patch(group.Id).AppendIfNotExists(x => x.Items, new Item{Name = "One"}); session.Patch(group.Id).AppendIfNotExists(x => x.Items, new ColoredItem{Name = "Two", Color = "Blue"}); session.Patch(group.Id).AppendIfNotExists(x => x.Items, new NumberedItem(){Name = "Three", Number = 3}); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -533,19 +533,19 @@ public void can_append_if_not_exists_with_sub_types_in_collection() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_insert_if_not_exists_with_sub_types_in_collection() + public async Task can_insert_if_not_exists_with_sub_types_in_collection() { var group = new ItemGroup { Items = new List{new Item{Name = "regular"}} }; theSession.Store(group); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Patch(group.Id).Insert(x => x.Items, new ColoredItem{Name = "Two", Color = "Blue"}); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -559,7 +559,7 @@ public void can_insert_if_not_exists_with_sub_types_in_collection() [Fact] - public void save_large_bundle_of_operations() + public async Task save_large_bundle_of_operations() { var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); @@ -617,24 +617,24 @@ public void save_large_bundle_of_operations() session.Patch(x => x.ObjectId == id1 && x.DefinitionId == 1) .Set(x => x.Mode, 1); - session.SaveChanges(); + await session.SaveChangesAsync(); } } #nullable enable [Fact] - public void can_patch_nullable_field() + public async Task can_patch_nullable_field() { var model = new TestModel7(); var nullModel = new TestModel7() { NullableObjectId = Guid.NewGuid()}; theSession.Store(model, nullModel); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var id = Guid.NewGuid(); using (var session = theStore.LightweightSession()) { session.Patch(model.Id).Set(x => x.NullableObjectId, id); session.Patch(nullModel.Id).Set(x => x.NullableObjectId, null); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/Marten.PLv8.Testing/Patching/multi_tenancy.cs b/src/Marten.PLv8.Testing/Patching/multi_tenancy.cs index d0422e9f51..b0795ef63e 100644 --- a/src/Marten.PLv8.Testing/Patching/multi_tenancy.cs +++ b/src/Marten.PLv8.Testing/Patching/multi_tenancy.cs @@ -25,7 +25,7 @@ public MultiTenancyFixture(): base("multi_tenancy") } [Collection("multi_tenancy")] -public class multi_tenancy: StoreContext, IClassFixture +public class multi_tenancy: StoreContext, IClassFixture, IAsyncLifetime { private readonly ITestOutputHelper _output; private readonly Target[] _greens = Target.GenerateRandomData(100).ToArray(); @@ -40,22 +40,32 @@ public class multi_tenancy: StoreContext, IClassFixture(user.Id).Set(x => x.FirstName, "John"); - green.SaveChanges(); + await green.SaveChangesAsync(); } using (var red = theStore.QuerySession("Red")) @@ -80,7 +90,7 @@ public void patching_respects_tenancy_too() } [Fact] - public void patching_respects_tenancy_too_2() + public async Task patching_respects_tenancy_too_2() { var user = new User { UserName = "Me", FirstName = "Jeremy", LastName = "Miller" }; user.Id = Guid.NewGuid(); @@ -88,13 +98,13 @@ public void patching_respects_tenancy_too_2() using (var red = theStore.LightweightSession("Red")) { red.Store(user); - red.SaveChanges(); + await red.SaveChangesAsync(); } using (var green = theStore.LightweightSession("Green")) { green.Patch(x => x.UserName == "Me").Set(x => x.FirstName, "John"); - green.SaveChanges(); + await green.SaveChangesAsync(); } using (var red = theStore.QuerySession("Red")) diff --git a/src/Marten.PLv8.Testing/Patching/patching_api.cs b/src/Marten.PLv8.Testing/Patching/patching_api.cs index f6cc68de96..ae96584f41 100644 --- a/src/Marten.PLv8.Testing/Patching/patching_api.cs +++ b/src/Marten.PLv8.Testing/Patching/patching_api.cs @@ -57,16 +57,16 @@ public async Task can_use_patch_api_when_autocreate_is_none() #region sample_plv8_set_an_immediate_property_by_id [Fact] - public void set_an_immediate_property_by_id() + public async Task set_an_immediate_property_by_id() { var target = Target.Random(true); target.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Set(x => x.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -77,16 +77,16 @@ public void set_an_immediate_property_by_id() #endregion [Fact] - public void initialise_a_new_property_by_expression() + public async Task initialise_a_new_property_by_expression() { theSession.Store(Target.Random(), Target.Random(), Target.Random()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_initialise_a_new_property_by_expression const string where = "(data ->> 'UpdatedAt') is null"; theSession.Query(where).Count.ShouldBe(3); theSession.Patch(new WhereFragment(where)).Set("UpdatedAt", DateTime.UtcNow); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -96,16 +96,16 @@ public void initialise_a_new_property_by_expression() } [Fact] - public void set_a_deep_property_by_id() + public async Task set_a_deep_property_by_id() { var target = Target.Random(true); target.Inner.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Set(x => x.Inner.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -114,7 +114,7 @@ public void set_a_deep_property_by_id() } [Fact] - public void set_an_immediate_property_by_where_clause() + public async Task set_an_immediate_property_by_where_clause() { var target1 = new Target { Color = Colors.Blue, Number = 1 }; var target2 = new Target { Color = Colors.Blue, Number = 1 }; @@ -124,14 +124,14 @@ public void set_an_immediate_property_by_where_clause() var target6 = new Target { Color = Colors.Red, Number = 1 }; theSession.Store(target1, target2, target3, target4, target5, target6); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_set_an_immediate_property_by_where_clause // Change every Target document where the Color is Blue theSession.Patch(x => x.Color == Colors.Blue).Set(x => x.Number, 2); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -148,16 +148,16 @@ public void set_an_immediate_property_by_where_clause() } [Fact] - public void duplicate_to_new_field() + public async Task duplicate_to_new_field() { #region sample_plv8_duplicate_to_new_field var target = Target.Random(); target.AnotherString = null; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Duplicate(t => t.String, t => t.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -168,13 +168,13 @@ public void duplicate_to_new_field() } [Fact] - public void duplicate_to_multiple_new_fields() + public async Task duplicate_to_multiple_new_fields() { var target = Target.Random(); target.StringField = null; target.Inner = null; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_duplicate_to_multiple_new_fields theSession.Patch(target.Id).Duplicate(t => t.String, @@ -182,7 +182,7 @@ public void duplicate_to_multiple_new_fields() t => t.Inner.String, t => t.Inner.AnotherString); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -197,16 +197,16 @@ public void duplicate_to_multiple_new_fields() #region sample_plv8_increment_for_int [Fact] - public void increment_for_int() + public async Task increment_for_int() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -218,16 +218,16 @@ public void increment_for_int() #region sample_plv8_increment_for_int_with_explicit_increment [Fact] - public void increment_for_int_with_explicit_increment() + public async Task increment_for_int_with_explicit_increment() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number, 3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -238,16 +238,16 @@ public void increment_for_int_with_explicit_increment() #endregion [Fact] - public void increment_for_long() + public async Task increment_for_long() { var target = Target.Random(); target.Long = 13; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Long); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -256,16 +256,16 @@ public void increment_for_long() } [Fact] - public void increment_for_double() + public async Task increment_for_double() { var target = Target.Random(); target.Double = 11.2; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Double, 2.4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -274,16 +274,16 @@ public void increment_for_double() } [Fact] - public void increment_for_float() + public async Task increment_for_float() { var target = Target.Random(); target.Float = 11.2F; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Float, 2.4F); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -292,16 +292,16 @@ public void increment_for_float() } [Fact] - public void append_to_a_primitive_array() + public async Task append_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -311,16 +311,16 @@ public void append_to_a_primitive_array() } [Fact] - public void append_if_not_exists_to_a_primitive_array() + public async Task append_if_not_exists_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).AppendIfNotExists(x => x.NumberArray, 3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -329,7 +329,7 @@ public void append_if_not_exists_to_a_primitive_array() } theSession.Patch(target.Id).AppendIfNotExists(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -340,7 +340,7 @@ public void append_if_not_exists_to_a_primitive_array() #region sample_plv8_append_complex_element [Fact] - public void append_complex_element() + public async Task append_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -348,10 +348,10 @@ public void append_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -365,7 +365,7 @@ public void append_complex_element() #endregion [Fact] - public void append_if_not_exists_complex_element() + public async Task append_if_not_exists_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -374,11 +374,11 @@ public void append_if_not_exists_complex_element() var child2 = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).AppendIfNotExists(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -389,7 +389,7 @@ public void append_if_not_exists_complex_element() } theSession.Patch(target.Id).AppendIfNotExists(x => x.Children, child2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -401,16 +401,16 @@ public void append_if_not_exists_complex_element() } [Fact] - public void insert_first_to_a_primitive_array() + public async Task insert_first_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -420,16 +420,16 @@ public void insert_first_to_a_primitive_array() } [Fact] - public void insert_if_not_exists_first_to_a_primitive_array() + public async Task insert_if_not_exists_first_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -438,7 +438,7 @@ public void insert_if_not_exists_first_to_a_primitive_array() } theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -448,16 +448,16 @@ public void insert_if_not_exists_first_to_a_primitive_array() } [Fact] - public void insert_first_to_a_primitive_array_at_a_certain_position() + public async Task insert_first_to_a_primitive_array_at_a_certain_position() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.NumberArray, 4, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -467,16 +467,16 @@ public void insert_first_to_a_primitive_array_at_a_certain_position() } [Fact] - public void insert_if_not_exists_first_to_a_primitive_array_at_a_certain_position() + public async Task insert_if_not_exists_first_to_a_primitive_array_at_a_certain_position() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 3, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -485,7 +485,7 @@ public void insert_if_not_exists_first_to_a_primitive_array_at_a_certain_positio } theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 4, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -496,7 +496,7 @@ public void insert_if_not_exists_first_to_a_primitive_array_at_a_certain_positio #region sample_plv8_insert_first_complex_element [Fact] - public void insert_first_complex_element() + public async Task insert_first_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -504,10 +504,10 @@ public void insert_first_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -521,7 +521,7 @@ public void insert_first_complex_element() #endregion [Fact] - public void insert_if_not_exists_first_complex_element() + public async Task insert_if_not_exists_first_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -529,10 +529,10 @@ public void insert_if_not_exists_first_complex_element() var child = Target.Random(); var child2 = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -543,7 +543,7 @@ public void insert_if_not_exists_first_complex_element() } theSession.Patch(target.Id).InsertIfNotExists(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -554,7 +554,7 @@ public void insert_if_not_exists_first_complex_element() } theSession.Patch(target.Id).InsertIfNotExists(x => x.Children, child2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -566,17 +566,17 @@ public void insert_if_not_exists_first_complex_element() } [Fact] - public void rename_shallow_prop() + public async Task rename_shallow_prop() { var target = Target.Random(true); target.String = "Foo"; target.AnotherString = "Bar"; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Rename("String", x => x.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -588,17 +588,17 @@ public void rename_shallow_prop() #region sample_plv8_rename_deep_prop [Fact] - public void rename_deep_prop() + public async Task rename_deep_prop() { var target = Target.Random(true); target.Inner.String = "Foo"; target.Inner.AnotherString = "Bar"; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Rename("String", x => x.Inner.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -612,7 +612,7 @@ public void rename_deep_prop() #region sample_plv8_remove_primitive_element [Fact] - public void remove_primitive_element() + public async Task remove_primitive_element() { var target = Target.Random(); target.NumberArray = new[] { Random.Shared.Next(0, 10), Random.Shared.Next(0, 10), Random.Shared.Next(0, 10) }; @@ -624,10 +624,10 @@ public void remove_primitive_element() var child = target.NumberArray[Random.Shared.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -642,7 +642,7 @@ public void remove_primitive_element() #region sample_plv8_remove_repeated_primitive_element [Fact] - public void remove_repeated_primitive_elements() + public async Task remove_repeated_primitive_elements() { var random = new Random(); var target = Target.Random(); @@ -662,10 +662,10 @@ public void remove_repeated_primitive_elements() } theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child, RemoveAction.RemoveAll); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -680,7 +680,7 @@ public void remove_repeated_primitive_elements() #region sample_plv8_remove_complex_element [Fact] - public void remove_complex_element() + public async Task remove_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -689,10 +689,10 @@ public void remove_complex_element() var child = target.Children[random.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -706,16 +706,16 @@ public void remove_complex_element() #endregion [Fact] - public void delete_redundant_property() + public async Task delete_redundant_property() { var target = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_delete_redundant_property theSession.Patch(target.Id).Delete("String"); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -726,16 +726,16 @@ public void delete_redundant_property() } [Fact] - public void delete_redundant_nested_property() + public async Task delete_redundant_nested_property() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_delete_redundant_nested_property theSession.Patch(target.Id).Delete("String", t => t.Inner); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -746,16 +746,16 @@ public void delete_redundant_nested_property() } [Fact] - public void delete_existing_property() + public async Task delete_existing_property() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_delete_existing_property theSession.Patch(target.Id).Delete(t => t.Inner); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -766,19 +766,19 @@ public void delete_existing_property() } [Fact] - public void delete_property_from_many_documents() + public async Task delete_property_from_many_documents() { for (var i = 0; i < 15; i++) { theSession.Store(Target.Random()); } - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_plv8_delete_property_from_many_documents const string where = "(data ->> 'String') is not null"; theSession.Query(where).Count.ShouldBe(15); theSession.Patch(new WhereFragment(where)).Delete("String"); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -832,7 +832,7 @@ public async Task bug_611_duplicate_field_is_updated_by_set_operation_with_multi count.ShouldBe(1); } - public void SampleSetup() + public async Task SampleSetup() { #region sample_plv8_registering_custom_projection diff --git a/src/Marten.PLv8.Testing/Transforms/document_transforms.cs b/src/Marten.PLv8.Testing/Transforms/document_transforms.cs index dd71c24eab..5f9980e307 100644 --- a/src/Marten.PLv8.Testing/Transforms/document_transforms.cs +++ b/src/Marten.PLv8.Testing/Transforms/document_transforms.cs @@ -112,18 +112,18 @@ public void transform_all_documents() } [Fact] - public void transform_all_documents_in_session() + public async Task transform_all_documents_in_session() { var user1 = new User { FirstName = "Jeremy", LastName = "Miller" }; var user2 = new User { FirstName = "Corey", LastName = "Kaylor" }; var user3 = new User { FirstName = "Tim", LastName = "Cools" }; - theStore.BulkInsert(new User[] { user1, user2, user3 }); + await theStore.BulkInsertAsync(new User[] { user1, user2, user3 }); using (var session = theStore.LightweightSession()) { session.Transform(x => x.All("default_username")); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.LightweightSession()) @@ -180,18 +180,18 @@ public void transform_a_single_document() } [Fact] - public void transform_a_single_document_in_session() + public async Task transform_a_single_document_in_session() { var user1 = new User { FirstName = "Jeremy", LastName = "Miller" }; var user2 = new User { FirstName = "Corey", LastName = "Kaylor", UserName = "user2" }; var user3 = new User { FirstName = "Tim", LastName = "Cools", UserName = "user3" }; - theStore.BulkInsert(new[] { user1, user2, user3 }); + await theStore.BulkInsertAsync(new[] { user1, user2, user3 }); using (var session = theStore.LightweightSession()) { session.Transform(x => x.Document("default_username", user1.Id)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) @@ -226,18 +226,18 @@ public void transform_with_where_clause() } [Fact] - public void transform_with_where_clause_in_session() + public async Task transform_with_where_clause_in_session() { var user1 = new User { FirstName = "Jeremy", LastName = "Miller" }; var user2 = new User { FirstName = "Corey", LastName = "Kaylor", UserName = "user2" }; var user3 = new User { FirstName = "Tim", LastName = "Cools", UserName = "user3" }; - theStore.BulkInsert(new User[] { user1, user2, user3 }); + await theStore.BulkInsertAsync(new User[] { user1, user2, user3 }); using (var session = theStore.LightweightSession()) { session.Transform(x => x.Where("default_username", x => x.FirstName == user1.FirstName)); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) diff --git a/src/Marten.PLv8.Testing/Transforms/select_with_transformation.cs b/src/Marten.PLv8.Testing/Transforms/select_with_transformation.cs index 6323e94c11..8211a3fd87 100644 --- a/src/Marten.PLv8.Testing/Transforms/select_with_transformation.cs +++ b/src/Marten.PLv8.Testing/Transforms/select_with_transformation.cs @@ -16,9 +16,9 @@ public class select_with_transformation: OneOffConfigurationsContext { public select_with_transformation() { - StoreOptions(_ => + StoreOptions(opts => { - _.UseJavascriptTransformsAndPatching(x => x.LoadFile("get_fullname.js")); + opts.UseJavascriptTransformsAndPatching(x => x.LoadFile("get_fullname.js")); }); } @@ -26,13 +26,13 @@ public select_with_transformation() #region sample_using_transform_to_json [Fact] - public void can_select_a_string_field_in_compiled_query() + public async Task can_select_a_string_field_in_compiled_query() { var user = new User { FirstName = "Eric", LastName = "Berry" }; using var session = theStore.LightweightSession(); session.Store(user); - session.SaveChanges(); + await session.SaveChangesAsync(); var name = session.Query().Select(x => x.FirstName) .Single(); diff --git a/src/Marten.PLv8/StoreOptionsExtensions.cs b/src/Marten.PLv8/StoreOptionsExtensions.cs index 6b0a6fe941..c5ec3584b7 100644 --- a/src/Marten.PLv8/StoreOptionsExtensions.cs +++ b/src/Marten.PLv8/StoreOptionsExtensions.cs @@ -36,6 +36,7 @@ public static void UseJavascriptTransformsAndPatching( /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] public static void Transform(this IDocumentStore store, Action apply) { var s = store.As(); @@ -58,6 +59,7 @@ public static void Transform(this IDocumentStore store, Action /// /// + [Obsolete(QuerySession.SynchronousRemoval)] public static void Transform(this IDocumentOperations operations, Action apply) { var session = operations.As(); @@ -97,6 +99,7 @@ public static async Task TransformAsync(this IDocumentStore store, Action /// /// + [Obsolete(QuerySession.SynchronousRemoval)] public static void Transform(this IDocumentStore store, string tenantId, Action apply) { var s = store.As(); diff --git a/src/Marten.Testing/Examples/Deletes.cs b/src/Marten.Testing/Examples/Deletes.cs index 7a249af5e3..7d15418209 100644 --- a/src/Marten.Testing/Examples/Deletes.cs +++ b/src/Marten.Testing/Examples/Deletes.cs @@ -77,18 +77,18 @@ public Task DeleteByDocument(IDocumentSession session, User user) #endregion #region sample_deletes - public void delete_documents(IDocumentSession session) + public async Task delete_documents(IDocumentSession session) { var user = new User(); session.Delete(user); - session.SaveChanges(); + await session.SaveChangesAsync(); // OR session.Delete(user.Id); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion -} \ No newline at end of file +} diff --git a/src/Marten.Testing/Examples/MultiTenancy.cs b/src/Marten.Testing/Examples/MultiTenancy.cs index abfaab07b0..34fb91d7b3 100644 --- a/src/Marten.Testing/Examples/MultiTenancy.cs +++ b/src/Marten.Testing/Examples/MultiTenancy.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; using Xunit; @@ -28,7 +29,7 @@ public static void configuring_tenant_id_rules() } [Fact] - public void use_multiple_tenants() + public async Task use_multiple_tenants() { // Set up a basic DocumentStore with multi-tenancy // via a tenant_id column @@ -59,7 +60,7 @@ public void use_multiple_tenants() { session.Store(new User { UserName = "Bill" }); session.Store(new User { UserName = "Lindsey" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion @@ -69,7 +70,7 @@ public void use_multiple_tenants() { session.Store(new User { UserName = "Jill" }); session.Store(new User { UserName = "Frank" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } #region sample_tenancy-scoping-session-read @@ -96,7 +97,7 @@ public void use_multiple_tenants() } [Fact] - public void use_multiple_tenants_with_partitioning() + public async Task use_multiple_tenants_with_partitioning() { // Set up a basic DocumentStore with multi-tenancy // via a tenant_id column @@ -152,7 +153,7 @@ public void use_multiple_tenants_with_partitioning() { session.Store(new User { UserName = "Bill" }); session.Store(new User { UserName = "Lindsey" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } #endregion @@ -162,7 +163,7 @@ public void use_multiple_tenants_with_partitioning() { session.Store(new User { UserName = "Jill" }); session.Store(new User { UserName = "Frank" }); - session.SaveChanges(); + await session.SaveChangesAsync(); } #region sample_tenancy-scoping-session-read_with_partitioning diff --git a/src/Marten.Testing/Examples/OnePointOneNotes.cs b/src/Marten.Testing/Examples/OnePointOneNotes.cs deleted file mode 100644 index e5e77f0e9d..0000000000 --- a/src/Marten.Testing/Examples/OnePointOneNotes.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Linq; -using JasperFx.CodeGeneration.Util; -using Marten.Testing.Documents; - -namespace Marten.Testing.Examples; - -public class OnePointOneNotes -{ - public void use_distinct(IQuerySession session) - { - var surnames = session - .Query() - .Select(x => x.LastName) - .Distinct(); - } - - public void lazy_tx(IDocumentSession session) - { - // Executing this query will *not* start - // a new transaction - var users = session - .Query() - .Where(x => x.Internal) - .ToList(); - - session.Store(new User { UserName = "lebron" }); - - // This starts a transaction against the open - // connection before doing any writes - session.SaveChanges(); - } - - public void reset_hilo(IDocumentStore store) - { - // This resets the Hilo state in the database so that - // all id's assigned will be greater than the floor - // value. - store.Advanced.ResetHiloSequenceFloor(3000); - } - - public void bulk_inserts(IDocumentStore store, Target[] documents) - { - store.BulkInsert(documents, BulkInsertMode.IgnoreDuplicates); - - // or - - store.BulkInsert(documents, BulkInsertMode.OverwriteExisting); - } -} diff --git a/src/Marten.Testing/Examples/Setting_Timestamp_on_all_changes_by_base_class_Tests.cs b/src/Marten.Testing/Examples/Setting_Timestamp_on_all_changes_by_base_class_Tests.cs index 979c866341..5d1d4d0045 100644 --- a/src/Marten.Testing/Examples/Setting_Timestamp_on_all_changes_by_base_class_Tests.cs +++ b/src/Marten.Testing/Examples/Setting_Timestamp_on_all_changes_by_base_class_Tests.cs @@ -12,7 +12,7 @@ namespace Marten.Testing.Examples; public class Setting_Timestamp_on_all_changes_by_base_class_Tests { [Fact] - public void demonstration() + public async Task demonstration() { using (var store = DocumentStore.For(_ => { @@ -32,7 +32,7 @@ public void demonstration() session.Store(doc2s); session.Store(doc3s); - session.SaveChanges(); + await session.SaveChangesAsync(); } doc1s.Each(x => x.Timestamp.ShouldNotBeNull()); diff --git a/src/Marten.Testing/Examples/UnitOfWorkBlogSamples.cs b/src/Marten.Testing/Examples/UnitOfWorkBlogSamples.cs index 51afc07736..1ce622f3eb 100644 --- a/src/Marten.Testing/Examples/UnitOfWorkBlogSamples.cs +++ b/src/Marten.Testing/Examples/UnitOfWorkBlogSamples.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading.Tasks; using JasperFx.Core; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -13,7 +14,7 @@ namespace Marten.Testing.Examples; public class UnitOfWorkBlogSamples: IntegrationContext { [Fact] - public void show_unit_of_work() + public async Task show_unit_of_work() { // theStore is a DocumentStore using var session = theStore.LightweightSession(); @@ -35,7 +36,7 @@ public void show_unit_of_work() session.Delete(Guid.NewGuid()); // Persist in a single transaction - session.SaveChanges(); + await session.SaveChangesAsync(); // All of this was done in one batched command // in the same transaction diff --git a/src/Marten.Testing/Harness/SpecificationExtensions.cs b/src/Marten.Testing/Harness/SpecificationExtensions.cs index 839db96c1f..476aea1039 100644 --- a/src/Marten.Testing/Harness/SpecificationExtensions.cs +++ b/src/Marten.Testing/Harness/SpecificationExtensions.cs @@ -15,7 +15,7 @@ namespace Marten.Testing.Harness { - + [Obsolete("Use Shouldly instead. Just no reason to have this any longer")] public static class Exception where T : Exception { diff --git a/src/Marten/DocumentStore.cs b/src/Marten/DocumentStore.cs index cf54a4c6f1..d574c4e2b0 100644 --- a/src/Marten/DocumentStore.cs +++ b/src/Marten/DocumentStore.cs @@ -113,6 +113,7 @@ public ValueTask DisposeAsync() public AdvancedOperations Advanced { get; } + [Obsolete(Marten.Internal.Sessions.QuerySession.SynchronousRemoval)] public void BulkInsert(IReadOnlyCollection documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000) { @@ -120,6 +121,7 @@ public void BulkInsert(IReadOnlyCollection documents, BulkInsertMode mode bulkInsertion.BulkInsert(documents, mode, batchSize); } + [Obsolete(Marten.Internal.Sessions.QuerySession.SynchronousRemoval)] public void BulkInsertEnlistTransaction(IReadOnlyCollection documents, Transaction transaction, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000) @@ -128,6 +130,7 @@ public void BulkInsertEnlistTransaction(IReadOnlyCollection documents, bulkInsertion.BulkInsertEnlistTransaction(documents, transaction, mode, batchSize); } + [Obsolete(Marten.Internal.Sessions.QuerySession.SynchronousRemoval)] public void BulkInsertDocuments(IEnumerable documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000) { @@ -135,6 +138,7 @@ public void BulkInsertDocuments(IEnumerable documents, BulkInsertMode mo bulkInsertion.BulkInsertDocuments(documents, mode, batchSize); } + [Obsolete(Marten.Internal.Sessions.QuerySession.SynchronousRemoval)] public void BulkInsert(string tenantId, IReadOnlyCollection documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000) @@ -143,6 +147,7 @@ public void BulkInsert(string tenantId, IReadOnlyCollection documents, bulkInsertion.BulkInsert(documents, mode, batchSize); } + [Obsolete(Marten.Internal.Sessions.QuerySession.SynchronousRemoval)] public void BulkInsertDocuments(string tenantId, IEnumerable documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000) diff --git a/src/Marten/Events/IQueryEventStore.cs b/src/Marten/Events/IQueryEventStore.cs index 137bcd7edb..aab3771c8e 100644 --- a/src/Marten/Events/IQueryEventStore.cs +++ b/src/Marten/Events/IQueryEventStore.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Marten.Internal.Sessions; using Marten.Linq; namespace Marten.Events; @@ -18,6 +19,7 @@ public interface IQueryEventStore /// If set, queries for events captured on or before this timestamp /// If set, queries for events on or from this version /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList FetchStream(Guid streamId, long version = 0, DateTimeOffset? timestamp = null, long fromVersion = 0); @@ -40,6 +42,7 @@ Task> FetchStreamAsync(Guid streamId, long version = 0, Da /// If set, queries for events up to and including this version /// If set, queries for events captured on or before this timestamp /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList FetchStream(string streamKey, long version = 0, DateTimeOffset? timestamp = null, long fromVersion = 0); @@ -52,6 +55,7 @@ IReadOnlyList FetchStream(string streamKey, long version = 0, DateTimeOf /// If set, queries for events on or from this version /// /// + [Obsolete(QuerySession.SynchronousRemoval)] Task> FetchStreamAsync(string streamKey, long version = 0, DateTimeOffset? timestamp = null, long fromVersion = 0, CancellationToken token = default); @@ -65,6 +69,7 @@ Task> FetchStreamAsync(string streamKey, long version = 0, /// If set, queries for events on or from this version /// Instance of T to apply events to /// + [Obsolete(QuerySession.SynchronousRemoval)] T? AggregateStream(Guid streamId, long version = 0, DateTimeOffset? timestamp = null, T? state = null, long fromVersion = 0) where T : class; @@ -91,6 +96,7 @@ Task> FetchStreamAsync(string streamKey, long version = 0, /// /// Instance of T to apply events to /// + [Obsolete(QuerySession.SynchronousRemoval)] T? AggregateStream(string streamKey, long version = 0, DateTimeOffset? timestamp = null, T? state = null, long fromVersion = 0) where T : class; @@ -127,6 +133,7 @@ Task> FetchStreamAsync(string streamKey, long version = 0, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IEvent? Load(Guid id) where T : class; /// @@ -143,6 +150,7 @@ Task> FetchStreamAsync(string streamKey, long version = 0, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IEvent? Load(Guid id); /// @@ -158,6 +166,7 @@ Task> FetchStreamAsync(string streamKey, long version = 0, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] StreamState? FetchStreamState(Guid streamId); /// @@ -173,6 +182,7 @@ Task> FetchStreamAsync(string streamKey, long version = 0, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] StreamState? FetchStreamState(string streamKey); /// diff --git a/src/Marten/IDocumentSession.cs b/src/Marten/IDocumentSession.cs index c0840e669c..b324137ae4 100644 --- a/src/Marten/IDocumentSession.cs +++ b/src/Marten/IDocumentSession.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Marten.Events; +using Marten.Internal.Sessions; using Marten.Services; namespace Marten; @@ -56,6 +57,7 @@ public interface IDocumentSession: IDocumentOperations /// /// Saves all the pending changes and deletions to the server in a single Postgresql transaction. /// + [Obsolete(QuerySession.SynchronousRemoval)] void SaveChanges(); /// diff --git a/src/Marten/IJsonLoader.cs b/src/Marten/IJsonLoader.cs index 19792f4c2f..4b8d9c0985 100644 --- a/src/Marten/IJsonLoader.cs +++ b/src/Marten/IJsonLoader.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; +using Marten.Internal.Sessions; namespace Marten; @@ -14,6 +15,7 @@ public interface IJsonLoader /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] string? FindById(string id) where T : class; /// @@ -22,6 +24,7 @@ public interface IJsonLoader /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] string? FindById(int id) where T : class; /// @@ -30,6 +33,7 @@ public interface IJsonLoader /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] string? FindById(long id) where T : class; /// @@ -38,6 +42,7 @@ public interface IJsonLoader /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] string? FindById(Guid id) where T : class; /// diff --git a/src/Marten/IQuerySession.cs b/src/Marten/IQuerySession.cs index 4bf91ce769..2275c96af1 100644 --- a/src/Marten/IQuerySession.cs +++ b/src/Marten/IQuerySession.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Marten.Events; +using Marten.Internal.Sessions; using Marten.Linq; using Marten.Schema; using Marten.Services.BatchQuerying; @@ -77,6 +78,7 @@ public interface IQuerySession: IDisposable, IAsyncDisposable /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] T? Load(string id) where T : notnull; /// @@ -103,6 +105,7 @@ public interface IQuerySession: IDisposable, IAsyncDisposable /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] T? Load(int id) where T : notnull; /// @@ -111,6 +114,7 @@ public interface IQuerySession: IDisposable, IAsyncDisposable /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] T? Load(long id) where T : notnull; /// @@ -119,6 +123,7 @@ public interface IQuerySession: IDisposable, IAsyncDisposable /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] T? Load(Guid id) where T : notnull; /// @@ -320,6 +325,7 @@ public interface IQuerySession: IDisposable, IAsyncDisposable /// The output /// The instance of a compiled query /// A single item query result + [Obsolete(QuerySession.SynchronousRemoval)] TOut Query(ICompiledQuery query); /// @@ -381,6 +387,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(params string[] ids) where T : notnull; /// @@ -388,6 +395,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(IEnumerable ids) where T : notnull; /// @@ -395,6 +403,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(params Guid[] ids) where T : notnull; /// @@ -402,6 +411,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(IEnumerable ids) where T : notnull; /// @@ -409,6 +419,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(params int[] ids) where T : notnull; /// @@ -416,6 +427,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(IEnumerable ids) where T : notnull; /// @@ -423,6 +435,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(params long[] ids) where T : notnull; /// @@ -430,6 +443,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList LoadMany(IEnumerable ids) where T : notnull; /// @@ -564,6 +578,7 @@ Task StreamJsonMany(ICompiledQuery query, Stream de /// /// See: https://www.postgresql.org/docs/10/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// + [Obsolete(QuerySession.SynchronousRemoval)] IReadOnlyList Search(string queryText, string regConfig = FullTextIndexDefinition.DefaultRegConfig); /// @@ -682,6 +697,7 @@ Task> WebStyleSearchAsync(string searchTerm, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] DocumentMetadata? MetadataFor(T entity) where T : notnull; /// @@ -706,6 +722,7 @@ Task MetadataForAsync(T entity, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] int Execute(NpgsqlCommand cmd); /// @@ -721,6 +738,7 @@ Task MetadataForAsync(T entity, /// /// /// + [Obsolete(QuerySession.SynchronousRemoval)] DbDataReader ExecuteReader(NpgsqlCommand command); /// diff --git a/src/Marten/Internal/Sessions/QuerySession.Execution.cs b/src/Marten/Internal/Sessions/QuerySession.Execution.cs index 9cdd9d447b..60579f0988 100644 --- a/src/Marten/Internal/Sessions/QuerySession.Execution.cs +++ b/src/Marten/Internal/Sessions/QuerySession.Execution.cs @@ -100,6 +100,7 @@ public async Task ExecuteHandlerAsync(IQueryHandler handler, Cancellati return await handler.HandleAsync(reader, this, token).ConfigureAwait(false); } + [Obsolete(QuerySession.SynchronousRemoval)] public T ExecuteHandler(IQueryHandler handler) { var batch = this.BuildCommand(handler); diff --git a/src/Marten/Internal/Sessions/QuerySession.cs b/src/Marten/Internal/Sessions/QuerySession.cs index b6308216f5..c0036a039b 100644 --- a/src/Marten/Internal/Sessions/QuerySession.cs +++ b/src/Marten/Internal/Sessions/QuerySession.cs @@ -14,6 +14,9 @@ namespace Marten.Internal.Sessions; public partial class QuerySession: IMartenSession, IQuerySession { + public const string SynchronousRemoval = + "All synchronous APIs that result in database calls will be removed in Marten 8.0. Please use the asynchronous equivalent"; + private readonly DocumentStore _store; private readonly ResiliencePipeline _resilience; diff --git a/src/Marten/Internal/Storage/IDocumentStorage.cs b/src/Marten/Internal/Storage/IDocumentStorage.cs index eae40bd0d4..b4cecc7242 100644 --- a/src/Marten/Internal/Storage/IDocumentStorage.cs +++ b/src/Marten/Internal/Storage/IDocumentStorage.cs @@ -145,6 +145,7 @@ public interface IDocumentStorage: IDocumentStorage where T : notnull IDeletion DeleteForId(TId id, string tenantId); + [Obsolete(QuerySession.SynchronousRemoval)] T? Load(TId id, IMartenSession session); Task LoadAsync(TId id, IMartenSession session, CancellationToken token); diff --git a/src/Marten/Linq/MartenLinqQueryProvider.cs b/src/Marten/Linq/MartenLinqQueryProvider.cs index 8e1a9fef48..cedbd42b83 100644 --- a/src/Marten/Linq/MartenLinqQueryProvider.cs +++ b/src/Marten/Linq/MartenLinqQueryProvider.cs @@ -134,6 +134,7 @@ public async Task StreamJson(Stream stream, Expression expression, return default; } + [Obsolete(QuerySession.SynchronousRemoval)] public T? ExecuteHandler(IQueryHandler handler) { try diff --git a/src/Marten/Linq/MartenLinqQueryable.cs b/src/Marten/Linq/MartenLinqQueryable.cs index bb2328e623..6699c32853 100644 --- a/src/Marten/Linq/MartenLinqQueryable.cs +++ b/src/Marten/Linq/MartenLinqQueryable.cs @@ -214,6 +214,7 @@ public Task AverageAsync(CancellationToken token) return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Average); } + [Obsolete(QuerySession.SynchronousRemoval)] public QueryPlan Explain(FetchType fetchType = FetchType.FetchMany, Action? configureExplain = null) { diff --git a/src/Marten/Linq/QueryHandlers/IQueryHandler.cs b/src/Marten/Linq/QueryHandlers/IQueryHandler.cs index edcfb51588..8071fe7375 100644 --- a/src/Marten/Linq/QueryHandlers/IQueryHandler.cs +++ b/src/Marten/Linq/QueryHandlers/IQueryHandler.cs @@ -1,9 +1,11 @@ #nullable enable +using System; using System.Data.Common; using System.IO; using System.Threading; using System.Threading.Tasks; using Marten.Internal; +using Marten.Internal.Sessions; using Weasel.Postgresql; namespace Marten.Linq.QueryHandlers; @@ -15,6 +17,7 @@ public interface IQueryHandler public interface IQueryHandler: IQueryHandler { + [Obsolete(QuerySession.SynchronousRemoval)] T Handle(DbDataReader reader, IMartenSession session); Task HandleAsync(DbDataReader reader, IMartenSession session, CancellationToken token); diff --git a/src/Marten/QueryableExtensions.cs b/src/Marten/QueryableExtensions.cs index 698e319c60..1fada17556 100644 --- a/src/Marten/QueryableExtensions.cs +++ b/src/Marten/QueryableExtensions.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using JasperFx.Core.Reflection; +using Marten.Internal.Sessions; using Marten.Linq; using Marten.Linq.Includes; using Marten.Services.BatchQuerying; diff --git a/src/Marten/Services/BatchQuerying/BatchQueryItem.cs b/src/Marten/Services/BatchQuerying/BatchQueryItem.cs index 46f7ecd519..e7daf3c796 100644 --- a/src/Marten/Services/BatchQuerying/BatchQueryItem.cs +++ b/src/Marten/Services/BatchQuerying/BatchQueryItem.cs @@ -1,8 +1,10 @@ #nullable enable +using System; using System.Data.Common; using System.Threading; using System.Threading.Tasks; using Marten.Internal; +using Marten.Internal.Sessions; using Marten.Linq.QueryHandlers; namespace Marten.Services.BatchQuerying; @@ -29,7 +31,8 @@ public async Task ReadAsync(DbDataReader reader, IMartenSession session, Cancell var result = await _handler.HandleAsync(reader, session, token).ConfigureAwait(false); Completion.SetResult(result); } - + + [Obsolete(QuerySession.SynchronousRemoval)] public void Read(DbDataReader reader, IMartenSession session) { var result = _handler.Handle(reader, session); diff --git a/src/PatchingTests/Patching/Bug_1173_patch_typenamehandling_bug.cs b/src/PatchingTests/Patching/Bug_1173_patch_typenamehandling_bug.cs index 7d799fbf36..647558e710 100644 --- a/src/PatchingTests/Patching/Bug_1173_patch_typenamehandling_bug.cs +++ b/src/PatchingTests/Patching/Bug_1173_patch_typenamehandling_bug.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Marten.Patching; using Marten.Services; using Marten.Testing.Harness; @@ -20,7 +21,7 @@ public class PatchTypeB public class Bug_1173_patch_typenamehandling_bug: BugIntegrationContext { [Fact] - public void can_support_typenamehandling() + public async Task can_support_typenamehandling() { using var store = SeparateStore(_ => { @@ -48,7 +49,7 @@ public void can_support_typenamehandling() }; session.Store(obj); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession()) { @@ -58,7 +59,7 @@ public void can_support_typenamehandling() }; session.Patch("1").Set(set => set.TypeB, newObj); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = store.LightweightSession()) diff --git a/src/PatchingTests/Patching/PatchExpressionTests.cs b/src/PatchingTests/Patching/PatchExpressionTests.cs index 18f4a215f4..052cfc2745 100644 --- a/src/PatchingTests/Patching/PatchExpressionTests.cs +++ b/src/PatchingTests/Patching/PatchExpressionTests.cs @@ -497,18 +497,18 @@ public class ItemGroup } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_append_with_sub_types_in_collection() + public async Task can_append_with_sub_types_in_collection() { var group = new ItemGroup(); theSession.Store(group); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Patch(group.Id).Append(x => x.Items, new Item{Name = "One"}); session.Patch(group.Id).Append(x => x.Items, new ColoredItem{Name = "Two", Color = "Blue"}); session.Patch(group.Id).Append(x => x.Items, new NumberedItem(){Name = "Three", Number = 3}); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -523,18 +523,18 @@ public void can_append_with_sub_types_in_collection() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_append_if_not_exists_with_sub_types_in_collection() + public async Task can_append_if_not_exists_with_sub_types_in_collection() { var group = new ItemGroup(); theSession.Store(group); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Patch(group.Id).AppendIfNotExists(x => x.Items, new Item{Name = "One"}); session.Patch(group.Id).AppendIfNotExists(x => x.Items, new ColoredItem{Name = "Two", Color = "Blue"}); session.Patch(group.Id).AppendIfNotExists(x => x.Items, new NumberedItem(){Name = "Three", Number = 3}); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -549,19 +549,19 @@ public void can_append_if_not_exists_with_sub_types_in_collection() } [SerializerTypeTargetedFact(RunFor = SerializerType.Newtonsoft)] - public void can_insert_if_not_exists_with_sub_types_in_collection() + public async Task can_insert_if_not_exists_with_sub_types_in_collection() { var group = new ItemGroup { Items = new List{new Item{Name = "regular"}} }; theSession.Store(group); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var session = theStore.LightweightSession()) { session.Patch(group.Id).Insert(x => x.Items, new ColoredItem{Name = "Two", Color = "Blue"}); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) @@ -575,7 +575,7 @@ public void can_insert_if_not_exists_with_sub_types_in_collection() [Fact] - public void save_large_bundle_of_operations() + public async Task save_large_bundle_of_operations() { var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); @@ -633,24 +633,24 @@ public void save_large_bundle_of_operations() session.Patch(x => x.ObjectId == id1 && x.DefinitionId == 1) .Set(x => x.Mode, 1); - session.SaveChanges(); + await session.SaveChangesAsync(); } } #nullable enable [Fact] - public void can_patch_nullable_field() + public async Task can_patch_nullable_field() { var model = new TestModel7(); var nullModel = new TestModel7() { NullableObjectId = Guid.NewGuid()}; theSession.Store(model, nullModel); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); var id = Guid.NewGuid(); using (var session = theStore.LightweightSession()) { session.Patch(model.Id).Set(x => x.NullableObjectId, id); session.Patch(nullModel.Id).Set(x => x.NullableObjectId, null); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var query = theStore.QuerySession()) diff --git a/src/PatchingTests/Patching/multi_tenancy.cs b/src/PatchingTests/Patching/multi_tenancy.cs index fb5c96f807..ae16156a66 100644 --- a/src/PatchingTests/Patching/multi_tenancy.cs +++ b/src/PatchingTests/Patching/multi_tenancy.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using Marten.Patching; using Marten.Schema; using Marten.Testing.Documents; @@ -20,7 +21,7 @@ public MultiTenancyFixture(): base("multi_tenancy") } [Collection("multi_tenancy")] -public class multi_tenancy: StoreContext, IClassFixture +public class multi_tenancy: StoreContext, IClassFixture, IAsyncLifetime { private readonly ITestOutputHelper _output; private readonly Target[] _greens = Target.GenerateRandomData(100).ToArray(); @@ -35,22 +36,32 @@ public class multi_tenancy: StoreContext, IClassFixture(user.Id).Set(x => x.FirstName, "John"); - green.SaveChanges(); + await green.SaveChangesAsync(); } using (var red = theStore.QuerySession("Red")) @@ -75,7 +86,7 @@ public void patching_respects_tenancy_too() } [Fact] - public void patching_respects_tenancy_too_2() + public async Task patching_respects_tenancy_too_2() { var user = new User { UserName = "Me", FirstName = "Jeremy", LastName = "Miller" }; user.Id = Guid.NewGuid(); @@ -83,13 +94,13 @@ public void patching_respects_tenancy_too_2() using (var red = theStore.LightweightSession("Red")) { red.Store(user); - red.SaveChanges(); + await red.SaveChangesAsync(); } using (var green = theStore.LightweightSession("Green")) { green.Patch(x => x.UserName == "Me").Set(x => x.FirstName, "John"); - green.SaveChanges(); + await green.SaveChangesAsync(); } using (var red = theStore.QuerySession("Red")) diff --git a/src/PatchingTests/Patching/patching_api.cs b/src/PatchingTests/Patching/patching_api.cs index 36c227b30e..0018c419f8 100644 --- a/src/PatchingTests/Patching/patching_api.cs +++ b/src/PatchingTests/Patching/patching_api.cs @@ -31,16 +31,16 @@ public patching_api() #region sample_patching_set_an_immediate_property_by_id [Fact] - public void set_an_immediate_property_by_id() + public async Task set_an_immediate_property_by_id() { var target = Target.Random(true); target.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Set(x => x.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -51,16 +51,16 @@ public void set_an_immediate_property_by_id() #endregion [Fact] - public void initialise_a_new_property_by_expression() + public async Task initialise_a_new_property_by_expression() { theSession.Store(Target.Random(), Target.Random(), Target.Random()); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_initialise_a_new_property_by_expression const string where = "(data ->> 'UpdatedAt') is null"; theSession.Query(where).Count.ShouldBe(3); theSession.Patch(new WhereFragment(where)).Set("UpdatedAt", DateTime.UtcNow); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -70,16 +70,16 @@ public void initialise_a_new_property_by_expression() } [Fact] - public void set_a_deep_property_by_id() + public async Task set_a_deep_property_by_id() { var target = Target.Random(true); target.Inner.Number = 5; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Set(x => x.Inner.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -88,7 +88,7 @@ public void set_a_deep_property_by_id() } [Fact] - public void set_an_immediate_property_by_where_clause() + public async Task set_an_immediate_property_by_where_clause() { var target1 = new Target { Color = Colors.Blue, Number = 1 }; var target2 = new Target { Color = Colors.Blue, Number = 1 }; @@ -98,14 +98,14 @@ public void set_an_immediate_property_by_where_clause() var target6 = new Target { Color = Colors.Red, Number = 1 }; theSession.Store(target1, target2, target3, target4, target5, target6); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_set_an_immediate_property_by_where_clause // Change every Target document where the Color is Blue theSession.Patch(x => x.Color == Colors.Blue).Set(x => x.Number, 2); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -122,16 +122,16 @@ public void set_an_immediate_property_by_where_clause() } [Fact] - public void duplicate_to_new_field() + public async Task duplicate_to_new_field() { #region sample_patching_duplicate_to_new_field var target = Target.Random(); target.AnotherString = null; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Duplicate(t => t.String, t => t.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -142,13 +142,13 @@ public void duplicate_to_new_field() } [Fact] - public void duplicate_to_multiple_new_fields() + public async Task duplicate_to_multiple_new_fields() { var target = Target.Random(); target.StringField = null; target.Inner = null; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_duplicate_to_multiple_new_fields theSession.Patch(target.Id).Duplicate(t => t.String, @@ -156,7 +156,7 @@ public void duplicate_to_multiple_new_fields() t => t.Inner.String, t => t.Inner.AnotherString); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -171,16 +171,16 @@ public void duplicate_to_multiple_new_fields() #region sample_patching_increment_for_int [Fact] - public void increment_for_int() + public async Task increment_for_int() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -192,16 +192,16 @@ public void increment_for_int() #region sample_patching_increment_for_int_with_explicit_increment [Fact] - public void increment_for_int_with_explicit_increment() + public async Task increment_for_int_with_explicit_increment() { var target = Target.Random(); target.Number = 6; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Number, 3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -212,16 +212,16 @@ public void increment_for_int_with_explicit_increment() #endregion [Fact] - public void increment_for_long() + public async Task increment_for_long() { var target = Target.Random(); target.Long = 13; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Long); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -230,16 +230,16 @@ public void increment_for_long() } [Fact] - public void increment_for_double() + public async Task increment_for_double() { var target = Target.Random(); target.Double = 11.2; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Double, 2.4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -248,16 +248,16 @@ public void increment_for_double() } [Fact] - public void increment_for_float() + public async Task increment_for_float() { var target = Target.Random(); target.Float = 11.2F; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Increment(x => x.Float, 2.4F); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -266,15 +266,15 @@ public void increment_for_float() } [Fact] - public void increment_for_decimal() + public async Task increment_for_decimal() { var target = Target.Random(); target.Decimal = 11.2m; theSession.Store(target); theSession.Patch(target.Id).Increment(x => x.Decimal, 2.4m); - theSession.SaveChanges(); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -283,16 +283,16 @@ public void increment_for_decimal() } [Fact] - public void append_to_a_primitive_array() + public async Task append_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -302,16 +302,16 @@ public void append_to_a_primitive_array() } [Fact] - public void append_if_not_exists_to_a_primitive_array() + public async Task append_if_not_exists_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).AppendIfNotExists(x => x.NumberArray, 3); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -320,7 +320,7 @@ public void append_if_not_exists_to_a_primitive_array() } theSession.Patch(target.Id).AppendIfNotExists(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -331,7 +331,7 @@ public void append_if_not_exists_to_a_primitive_array() #region sample_patching_append_complex_element [Fact] - public void append_complex_element() + public async Task append_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -339,10 +339,10 @@ public void append_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -356,7 +356,7 @@ public void append_complex_element() #endregion [Fact] - public void append_if_not_exists_complex_element() + public async Task append_if_not_exists_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -365,11 +365,11 @@ public void append_if_not_exists_complex_element() var child2 = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Append(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).AppendIfNotExists(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -380,7 +380,7 @@ public void append_if_not_exists_complex_element() } theSession.Patch(target.Id).AppendIfNotExists(x => x.Children, child2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -392,16 +392,16 @@ public void append_if_not_exists_complex_element() } [Fact] - public void insert_first_to_a_primitive_array() + public async Task insert_first_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -411,16 +411,16 @@ public void insert_first_to_a_primitive_array() } [Fact] - public void insert_if_not_exists_last_to_a_primitive_array() + public async Task insert_if_not_exists_last_to_a_primitive_array() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 1); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -429,7 +429,7 @@ public void insert_if_not_exists_last_to_a_primitive_array() } theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 4); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -439,16 +439,16 @@ public void insert_if_not_exists_last_to_a_primitive_array() } [Fact] - public void insert_first_to_a_primitive_array_at_a_certain_position() + public async Task insert_first_to_a_primitive_array_at_a_certain_position() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.NumberArray, 4, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -458,16 +458,16 @@ public void insert_first_to_a_primitive_array_at_a_certain_position() } [Fact] - public void insert_if_not_exists_first_to_a_primitive_array_at_a_certain_position() + public async Task insert_if_not_exists_first_to_a_primitive_array_at_a_certain_position() { var target = Target.Random(); target.NumberArray = new[] { 1, 2, 3 }; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 3, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -476,7 +476,7 @@ public void insert_if_not_exists_first_to_a_primitive_array_at_a_certain_positio } theSession.Patch(target.Id).InsertIfNotExists(x => x.NumberArray, 4, 2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -487,7 +487,7 @@ public void insert_if_not_exists_first_to_a_primitive_array_at_a_certain_positio #region sample_patching_insert_first_complex_element [Fact] - public void insert_first_complex_element() + public async Task insert_first_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -495,10 +495,10 @@ public void insert_first_complex_element() var child = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -512,7 +512,7 @@ public void insert_first_complex_element() #endregion [Fact] - public void insert_if_not_exists_last_complex_element() + public async Task insert_if_not_exists_last_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -520,10 +520,10 @@ public void insert_if_not_exists_last_complex_element() var child = Target.Random(); var child2 = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Insert(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -534,7 +534,7 @@ public void insert_if_not_exists_last_complex_element() } theSession.Patch(target.Id).InsertIfNotExists(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -545,7 +545,7 @@ public void insert_if_not_exists_last_complex_element() } theSession.Patch(target.Id).InsertIfNotExists(x => x.Children, child2); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -557,17 +557,17 @@ public void insert_if_not_exists_last_complex_element() } [Fact] - public void rename_shallow_prop() + public async Task rename_shallow_prop() { var target = Target.Random(true); target.String = "Foo"; target.AnotherString = "Bar"; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Rename("String", x => x.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -579,17 +579,17 @@ public void rename_shallow_prop() #region sample_patching_rename_deep_prop [Fact] - public void rename_deep_prop() + public async Task rename_deep_prop() { var target = Target.Random(true); target.Inner.String = "Foo"; target.Inner.AnotherString = "Bar"; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Rename("String", x => x.Inner.AnotherString); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -603,7 +603,7 @@ public void rename_deep_prop() #region sample_patching_remove_primitive_element [Fact] - public void remove_primitive_element() + public async Task remove_primitive_element() { var random = new Random(); var target = Target.Random(); @@ -616,10 +616,10 @@ public void remove_primitive_element() var child = target.NumberArray[random.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -634,7 +634,7 @@ public void remove_primitive_element() #region sample_patching_remove_repeated_primitive_element [Fact] - public void remove_repeated_primitive_elements() + public async Task remove_repeated_primitive_elements() { var random = new Random(); var target = Target.Random(); @@ -654,10 +654,10 @@ public void remove_repeated_primitive_elements() } theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.NumberArray, child, RemoveAction.RemoveAll); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -672,7 +672,7 @@ public void remove_repeated_primitive_elements() #region sample_patching_remove_complex_element [Fact] - public void remove_complex_element() + public async Task remove_complex_element() { var target = Target.Random(true); var initialCount = target.Children.Length; @@ -681,10 +681,10 @@ public void remove_complex_element() var child = target.Children[random.Next(0, initialCount)]; theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); theSession.Patch(target.Id).Remove(x => x.Children, child); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -698,16 +698,16 @@ public void remove_complex_element() #endregion [Fact] - public void delete_redundant_property() + public async Task delete_redundant_property() { var target = Target.Random(); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_delete_redundant_property theSession.Patch(target.Id).Delete("String"); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -718,16 +718,16 @@ public void delete_redundant_property() } [Fact] - public void delete_redundant_nested_property() + public async Task delete_redundant_nested_property() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_delete_redundant_nested_property theSession.Patch(target.Id).Delete("String", t => t.Inner); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -738,16 +738,16 @@ public void delete_redundant_nested_property() } [Fact] - public void delete_existing_property() + public async Task delete_existing_property() { var target = Target.Random(true); theSession.Store(target); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_delete_existing_property theSession.Patch(target.Id).Delete(t => t.Inner); #endregion - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -758,19 +758,19 @@ public void delete_existing_property() } [Fact] - public void delete_property_from_many_documents() + public async Task delete_property_from_many_documents() { for (var i = 0; i < 15; i++) { theSession.Store(Target.Random()); } - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); #region sample_patching_delete_property_from_many_documents const string where = "(data ->> 'String') is not null"; theSession.Query(where).Count.ShouldBe(15); theSession.Patch(new WhereFragment(where)).Delete("String"); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { @@ -910,18 +910,18 @@ public Task ApplyAsync(IDocumentOperations operations, IReadOnlyList(target.Id) .Set(x => x.Number, 10) .Increment(x => x.Number, 10); - theSession.SaveChanges(); + await theSession.SaveChangesAsync(); using (var query = theStore.QuerySession()) { diff --git a/src/StressTests/ability_to_use_an_existing_connection_and_transaction.cs b/src/StressTests/ability_to_use_an_existing_connection_and_transaction.cs index 6c9a84ff4f..5bcd7d2eb5 100644 --- a/src/StressTests/ability_to_use_an_existing_connection_and_transaction.cs +++ b/src/StressTests/ability_to_use_an_existing_connection_and_transaction.cs @@ -93,14 +93,14 @@ public async Task can_query_async_with_session_enlisted_in_transaction_scope() } [Fact] - public void enlist_in_transaction_scope() + public async Task enlist_in_transaction_scope() { using (var scope = new TransactionScope()) { using (var session = theStore.LightweightSession(SessionOptions.ForCurrentTransaction())) { session.Store(Target.Random(), Target.Random()); - session.SaveChanges(); + await session.SaveChangesAsync(); } // should not yet be committed @@ -122,14 +122,14 @@ public void enlist_in_transaction_scope() [Fact] - public void enlist_in_transaction_scope_by_transaction() + public async Task enlist_in_transaction_scope_by_transaction() { using (var scope = new TransactionScope()) { using (var session = theStore.LightweightSession(SessionOptions.ForCurrentTransaction())) { session.Store(Target.Random(), Target.Random()); - session.SaveChanges(); + await session.SaveChangesAsync(); } // should not yet be committed @@ -150,7 +150,7 @@ public void enlist_in_transaction_scope_by_transaction() } [Fact] - public void pass_in_current_connection_and_transaction() + public async Task pass_in_current_connection_and_transaction() { var newTargets = Target.GenerateRandomData(5).ToArray(); @@ -172,7 +172,7 @@ public void pass_in_current_connection_and_transaction() using (var session = theStore.LightweightSession(SessionOptions.ForTransaction(tx, true))) { session.Store(newTargets); - session.SaveChanges(); + await session.SaveChangesAsync(); } } @@ -219,7 +219,7 @@ public async Task pass_in_current_connection_and_transaction_async() } [Fact] - public void pass_in_current_connection_and_transaction_with_externally_controlled_tx_boundaries() + public async Task pass_in_current_connection_and_transaction_with_externally_controlled_tx_boundaries() { var newTargets = Target.GenerateRandomData(5).ToArray(); @@ -235,7 +235,7 @@ public void pass_in_current_connection_and_transaction_with_externally_controlle using (var session = theStore.LightweightSession(SessionOptions.ForTransaction(tx))) { session.Store(newTargets); - session.SaveChanges(); + await session.SaveChangesAsync(); } // To prove the isolation here diff --git a/src/samples/EventSourcingIntro/Program.cs b/src/samples/EventSourcingIntro/Program.cs index 695182b74a..5a28e72c1d 100644 --- a/src/samples/EventSourcingIntro/Program.cs +++ b/src/samples/EventSourcingIntro/Program.cs @@ -131,9 +131,9 @@ public WarehouseProductHandler(Guid id, IDocumentStore documentStore) this.documentStore = documentStore; } - public void ShipProduct(int quantity) + public async Task ShipProduct(int quantity) { - using var session = documentStore.LightweightSession(); + await using var session = documentStore.LightweightSession(); var warehouseProduct = session.Events.AggregateStream(id); @@ -143,18 +143,18 @@ public void ShipProduct(int quantity) } session.Events.Append(id, new ProductShipped(id, quantity, DateTime.UtcNow)); - session.SaveChanges(); + await session.SaveChangesAsync(); } - public void ReceiveProduct(int quantity) + public async Task ReceiveProduct(int quantity) { using var session = documentStore.LightweightSession(); session.Events.Append(id, new ProductReceived(id, quantity, DateTime.UtcNow)); - session.SaveChanges(); + await session.SaveChangesAsync(); } - public void AdjustInventory(int quantity, string reason) + public async Task AdjustInventory(int quantity, string reason) { using var session = documentStore.LightweightSession(); @@ -166,7 +166,7 @@ public void AdjustInventory(int quantity, string reason) } session.Events.Append(id, new InventoryAdjusted(id, quantity, reason, DateTime.UtcNow)); - session.SaveChanges(); + await session.SaveChangesAsync(); } }