Ejemplo n.º 1
0
        public async Task read_head_link_no_messages(string stream, string baseAddress, HttpStatusCode statusCode)
        {
            using (var firstResponse = await _fixture.HttpClient.GetAsync($"{baseAddress}{stream}"))
                using (var response = await _fixture.HttpClient.GetAsync($"{baseAddress}{firstResponse.Headers.Location}"))
                {
                    response.StatusCode.ShouldBe(statusCode);
                    var eTag = IsAllStream(stream)
                    ? ETag.FromPosition(Position.End)
                    : ETag.FromStreamVersion(StreamVersion.End);
                    response.Headers.ETag.ShouldBe(new EntityTagHeaderValue(eTag));

                    var resource = await response.AsHal();

                    resource.ShouldLink(Constants.Relations.Self, $"{stream}?{LastLinkQuery}");

                    resource.ShouldLink(Constants.Relations.Last, $"{stream}?{LastLinkQuery}");

                    resource.ShouldLink(Constants.Relations.First, $"{stream}?{FirstLinkQuery}");

                    resource.ShouldLink(Constants.Relations.Feed, $"{stream}?{LastLinkQuery}");

                    if (!IsAllStream($"{baseAddress}{stream}"))
                    {
                        resource.ShouldLink(Constants.Relations.Metadata, $"{stream}/metadata");
                    }
                }
        }
Ejemplo n.º 2
0
        public async Task read_head_link_when_multiple_pages(string path, string root)
        {
            var result = await _fixture.WriteNMessages(StreamId, 30);

            using (var response = await _fixture.HttpClient.GetAsync($"{path}"))
            {
                response.StatusCode.ShouldBe(HttpStatusCode.OK);
                var eTag = IsAllStream(path)
                    ? ETag.FromPosition(result.CurrentPosition)
                    : ETag.FromStreamVersion(result.CurrentVersion);
                response.Headers.ETag.ShouldBe(new EntityTagHeaderValue(eTag));

                var resource = await response.AsHal();

                var links = Links
                            .FromRequestMessage(response.RequestMessage)
                            .Index()
                            .Find()
                            .Add(Constants.Relations.Self, $"{path}?{LastLinkQuery}", !IsAllStream(path) ? StreamId : null)
                            .Add(Constants.Relations.Last, $"{path}?{LastLinkQuery}")
                            .Add(Constants.Relations.Previous, $"{path}?d=b&m=20&p=9&e=0")
                            .Add(Constants.Relations.First, $"{path}?{FirstLinkQuery}")
                            .Add(Constants.Relations.Feed, $"{path}?{LastLinkQuery}", !IsAllStream(path) ? StreamId : null);

                if (!IsAllStream($"{path}"))
                {
                    links.Add(Constants.Relations.Metadata, $"{path}/metadata");
                }

                resource.ShouldLink(links);
            }
        }
Ejemplo n.º 3
0
        public async Task read_first_link(string stream, string baseAddress)
        {
            var result = await _fixture.WriteNMessages("a-stream", 10);

            using (var response = await _fixture.HttpClient.GetAsync($"{baseAddress}{stream}?{FirstLinkQuery}"))
            {
                response.StatusCode.ShouldBe(HttpStatusCode.OK);
                var eTag = IsAllStream(stream)
                    ? ETag.FromPosition(result.CurrentPosition)
                    : ETag.FromStreamVersion(result.CurrentVersion);
                response.Headers.ETag.ShouldBe(new EntityTagHeaderValue(eTag));

                var resource = await response.AsHal();

                resource.ShouldLink(Constants.Relations.Self, $"{stream}?{FirstLinkQuery}");

                resource.ShouldLink(Constants.Relations.Last, $"{stream}?{LastLinkQuery}");

                resource.ShouldLink(Constants.Relations.First, $"{stream}?{FirstLinkQuery}");

                resource.ShouldLink(Constants.Relations.Feed, $"{stream}?{FirstLinkQuery}");

                if (!IsAllStream($"{baseAddress}{stream}"))
                {
                    resource.ShouldLink(Constants.Relations.Metadata, $"{stream}/metadata");
                }
            }
        }
Ejemplo n.º 4
0
        public async Task read_head_link_no_messages(string path, string root, HttpStatusCode statusCode)
        {
            using (var response = await _fixture.HttpClient.GetAsync(path))
            {
                response.StatusCode.ShouldBe(statusCode);
                var eTag = IsAllStream(path)
                    ? ETag.FromPosition(Position.End)
                    : ETag.FromStreamVersion(StreamVersion.End);
                response.Headers.ETag.ShouldBe(new EntityTagHeaderValue(eTag));

                var resource = await response.AsHal();

                var links = Links
                            .FromRequestMessage(response.RequestMessage)
                            .Index()
                            .Find()
                            .Add(Constants.Relations.Self, $"{path}?{LastLinkQuery}", !IsAllStream(path) ? StreamId : null)
                            .Add(Constants.Relations.Last, $"{path}?{LastLinkQuery}")
                            .Add(Constants.Relations.First, $"{path}?{FirstLinkQuery}")
                            .Add(Constants.Relations.Feed, $"{path}?{LastLinkQuery}", !IsAllStream(path) ? StreamId : null);

                if (!IsAllStream(path))
                {
                    links.Add(Constants.Relations.Metadata, $"{path}/metadata");
                }

                resource.ShouldLink(links);
            }
        }