Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Marten.Testing/Events/query_against_event_documents_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,28 @@ public void will_not_blow_up_if_searching_for_events_before_event_store_is_warme
{
theSession.Events.Query<MembersJoined>().Any().ShouldBeFalse();
}

[Fact]
public void can_query_against_event_type_with_different_schema_name()
{
StoreOptions(_ =>
{
_.DatabaseSchemaName = "test";
_.Events.DatabaseSchemaName = "events";
});

theSession.Events.StartStream<Quest>(joined1, departed1);
theSession.Events.StartStream<Quest>(joined2, departed2);

theSession.SaveChanges();

theSession.Events.Query<MembersJoined>().Count().ShouldBe(2);
theSession.Events.Query<MembersJoined>().ToArray().SelectMany(x => x.Members).Distinct()
.OrderBy(x => x)
.ShouldHaveTheSameElementsAs("Egwene", "Matt", "Nynaeve", "Perrin", "Rand", "Thom");

theSession.Events.Query<MembersDeparted>().Where(x => x.Members.Contains("Matt"))
.Single().Id.ShouldBe(departed2.Id);
}
}
}
49 changes: 44 additions & 5 deletions src/Marten.Testing/Schema/DocumentCleanerTests.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
using System.Diagnostics;
using System;
using System.Linq;
using Baseline;
using Marten.Generation;
using Marten.Events;
using Marten.Schema;
using Marten.Services;
using Marten.Testing.Documents;
using Marten.Testing.Events;
using Marten.Testing.Fixtures;
using Shouldly;
using StructureMap;
using Xunit;
using Issue = Marten.Testing.Documents.Issue;

namespace Marten.Testing.Schema
{
public class DocumentCleanerTests : DocumentSessionFixture<NulloIdentityMap>
{
private readonly DocumentCleaner theCleaner;
private readonly Lazy<DocumentCleaner> _theCleaner;
private DocumentCleaner theCleaner => _theCleaner.Value;

public DocumentCleanerTests()
{
theCleaner = theStore.Advanced.Clean.As<DocumentCleaner>();
_theCleaner = new Lazy<DocumentCleaner>(() => theStore.Advanced.Clean.As<DocumentCleaner>());
}

[Fact]
Expand Down Expand Up @@ -126,6 +128,43 @@ public void completely_remove_everything()
ShouldBeEmpty(schema.SchemaFunctionNames());
}

[Fact]
public void delete_all_event_data()
{
var streamId = Guid.NewGuid();
theSession.Events.StartStream<Quest>(streamId, new QuestStarted());

theSession.SaveChanges();

theCleaner.DeleteAllEventData();

theSession.Events.Query<QuestStarted>().ShouldBeEmpty();
theSession.Events.FetchStream(streamId).ShouldBeEmpty();

}

[Fact]
public void delete_all_event_data_with_different_schema_names()
{
StoreOptions(_ =>
{
_.DatabaseSchemaName = "test";
_.Events.DatabaseSchemaName = "events";
});

var streamId = Guid.NewGuid();

theSession.Events.StartStream<Quest>(streamId, new QuestStarted());

theSession.SaveChanges();

theCleaner.DeleteAllEventData();

// Todo: theSession.Events.Query<>() uses the wrong schema name when using Event type.
//theSession.Events.Query<QuestStarted>().ShouldBeEmpty();
theSession.Events.FetchStream(streamId).ShouldBeEmpty();
}

private static void ShouldBeEmpty<T>(T[] documentTables)
{
var stillInDatabase = string.Join(",", documentTables);
Expand Down
4 changes: 2 additions & 2 deletions src/Marten/Schema/DocumentCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void DeleteAllEventData()
{
using (var connection = new ManagedConnection(_factory, CommandRunnerMode.ReadOnly))
{
connection.Execute($"truncate table {_schema.StoreOptions.DatabaseSchemaName}.mt_events cascade;" +
$"truncate table {_schema.StoreOptions.DatabaseSchemaName}.mt_streams cascade");
connection.Execute($"truncate table {_schema.Events.DatabaseSchemaName}.mt_events cascade;" +
$"truncate table {_schema.Events.DatabaseSchemaName}.mt_streams cascade");
}
}
}
Expand Down