Skip to content

Commit

Permalink
Yet another attempt to make the select_clause tests more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Oct 25, 2024
1 parent f89aeaa commit d40e549
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 55 deletions.
95 changes: 51 additions & 44 deletions src/EventSourcingTests/removing_protected_information.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ public async Task end_to_end_for_Guid_identified_stream_single_rule()
var streamId2 = theSession.Events.StartStream<Quest>(new QuestStarted{Name = "Find the Eye of the World"}, new MembersJoined(1, "Fal Dara", "Rand", "Perrin", "Mat")).Id;
await theSession.SaveChangesAsync();

await theStore.Advanced.ApplyEventDataMasking()
.IncludeStream(streamId)
.AddHeader("color", "green")
.AddHeader("opid", 1)
.ApplyAsync();
await theStore.Advanced.ApplyEventDataMasking(x =>
{
x.IncludeStream(streamId)
.AddHeader("color", "green")
.AddHeader("opid", 1);
});

// Should apply to this stream
var events = await theSession.Events.FetchStreamAsync(streamId);
Expand Down Expand Up @@ -128,11 +129,12 @@ public async Task end_to_end_for_Guid_identified_stream_multiple_rules_and_singl
var streamId2 = theSession.Events.StartStream<Quest>(new QuestStarted{Name = "Find the Eye of the World"}, new MembersJoined(1, "Fal Dara", "Rand", "Perrin", "Mat")).Id;
await theSession.SaveChangesAsync();

await theStore.Advanced.ApplyEventDataMasking()
.IncludeStream(streamId)
.AddHeader("color", "green")
.AddHeader("opid", 1)
.ApplyAsync();
await theStore.Advanced.ApplyEventDataMasking(x =>
{
x.IncludeStream(streamId)
.AddHeader("color", "green")
.AddHeader("opid", 1);
});

// Should apply to this stream
var events = await theSession.Events.FetchStreamAsync(streamId);
Expand Down Expand Up @@ -187,12 +189,14 @@ public async Task end_to_end_for_Guid_identified_stream_multiple_rules_and_multi
var streamId2 = theSession.Events.StartStream<Quest>(new QuestStarted{Name = "Find the Eye of the World"}, new MembersJoined(1, "Fal Dara", "Rand", "Perrin", "Mat")).Id;
await theSession.SaveChangesAsync();

await theStore.Advanced.ApplyEventDataMasking()
.IncludeStream(streamId)
.IncludeStream(streamId2)
.AddHeader("color", "green")
.AddHeader("opid", 1)
.ApplyAsync();
await theStore.Advanced.ApplyEventDataMasking(x =>
{
x
.IncludeStream(streamId)
.IncludeStream(streamId2)
.AddHeader("color", "green")
.AddHeader("opid", 1);
});

// Should apply to this stream
var events = await theSession.Events.FetchStreamAsync(streamId);
Expand Down Expand Up @@ -247,11 +251,12 @@ public async Task end_to_end_for_Guid_identified_stream_multiple_rules_and_throu
var streamId2 = theSession.Events.StartStream<Quest>(new QuestStarted{Name = "Find the Eye of the World"}, new MembersJoined(1, "Fal Dara", "Rand", "Perrin", "Mat")).Id;
await theSession.SaveChangesAsync();

await theStore.Advanced.ApplyEventDataMasking()
.IncludeEvents(e => e.EventTypesAre(typeof(QuestStarted)))
.AddHeader("color", "green")
.AddHeader("opid", 1)
.ApplyAsync();
await theStore.Advanced.ApplyEventDataMasking(x =>
{
x.IncludeEvents(e => e.EventTypesAre(typeof(QuestStarted)))
.AddHeader("color", "green")
.AddHeader("opid", 1);
});

// Should apply to this stream
var events = await theSession.Events.FetchStreamAsync(streamId);
Expand Down Expand Up @@ -307,12 +312,13 @@ public async Task end_to_end_for_string_identified_stream_multiple_rules_and_mul
theSession.Events.StartStream<Quest>(streamId2, new QuestStarted{Name = "Find the Eye of the World"}, new MembersJoined(1, "Fal Dara", "Rand", "Perrin", "Mat"));
await theSession.SaveChangesAsync();

