-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from thefringeninja/inenumerable
Fixed Enumerator Exception Being Overridden w/ DeadlineExceeded
- Loading branch information
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/EventStore.Client.Streams.Tests/append_to_stream_when_events_enumerator_throws.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace EventStore.Client { | ||
public class append_to_stream_when_events_enumerator_throws | ||
: IClassFixture<append_to_stream_when_events_enumerator_throws.Fixture> { | ||
private readonly Fixture _fixture; | ||
|
||
public append_to_stream_when_events_enumerator_throws(Fixture fixture) { | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public void throws_the_exception() { | ||
Assert.IsType<EnumerationFailedException>(_fixture.CaughtException); | ||
} | ||
|
||
[Fact] | ||
public async Task the_write_does_not_succeed() { | ||
var result = _fixture.Client.ReadStreamAsync(Direction.Forwards, _fixture.StreamName, StreamPosition.Start); | ||
Assert.Equal(ReadState.StreamNotFound, await result.ReadState); | ||
} | ||
|
||
private class EnumerationFailedException : Exception { | ||
} | ||
|
||
public class Fixture : EventStoreClientFixture { | ||
public string StreamName { get; } | ||
|
||
public Fixture() { | ||
StreamName = GetStreamName("stream"); | ||
} | ||
|
||
public Exception CaughtException { get; private set; } | ||
|
||
protected override async Task Given() { | ||
try { | ||
await Client.AppendToStreamAsync(StreamName, StreamRevision.None, Events()); | ||
} catch (Exception ex) { | ||
CaughtException = ex; | ||
} | ||
|
||
IEnumerable<EventData> Events() { | ||
var i = 0; | ||
foreach (var e in CreateTestEvents(5)) { | ||
if (i++ % 3 == 0) { | ||
throw new EnumerationFailedException(); | ||
} | ||
|
||
yield return e; | ||
} | ||
} | ||
} | ||
|
||
protected override Task When() => Task.CompletedTask; | ||
} | ||
} | ||
} |