|
| 1 | +#pragma warning disable IDE1006 // Naming Styles |
| 2 | + |
| 3 | +using FluentAssertions; |
| 4 | +using NEventStore.Persistence.AcceptanceTests.BDD; |
| 5 | + |
| 6 | +#if MSTEST |
| 7 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 8 | +#endif |
| 9 | +#if NUNIT |
| 10 | +using NUnit.Framework; |
| 11 | +#endif |
| 12 | +#if XUNIT |
| 13 | +using Xunit; |
| 14 | +#endif |
| 15 | + |
| 16 | +namespace NEventStore.Persistence.AcceptanceTests.Async |
| 17 | +{ |
| 18 | +#if MSTEST |
| 19 | + [TestClass] |
| 20 | +#endif |
| 21 | + public class when_getting_streams_to_snapshot_for_a_bucket_that_shares_stream_ids_with_other_buckets : PersistenceEngineConcernAsync |
| 22 | + { |
| 23 | + private const string BucketAId = "a"; |
| 24 | + private const string BucketBId = "b"; |
| 25 | + private const int Threshold = 2; |
| 26 | + private string? _streamId; |
| 27 | + private StreamHeadObserver? _observer; |
| 28 | + |
| 29 | + protected override async Task ContextAsync() |
| 30 | + { |
| 31 | + _streamId = Guid.NewGuid().ToString(); |
| 32 | + |
| 33 | + var bucketAFirst = _streamId.BuildAttempt(bucketId: BucketAId); |
| 34 | + await Persistence.CommitAsync(bucketAFirst, CancellationToken.None); |
| 35 | + |
| 36 | + var bucketASecond = bucketAFirst.BuildNextAttempt(); |
| 37 | + await Persistence.CommitAsync(bucketASecond, CancellationToken.None); |
| 38 | + |
| 39 | + await Persistence.CommitAsync(_streamId.BuildAttempt(bucketId: BucketBId), CancellationToken.None); |
| 40 | + await Persistence.AddSnapshotAsync(new Snapshot(BucketBId, _streamId, bucketASecond.StreamRevision, "SnapshotB"), CancellationToken.None); |
| 41 | + } |
| 42 | + |
| 43 | + protected override async Task BecauseAsync() |
| 44 | + { |
| 45 | + _observer = new StreamHeadObserver(); |
| 46 | + await Persistence.GetStreamsToSnapshotAsync(BucketAId, Threshold, _observer, CancellationToken.None); |
| 47 | + } |
| 48 | + |
| 49 | + [Fact] |
| 50 | + public void should_return_only_bucket_a_stream_heads() |
| 51 | + { |
| 52 | + _observer!.StreamHeads.Should().ContainSingle(x => x.BucketId == BucketAId && x.StreamId == _streamId); |
| 53 | + _observer.StreamHeads.Should().NotContain(x => x.BucketId == BucketBId); |
| 54 | + } |
| 55 | + |
| 56 | + [Fact] |
| 57 | + public void should_not_let_a_bucket_b_snapshot_hide_bucket_a_snapshot_eligibility() |
| 58 | + { |
| 59 | + _observer!.StreamHeads.Should().ContainSingle(x => x.StreamId == _streamId && x.SnapshotRevision == 0); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +#pragma warning restore IDE1006 // Naming Styles |
0 commit comments