This repository was archived by the owner on Feb 16, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathread_event_should.cs
More file actions
119 lines (100 loc) · 4.6 KB
/
Copy pathread_event_should.cs
File metadata and controls
119 lines (100 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using EventStore.ClientAPI;
using NUnit.Framework;
namespace EventStore.Core.Tests.ClientAPI
{
[TestFixture, Category("LongRunning")]
public class read_event_should : SpecificationWithConnection
{
private Guid _eventId0;
private Guid _eventId1;
protected override void When()
{
_eventId0 = Guid.NewGuid();
_eventId1 = Guid.NewGuid();
_conn.AppendToStreamAsync("test-stream",
-1,
new EventData(_eventId0, "event0", false, new byte[3], new byte[2]),
new EventData(_eventId1, "event1", true, new byte[7], new byte[10]))
.Wait();
_conn.DeleteStreamAsync("deleted-stream", -1, hardDelete: true).Wait();
}
[Test, Category("Network")]
public void throw_if_stream_id_is_null()
{
Assert.ThrowsAsync<ArgumentNullException>(() => _conn.ReadEventAsync(null, 0, resolveLinkTos: false));
}
[Test, Category("Network")]
public void throw_if_stream_id_is_empty()
{
Assert.ThrowsAsync<ArgumentNullException>(() => _conn.ReadEventAsync("", 0, resolveLinkTos: false));
}
[Test, Category("Network")]
public void throw_if_event_number_is_less_than_minus_one()
{
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => _conn.ReadEventAsync("stream", -2, resolveLinkTos: false));
}
[Test, Category("Network")]
public void notify_using_status_code_if_stream_not_found()
{
var res = _conn.ReadEventAsync("unexisting-stream", 5, false).Result;
Assert.AreEqual(EventReadStatus.NoStream, res.Status);
Assert.IsNull(res.Event);
Assert.AreEqual("unexisting-stream", res.Stream);
Assert.AreEqual(5, res.EventNumber);
}
[Test, Category("Network")]
public void return_no_stream_if_requested_last_event_in_empty_stream()
{
var res = _conn.ReadEventAsync("some-really-empty-stream", -1, false).Result;
Assert.AreEqual(EventReadStatus.NoStream, res.Status);
}
[Test, Category("Network")]
public void notify_using_status_code_if_stream_was_deleted()
{
var res = _conn.ReadEventAsync("deleted-stream", 5, false).Result;
Assert.AreEqual(EventReadStatus.StreamDeleted, res.Status);
Assert.IsNull(res.Event);
Assert.AreEqual("deleted-stream", res.Stream);
Assert.AreEqual(5, res.EventNumber);
}
[Test, Category("Network")]
public void notify_using_status_code_if_stream_does_not_have_event()
{
var res = _conn.ReadEventAsync("test-stream", 5, false).Result;
Assert.AreEqual(EventReadStatus.NotFound, res.Status);
Assert.IsNull(res.Event);
Assert.AreEqual("test-stream", res.Stream);
Assert.AreEqual(5, res.EventNumber);
}
[Test, Category("Network")]
public void return_existing_event()
{
var res = _conn.ReadEventAsync("test-stream", 0, false).Result;
Assert.AreEqual(EventReadStatus.Success, res.Status);
Assert.AreEqual(res.Event.Value.OriginalEvent.EventId, _eventId0);
Assert.AreEqual("test-stream", res.Stream);
Assert.AreEqual(0, res.EventNumber);
Assert.AreNotEqual(DateTime.MinValue, res.Event.Value.OriginalEvent.Created);
Assert.AreNotEqual(0, res.Event.Value.OriginalEvent.CreatedEpoch);
}
[Test, Category("Network")]
public void retrieve_the_is_json_flag_properly() {
var res = _conn.ReadEventAsync("test-stream", 1, false).Result;
Assert.AreEqual(EventReadStatus.Success, res.Status);
Assert.AreEqual(res.Event.Value.OriginalEvent.EventId, _eventId1);
Assert.IsTrue(res.Event.Value.OriginalEvent.IsJson);
}
[Test, Category("Network")]
public void return_last_event_in_stream_if_event_number_is_minus_one()
{
var res = _conn.ReadEventAsync("test-stream", -1, false).Result;
Assert.AreEqual(EventReadStatus.Success, res.Status);
Assert.AreEqual(res.Event.Value.OriginalEvent.EventId, _eventId1);
Assert.AreEqual("test-stream", res.Stream);
Assert.AreEqual(-1, res.EventNumber);
Assert.AreNotEqual(DateTime.MinValue, res.Event.Value.OriginalEvent.Created);
Assert.AreNotEqual(0, res.Event.Value.OriginalEvent.CreatedEpoch);
}
}
}