await theStore.Advanced.ApplyEventDataMasking()
.IncludeStream(streamId)
.IncludeStream(streamId2)
.AddHeader("color", "green")
.AddHeader("opid", 1)
.ApplyAsync();
await theStore.Advanced.ApplyEventDataMasking(x =>
{
x.IncludeStream(streamId)
.IncludeStream(streamId2)
.AddHeader("color", "green")
.AddHeader("opid", 1);
});

// Should apply to this stream
var events = await theSession.Events.FetchStreamAsync(streamId);
Expand Down Expand Up @@ -395,14 +401,14 @@ public static Task apply_masking_to_streams(IDocumentStore store, Guid streamId,
{
return store
.Advanced
.ApplyEventDataMasking()
.IncludeStream(streamId)

// You can add or modify event metadata headers as well
// BUT, you'll of course need event header tracking to be enabled
.AddHeader("masked", DateTimeOffset.UtcNow)
.ApplyEventDataMasking(x =>
{
x.IncludeStream(streamId);

.ApplyAsync(token);
// You can add or modify event metadata headers as well
// BUT, you'll of course need event header tracking to be enabled
x.AddHeader("masked", DateTimeOffset.UtcNow);
}, token);
}

#endregion
Expand All @@ -411,9 +417,10 @@ public static Task apply_masking_to_streams(IDocumentStore store, Guid streamId,

public static Task apply_masking_by_filter(IDocumentStore store, Guid[] streamIds)
{
return store.Advanced.ApplyEventDataMasking()
.IncludeEvents(e => e.EventTypesAre(typeof(QuestStarted)) && e.StreamId.IsOneOf(streamIds))
.ApplyAsync();
return store.Advanced.ApplyEventDataMasking(x =>
{
x.IncludeEvents(e => e.EventTypesAre(typeof(QuestStarted)) && e.StreamId.IsOneOf(streamIds));
});
}

#endregion
Expand All @@ -424,14 +431,14 @@ public static Task apply_masking_by_tenant(IDocumentStore store, string tenantId
{
return store
.Advanced
.ApplyEventDataMasking()
.IncludeStream(streamId)

// Specify the tenant id, and it doesn't matter
// in what order this appears in
.ForTenant(tenantId)
.ApplyEventDataMasking(x =>
{
x.IncludeStream(streamId);

.ApplyAsync();
// Specify the tenant id, and it doesn't matter
// in what order this appears in
x.ForTenant(tenantId);
});
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/LinqTests/Acceptance/Support/SelectTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public SelectTransform(Expression<Func<Target, T>> selector)

public override async Task Compare(IQuerySession session, Target[] documents, TestOutputMartenLogger logger)
{
var target = documents.FirstOrDefault(x => x.StringArray?.Length > 0 && x.NumberArray?.Length > 0 && x.Inner != null);
var expected = documents.Select(_selector.CompileFast()).Take(1).Single();
var target = documents.OrderBy(x => x.Id).FirstOrDefault(x => x.StringArray?.Length > 0 && x.NumberArray?.Length > 0 && x.Inner != null);
var expected = documents.Where(x => x.Id == target.Id).Select(_selector.CompileFast()).Take(1).Single();

var actual = await session.Query<Target>().Where(x => x.Id == target.Id).Select(_selector).SingleAsync();

Expand Down
7 changes: 6 additions & 1 deletion src/Marten/AdvancedOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,10 @@ public async Task<TablePartitionStatus[]> AddMartenManagedTenantsAsync(Cancellat
/// in the event store
/// </summary>
/// <returns></returns>
public IEventDataMasking ApplyEventDataMasking() => new EventDataMasking(_store);
public Task ApplyEventDataMasking(Action<IEventDataMasking> configure, CancellationToken token = default)
{
var masking = new EventDataMasking(_store);
configure(masking);
return masking.ApplyAsync(token);
}
}
8 changes: 0 additions & 8 deletions src/Marten/Events/Protected/EventDataMasking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,4 @@ public interface IEventDataMasking
/// <param name="value"></param>
/// <returns></returns>
IEventDataMasking AddHeader(string key, object value);

/// <summary>
/// Actually execute and apply data protection masking to all the events
/// matching the criteria specified by this expression
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task ApplyAsync(CancellationToken token = default);
}

0 comments on commit d40e549

Please sign in to comment.