diff --git a/src/CoreTests/Bugs/Bug_983_autocreate_none_is_disabling_schema_validation.cs b/src/CoreTests/Bugs/Bug_983_autocreate_none_is_disabling_schema_validation.cs index 238b53c6f2..d4dd23df23 100644 --- a/src/CoreTests/Bugs/Bug_983_autocreate_none_is_disabling_schema_validation.cs +++ b/src/CoreTests/Bugs/Bug_983_autocreate_none_is_disabling_schema_validation.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Marten.Testing.Harness; +using Shouldly; using Weasel.Core; using Weasel.Core.Migrations; using Xunit; @@ -25,10 +26,10 @@ public async Task should_be_validating_the_new_doc_does_not_exist() cfg.AutoCreateSchemaObjects = AutoCreate.None; }); - await Exception.ShouldBeThrownByAsync(() => + await Should.ThrowAsync(async () => { - return theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync(); + await theStore.Storage.Database.AssertDatabaseMatchesConfigurationAsync(); }); } -} \ No newline at end of file +} diff --git a/src/DaemonTests/event_projection_scenario_tests.cs b/src/DaemonTests/event_projection_scenario_tests.cs index 3d19b81ec0..3829645925 100644 --- a/src/DaemonTests/event_projection_scenario_tests.cs +++ b/src/DaemonTests/event_projection_scenario_tests.cs @@ -86,7 +86,7 @@ public async Task sad_path_test_with_inline_projection() opts.Projections.Add(new UserProjection(), ProjectionLifecycle.Inline); }); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theStore.Advanced.EventProjectionScenario(scenario => { @@ -121,7 +121,7 @@ public async Task sad_path_test_with_inline_projection_with_document_assertion() opts.Projections.Add(new UserProjection(), ProjectionLifecycle.Inline); }); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theStore.Advanced.EventProjectionScenario(scenario => { @@ -186,7 +186,7 @@ public async Task sad_path_test_with_inline_projection_async() opts.Projections.Add(new UserProjection(), ProjectionLifecycle.Async); }); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theStore.Advanced.EventProjectionScenario(scenario => { @@ -221,7 +221,7 @@ public async Task sad_path_test_with_inline_projection_with_document_assertion_a opts.Projections.Add(new UserProjection(), ProjectionLifecycle.Async); }); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theStore.Advanced.EventProjectionScenario(scenario => { @@ -278,4 +278,4 @@ public void Project(DeleteUser deletion, IDocumentOperations operations) } } -#endregion \ No newline at end of file +#endregion diff --git a/src/DocumentDbTests/Bugs/Bug_648_defensive_programming_checks_on_bad_id_type.cs b/src/DocumentDbTests/Bugs/Bug_648_defensive_programming_checks_on_bad_id_type.cs index 36ce384215..482ac5f34d 100644 --- a/src/DocumentDbTests/Bugs/Bug_648_defensive_programming_checks_on_bad_id_type.cs +++ b/src/DocumentDbTests/Bugs/Bug_648_defensive_programming_checks_on_bad_id_type.cs @@ -4,6 +4,7 @@ using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace DocumentDbTests.Bugs; @@ -13,7 +14,7 @@ public class Bug_648_defensive_programming_checks_on_bad_id_type: IntegrationCon [Fact] public void try_to_load_a_guid_identified_type_with_wrong_type() { - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Load(111); }); @@ -22,16 +23,16 @@ public void try_to_load_a_guid_identified_type_with_wrong_type() [Fact] public Task try_to_load_a_guid_identified_type_with_wrong_type_async() { - return Exception.ShouldBeThrownByAsync(() => + return Should.ThrowAsync(async () => { - return theSession.LoadAsync(111); + await theSession.LoadAsync(111); }); } [Fact] public void bad_id_to_load_many() { - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.LoadMany(111, 121); }); @@ -40,13 +41,13 @@ public void bad_id_to_load_many() [Fact] public Task try_to_loadmany_a_guid_identified_type_with_wrong_type_async() { - return Exception.ShouldBeThrownByAsync(() => + return Should.ThrowAsync(async () => { - return theSession.LoadManyAsync(111, 222); + await theSession.LoadManyAsync(111, 222); }); } public Bug_648_defensive_programming_checks_on_bad_id_type(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_953_too_long_index_names.cs b/src/DocumentDbTests/Bugs/Bug_953_too_long_index_names.cs index be9f646380..ef26a2f705 100644 --- a/src/DocumentDbTests/Bugs/Bug_953_too_long_index_names.cs +++ b/src/DocumentDbTests/Bugs/Bug_953_too_long_index_names.cs @@ -1,6 +1,7 @@ using System; using Marten.Exceptions; using Marten.Testing.Harness; +using Shouldly; using Weasel.Postgresql; using Xunit; @@ -24,7 +25,7 @@ public void can_ensure_storage_with_index_id_greater_than_63_bytes() _.NameDataLength = 64; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theStore.Tenancy.Default.Database.EnsureStorageExists(typeof(LongEnoughNameToCauseIdTruncation)); }); diff --git a/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs b/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs index 65f47abc90..ab2e8903e0 100644 --- a/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs +++ b/src/DocumentDbTests/Bugs/optimistic_concurrency_with_update_method.cs @@ -123,7 +123,7 @@ public async Task update_with_stale_version_throws_exception_async() session2.Update(doc2); - var ex = await Exception.ShouldBeThrownByAsync(async () => + var ex = await Should.ThrowAsync(async () => { await session2.SaveChangesAsync(); }); diff --git a/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs b/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs index cd4b818e80..3fd09f73ac 100644 --- a/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs +++ b/src/DocumentDbTests/Concurrency/optimistic_concurrency.cs @@ -233,7 +233,7 @@ public async Task update_with_stale_version_standard_async() // Should go through just fine await session2.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(async () => + var ex = await Should.ThrowAsync(async () => { await session1.SaveChangesAsync(); }); @@ -474,7 +474,7 @@ public async Task update_multiple_docs_at_a_time_sad_path_async() await other.SaveChangesAsync(); } - var ex = await Exception.ShouldBeThrownByAsync(async () => + var ex = await Should.ThrowAsync(async () => { await session.SaveChangesAsync(); }); @@ -589,7 +589,7 @@ public async Task store_with_the_right_version_sad_path_async() // Some random version that won't match session.UpdateExpectedVersion(doc1, Guid.NewGuid()); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await session.SaveChangesAsync(); }); @@ -797,7 +797,7 @@ public async Task update_with_stale_version_async() // Should go through just fine await session2.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(async () => + var ex = await Should.ThrowAsync(async () => { await session1.SaveChangesAsync(); }); diff --git a/src/DocumentDbTests/Configuration/DocumentMappingTests.cs b/src/DocumentDbTests/Configuration/DocumentMappingTests.cs index 2e38da7856..b4b6eba8c2 100644 --- a/src/DocumentDbTests/Configuration/DocumentMappingTests.cs +++ b/src/DocumentDbTests/Configuration/DocumentMappingTests.cs @@ -533,7 +533,7 @@ public void to_upsert_with_subclasses() [Fact] public void trying_to_replace_the_hilo_settings_when_not_using_hilo_for_the_sequence_throws() { - Exception.ShouldBeThrownBy( + Should.Throw( () => { DocumentMapping.For().HiloSettings = new HiloSettings(); }); } @@ -622,7 +622,7 @@ public void uses_ConfigureMarten_method_to_alter_mapping_upon_construction_with_ [Fact] public void trying_to_index_deleted_at_when_not_soft_deleted_document_throws() { - Exception.ShouldBeThrownBy(() => DocumentMapping.For().AddDeletedAtIndex()); + Should.Throw(() => DocumentMapping.For().AddDeletedAtIndex()); } [Fact] diff --git a/src/DocumentDbTests/ForeignKeys/foreign_keys.cs b/src/DocumentDbTests/ForeignKeys/foreign_keys.cs index 1fea155799..220d765da9 100644 --- a/src/DocumentDbTests/ForeignKeys/foreign_keys.cs +++ b/src/DocumentDbTests/ForeignKeys/foreign_keys.cs @@ -340,7 +340,7 @@ public async Task order_inserts() [Fact] public void throws_exception_on_cyclic_dependency() { - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { StoreOptions(_ => { diff --git a/src/DocumentDbTests/Metadata/assigning_versions_to_documents.cs b/src/DocumentDbTests/Metadata/assigning_versions_to_documents.cs index 41f1d56fa8..89902399e4 100644 --- a/src/DocumentDbTests/Metadata/assigning_versions_to_documents.cs +++ b/src/DocumentDbTests/Metadata/assigning_versions_to_documents.cs @@ -34,7 +34,7 @@ public void version_member_set_by_attribute() [Fact] public void wrong_version_member() { - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { DocumentMapping.For(); }); @@ -86,4 +86,4 @@ public class WrongVersionTypedDoc [Version] public string Version; -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/MultiTenancy/disabling_default_tenant_usage.cs b/src/DocumentDbTests/MultiTenancy/disabling_default_tenant_usage.cs index 89299f243e..302495bf6b 100644 --- a/src/DocumentDbTests/MultiTenancy/disabling_default_tenant_usage.cs +++ b/src/DocumentDbTests/MultiTenancy/disabling_default_tenant_usage.cs @@ -2,6 +2,7 @@ using Marten.Services; using Marten.Storage; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace DocumentDbTests.MultiTenancy; @@ -16,7 +17,7 @@ public void get_exception_when_creating_session_with_default_tenant_usage_disabl _.Advanced.DefaultTenantUsageEnabled = false; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { using (var session = theStore.LightweightSession()) { } }); @@ -30,7 +31,7 @@ public void get_exception_when_creating_query_session_with_default_tenant_usage_ _.Advanced.DefaultTenantUsageEnabled = false; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { using (var session = theStore.LightweightSession()) { } }); @@ -44,7 +45,7 @@ public void get_exception_when_creating_session_with_default_tenant_and_default_ _.Advanced.DefaultTenantUsageEnabled = false; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { using (var session = theStore.LightweightSession(Tenancy.DefaultTenantId)) { } }); @@ -58,7 +59,7 @@ public void get_exception_when_creating_query_session_with_default_tenant_and_de _.Advanced.DefaultTenantUsageEnabled = false; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { using (var session = theStore.LightweightSession(Tenancy.DefaultTenantId)) { } }); @@ -72,7 +73,7 @@ public void get_exception_when_creating_session_with_default_tenant_session_opti _.Advanced.DefaultTenantUsageEnabled = false; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { var sessionOptions = new SessionOptions {TenantId = Tenancy.DefaultTenantId}; using (var session = theStore.LightweightSession(sessionOptions)) { } @@ -87,7 +88,7 @@ public void get_exception_when_creating_query_session_with_default_tenant_sessio _.Advanced.DefaultTenantUsageEnabled = false; }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { var sessionOptions = new SessionOptions {TenantId = Tenancy.DefaultTenantId}; using (var session = theStore.QuerySession(sessionOptions)) { } diff --git a/src/DocumentDbTests/Reading/Json/streaming_json_results.cs b/src/DocumentDbTests/Reading/Json/streaming_json_results.cs index 26a5b88c06..b23440d78b 100644 --- a/src/DocumentDbTests/Reading/Json/streaming_json_results.cs +++ b/src/DocumentDbTests/Reading/Json/streaming_json_results.cs @@ -337,7 +337,7 @@ public async Task first_throws_when_none_returned() }; theSession.Store(user1,user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(async () => await theSession.Query().Where(x => x.Number != 5).ToJsonFirst()); + var ex = await Should.ThrowAsync(async () => await theSession.Query().Where(x => x.Number != 5).ToJsonFirst()); ex.Message.ShouldBe("Sequence contains no elements"); } @@ -421,7 +421,7 @@ public async Task first_async_throws_when_none_returned() }; theSession.Store(user1,user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(() => + var ex = await Should.ThrowAsync(() => theSession.Query().Where(x => x.Number != 5).ToJsonFirst()); ex.Message.ShouldBe("Sequence contains no elements"); } @@ -694,7 +694,7 @@ public async Task single_throws_when_none_found() }; theSession.Store(user1, user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(async () => await theSession.Query().Where(x => x.Number != 5).ToJsonSingle()); + var ex = await Should.ThrowAsync(async () => await theSession.Query().Where(x => x.Number != 5).ToJsonSingle()); ex.Message.ShouldBe("Sequence contains no elements"); } @@ -717,7 +717,7 @@ public async Task single_throws_when_more_than_one_found() }; theSession.Store(user1, user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(async () => await theSession.Query().Where(x => x.Number == 5).ToJsonSingle()); + var ex = await Should.ThrowAsync(async () => await theSession.Query().Where(x => x.Number == 5).ToJsonSingle()); ex.Message.ShouldBe("Sequence contains more than one element"); } @@ -780,7 +780,7 @@ public async Task single_async_throws_when_none_returned() }; theSession.Store(user1, user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(() => + var ex = await Should.ThrowAsync(() => theSession.Query().Where(x => x.Number != 5).ToJsonSingle()); ex.Message.ShouldBe("Sequence contains no elements"); } @@ -804,7 +804,7 @@ public async Task single_async_throws_when_more_than_one_returned() }; theSession.Store(user1, user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(() => + var ex = await Should.ThrowAsync(() => theSession.Query().Where(x => x.Number == 5).ToJsonSingle()); ex.Message.ShouldBe("Sequence contains more than one element"); } @@ -936,7 +936,7 @@ public async Task single_or_default_throws_when_more_than_one_found() }; theSession.Store(user1, user2); await theSession.SaveChangesAsync(); - var ex = await Exception.ShouldBeThrownByAsync(async () => await theSession.Query().Where(x => x.Number == 5).ToJsonSingleOrDefault()); + var ex = await Should.ThrowAsync(async () => await theSession.Query().Where(x => x.Number == 5).ToJsonSingleOrDefault()); ex.Message.ShouldBe("Sequence contains more than one element"); } diff --git a/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs b/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs index bc0bdc95c5..d9061b849c 100644 --- a/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs +++ b/src/DocumentDbTests/SessionMechanics/identity_map_mechanics.cs @@ -169,7 +169,7 @@ public void given_document_with_same_id_is_already_added_then_exception_should_o var session = OpenSession(tracking); session.Store(user1); - Exception.ShouldBeThrownBy(() => session.Store(user2)) + Should.Throw(() => session.Store(user2)) .Message.ShouldBe("Document 'Marten.Testing.Documents.User' with same Id already added to the session."); } diff --git a/src/DocumentDbTests/SessionMechanics/session_timeouts.cs b/src/DocumentDbTests/SessionMechanics/session_timeouts.cs index 7b956b9e40..188440670a 100644 --- a/src/DocumentDbTests/SessionMechanics/session_timeouts.cs +++ b/src/DocumentDbTests/SessionMechanics/session_timeouts.cs @@ -1,6 +1,7 @@ using System; using Marten.Services; using Marten.Testing.Harness; +using Shouldly; using Xunit; namespace DocumentDbTests.SessionMechanics; @@ -10,12 +11,12 @@ public class session_timeouts : IntegrationContext [Fact] public void should_respect_command_timeout_options() { - var ex = Exception.ShouldBeThrownBy(() => + var ex = Should.Throw(() => { var session = theStore.QuerySession(new SessionOptions() {Timeout = -1}); }); - ex.Message.ShouldContain("CommandTimeout can't be less than zero"); + ex.Message.ShouldContain("CommandTimeout can't be less than zero", Case.Insensitive); } @@ -23,4 +24,4 @@ public void should_respect_command_timeout_options() public session_timeouts(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Writing/Identity/using_string_identity.cs b/src/DocumentDbTests/Writing/Identity/using_string_identity.cs index 642d182054..6910ab53f4 100644 --- a/src/DocumentDbTests/Writing/Identity/using_string_identity.cs +++ b/src/DocumentDbTests/Writing/Identity/using_string_identity.cs @@ -45,7 +45,7 @@ public void throws_exception_if_trying_to_save_null_id() { var account = new Account {Id = null}; - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Store(account); }); @@ -57,7 +57,7 @@ public void throws_exception_if_trying_to_save_empty_id() { var account = new Account { Id = string.Empty }; - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Store(account); }); diff --git a/src/DocumentDbTests/Writing/document_updates.cs b/src/DocumentDbTests/Writing/document_updates.cs index 207edaf511..3701c4eaf9 100644 --- a/src/DocumentDbTests/Writing/document_updates.cs +++ b/src/DocumentDbTests/Writing/document_updates.cs @@ -54,7 +54,7 @@ public async Task update_sad_path_async() var target = Target.Random(); await using var session = theStore.LightweightSession(); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { session.Update(target); await session.SaveChangesAsync(); diff --git a/src/DocumentDbTests/duplicate_document_type_alias_detection.cs b/src/DocumentDbTests/duplicate_document_type_alias_detection.cs index a49b28453a..230ecd3c0a 100644 --- a/src/DocumentDbTests/duplicate_document_type_alias_detection.cs +++ b/src/DocumentDbTests/duplicate_document_type_alias_detection.cs @@ -15,7 +15,7 @@ public void throw_ambigous_alias_exception_when_you_have_duplicate_document_alia { theStore.Options.Providers.StorageFor().ShouldNotBeNull(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theStore.Options.Providers.StorageFor().ShouldNotBeNull(); }); diff --git a/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs b/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs index a83029371b..df89a781b9 100644 --- a/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs +++ b/src/EventSourcingTests/Aggregation/CustomProjectionTests.cs @@ -120,7 +120,7 @@ public void async_options_is_not_null() [Fact] public void assert_invalid_with_no_slicer() { - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { new MyCustomAggregateWithNoSlicer().AssembleAndAssertValidity(); }); @@ -132,7 +132,7 @@ public void assert_invalid_with_incomplete_slicing_rules() var projection = new MyCustomAggregateWithNoSlicer(); projection.AggregateEvents(x => { }); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { new MyCustomAggregateWithNoSlicer().AssembleAndAssertValidity(); }); @@ -152,7 +152,7 @@ public void throws_if_you_try_to_slice_by_string_on_something_besides_guid_or_st { var wrong = new EmptyCustomProjection(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { wrong.AggregateByStream(); }); diff --git a/src/EventSourcingTests/Aggregation/fetching_async_aggregates_for_writing.cs b/src/EventSourcingTests/Aggregation/fetching_async_aggregates_for_writing.cs index 104b4e65f6..4ba73fca58 100644 --- a/src/EventSourcingTests/Aggregation/fetching_async_aggregates_for_writing.cs +++ b/src/EventSourcingTests/Aggregation/fetching_async_aggregates_for_writing.cs @@ -62,7 +62,7 @@ public async Task fetch_new_stream_for_writing_Guid_identifier_exception_handlin await theSession.SaveChangesAsync(); var sameStream = theSession.Events.StartStream(streamId, new AEvent()); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theSession.SaveChangesAsync(); }); diff --git a/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs b/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs index 8f6c1b158e..f63fd26204 100644 --- a/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs +++ b/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs @@ -111,7 +111,7 @@ public async Task fetch_new_stream_for_writing_Guid_identifier_exception_handlin await theSession.SaveChangesAsync(); var sameStream = theSession.Events.StartStream(streamId, new AEvent()); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theSession.SaveChangesAsync(); }); 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 d87bdab7b1..f70fa6067a 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 @@ -633,7 +633,7 @@ await When.CalledForEachAsync(tenants, async (tenantId, index) => using (var session = store.LightweightSession(tenantId)) { - var streamEvents = session.Events.FetchStream(id); + var streamEvents = await session.Events.FetchStreamAsync(id); streamEvents.Count.ShouldBe(1); var @event = streamEvents.ElementAt(0).Data.ShouldBeOfType(); 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 68e8703b57..8469774475 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 @@ -649,10 +649,9 @@ public async Task capture_immutable_events(TenancyStyle tenancyStyle, string[] t { var store = InitStore(tenancyStyle); - var id = Guid.NewGuid(); - await When.CalledForEachAsync(tenants, async (tenantId, index) => { + var id = Guid.NewGuid(); var immutableEvent = new ImmutableEvent(id, "some-name"); using (var session = store.LightweightSession(tenantId)) @@ -663,7 +662,7 @@ await When.CalledForEachAsync(tenants, async (tenantId, index) => using (var session = store.LightweightSession(tenantId)) { - var streamEvents = session.Events.FetchStream(id); + var streamEvents = await session.Events.FetchStreamAsync(id); streamEvents.Count.ShouldBe(1); var @event = streamEvents.ElementAt(0).Data.ShouldBeOfType(); diff --git a/src/LinqTests/Acceptance/statistics_and_paged_list.cs b/src/LinqTests/Acceptance/statistics_and_paged_list.cs index e16461ce2d..9484bb157f 100644 --- a/src/LinqTests/Acceptance/statistics_and_paged_list.cs +++ b/src/LinqTests/Acceptance/statistics_and_paged_list.cs @@ -295,7 +295,7 @@ public async Task invalid_pagenumber_should_throw_exception(Func.ShouldBeThrownByAsync( + await Should.ThrowAsync( async () => await toPagedList(theSession.Query(), pageNumber, pageSize)); SpecificationExtensions.ShouldContain(ex.Message, "pageNumber = 0. PageNumber cannot be below 1."); } @@ -310,7 +310,7 @@ public async Task invalid_pagesize_should_throw_exception(Func.ShouldBeThrownByAsync( + await Should.ThrowAsync( async () => await toPagedList(theSession.Query(), pageNumber, pageSize)); SpecificationExtensions.ShouldContain(ex.Message, $"pageSize = 0. PageSize cannot be below 1."); } @@ -523,7 +523,7 @@ public async Task check_query_with_where_clause_followed_by_to_pagedlist(Func.ShouldBeThrownBy(() => + Should.Throw(() => { var data = theSession.Query(new TargetPage(1, 10)); }); diff --git a/src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs b/src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs index e7832bc8c6..f7d9c9e2d0 100644 --- a/src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs +++ b/src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs @@ -1,6 +1,7 @@ using System.Linq; using Marten.Exceptions; using Marten.Testing.Harness; +using Shouldly; namespace LinqTests.Bugs; @@ -16,7 +17,7 @@ public class TestClass [Fact] public void When_Property_Is_Null_Exception_Should_Be_Null_Reference_Exception() { - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Query().Where(x => x.Id == TestNullObject.Id).ToList(); }); diff --git a/src/LinqTests/ChildCollections/query_against_child_collections.cs b/src/LinqTests/ChildCollections/query_against_child_collections.cs index 15a5d16c63..076571c8a4 100644 --- a/src/LinqTests/ChildCollections/query_against_child_collections.cs +++ b/src/LinqTests/ChildCollections/query_against_child_collections.cs @@ -4,6 +4,7 @@ using System.Linq.Expressions; using System.Threading.Tasks; using JasperFx.Core; +using Marten; using Marten.Exceptions; using Marten.Linq; using Marten.Testing.Documents; @@ -410,16 +411,16 @@ public void query_guid_array_intersects_array() } [Fact] - public void query_array_with_Intersect_should_blow_up() + public async Task query_array_with_Intersect_should_blow_up() { - buildAuthorData(); + await buildAuthorData(); - Exception.ShouldBeThrownBy(() => + await Should.ThrowAsync(async () => { - var res = theSession.Query
() + var res = await theSession.Query
() .Where(x => x.AuthorArray.Any(s => favAuthors.Intersect(new Guid[] { Guid.NewGuid() }).Any())) .OrderBy(x => x.Long) - .ToList(); + .ToListAsync(); }); } diff --git a/src/LinqTests/Operators/first_operator.cs b/src/LinqTests/Operators/first_operator.cs index 42a4dae2ac..2b4ae1a369 100644 --- a/src/LinqTests/Operators/first_operator.cs +++ b/src/LinqTests/Operators/first_operator.cs @@ -89,7 +89,7 @@ public async Task first_miss() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Query().Where(x => x.Number == 11).First(); }); @@ -199,7 +199,7 @@ public async Task first_miss_async() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theSession.Query().Where(x => x.Number == 11).FirstAsync(); }); diff --git a/src/LinqTests/Operators/last_operator.cs b/src/LinqTests/Operators/last_operator.cs index 6f9de3bdbe..f0d75d7699 100644 --- a/src/LinqTests/Operators/last_operator.cs +++ b/src/LinqTests/Operators/last_operator.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Marten.Testing.Documents; using Marten.Testing.Harness; +using Shouldly; namespace LinqTests.Operators; @@ -17,10 +18,9 @@ public async Task last_throws_an_exception() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { - theSession.Query().Last(x => x.Number == 3) - .ShouldNotBeNull(); + SpecificationExtensions.ShouldNotBeNull(theSession.Query().Last(x => x.Number == 3)); }); } @@ -33,10 +33,9 @@ public async Task last_or_default_throws_an_exception() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { - theSession.Query().Last(x => x.Number == 3) - .ShouldNotBeNull(); + SpecificationExtensions.ShouldNotBeNull(theSession.Query().Last(x => x.Number == 3)); }); } diff --git a/src/LinqTests/Operators/single_operator.cs b/src/LinqTests/Operators/single_operator.cs index b315ddf28d..e141c870d3 100644 --- a/src/LinqTests/Operators/single_operator.cs +++ b/src/LinqTests/Operators/single_operator.cs @@ -60,7 +60,7 @@ public async Task single_hit_with_more_than_one_match() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Query().Where(x => x.Number == 2).Single(); }); @@ -89,7 +89,7 @@ public async Task single_or_default_hit_with_more_than_one_match() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Query().Where(x => x.Number == 2).SingleOrDefault(); }); @@ -104,7 +104,7 @@ public async Task single_miss() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - Exception.ShouldBeThrownBy(() => + Should.Throw(() => { theSession.Query().Where(x => x.Number == 11).Single(); }); @@ -158,7 +158,7 @@ public async Task single_hit_with_more_than_one_match_async() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theSession.Query().Where(x => x.Number == 2).SingleAsync(); }); @@ -186,7 +186,7 @@ public async Task single_or_default_hit_with_more_than_one_match_async() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theSession.Query().Where(x => x.Number == 2).SingleOrDefaultAsync(); }); @@ -201,7 +201,7 @@ public async Task single_miss_async() theSession.Store(new Target { Number = 4 }); await theSession.SaveChangesAsync(); - await Exception.ShouldBeThrownByAsync(async () => + await Should.ThrowAsync(async () => { await theSession.Query().Where(x => x.Number == 11).SingleAsync(); }); diff --git a/src/Marten.Testing/Harness/SpecificationExtensions.cs b/src/Marten.Testing/Harness/SpecificationExtensions.cs index 476aea1039..870a3c1da6 100644 --- a/src/Marten.Testing/Harness/SpecificationExtensions.cs +++ b/src/Marten.Testing/Harness/SpecificationExtensions.cs @@ -14,48 +14,6 @@ namespace Marten.Testing.Harness { - - [Obsolete("Use Shouldly instead. Just no reason to have this any longer")] - public static class Exception where T : Exception - { - - public static T ShouldBeThrownBy(Action action) - { - T exception = null; - - try - { - action(); - } - catch (Exception e) - { - exception = e.ShouldBeOfType(); - } - - exception.ShouldNotBeNull("An exception was expected, but not thrown by the given action."); - - return exception; - } - - public static async Task ShouldBeThrownByAsync(Func action) - { - T exception = null; - - try - { - await action(); - } - catch (Exception e) - { - exception = e.ShouldBeOfType(); - } - - exception.ShouldNotBeNull("An exception was expected, but not thrown by the given action."); - - return exception; - } - } - public delegate void MethodThatThrows(); public static class SpecificationExtensions