Skip to content

Commit 09cb34a

Browse files
Merge pull request #159 from mwasson74/master
Issue 157 and 158
2 parents 4bffc93 + 036dff5 commit 09cb34a

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/CouchDB.Driver/CouchDatabase.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ internal CouchDatabase(IFlurlClient flurlClient, CouchOptions options, QueryCont
8989
.GetAsync(cancellationToken)
9090
.ConfigureAwait(false);
9191

92-
return response != null && response.StatusCode == (int)HttpStatusCode.OK
93-
? await response.GetJsonAsync<TSource>().ConfigureAwait(false)
94-
: null;
92+
TSource? document = null;
93+
if (response is not { StatusCode: (int)HttpStatusCode.OK })
94+
{
95+
return document;
96+
}
97+
98+
document = await response.GetJsonAsync<TSource>().ConfigureAwait(false);
99+
if (document != null)
100+
{
101+
InitAttachments(document);
102+
}
103+
104+
return document;
95105
}
96106

97107
/// <inheritdoc />

src/CouchDB.Driver/Types/CouchAttachment.cs

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public sealed class CouchAttachment
2626
[JsonIgnore]
2727
public Uri Uri { get; internal set; }
2828

29+
[DataMember]
30+
[JsonProperty("stub")]
31+
public bool Stub { get; set; }
32+
2933
[DataMember]
3034
[JsonProperty("content_type")]
3135
public string ContentType { get; set; }
@@ -37,6 +41,10 @@ public sealed class CouchAttachment
3741
[DataMember]
3842
[JsonProperty("length")]
3943
public int? Length { get; private set; }
44+
45+
[DataMember]
46+
[JsonProperty("revpos")]
47+
public int? RevPos { get; private set; }
4048
}
4149
}
4250
#nullable restore

tests/CouchDB.Driver.UnitTests/Database_Tests.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public async Task Find()
3131
using var httpTest = new HttpTest();
3232
httpTest.RespondWithJson(new
3333
{
34-
Attachments = new Dictionary<string, object>
35-
{
36-
{ "luke.txt", new { ContentType = "text/plain" } }
37-
}
34+
_attachments = new Dictionary<string, object>
35+
{
36+
{ "luke.txt", new { ContentType = "text/plain" } }
37+
}
3838
});
3939

4040
var a = new List<Rebel>();
@@ -43,6 +43,11 @@ public async Task Find()
4343
.ShouldHaveCalled("http://localhost/rebels/1")
4444
.WithoutQueryParam("conflicts")
4545
.WithVerb(HttpMethod.Get);
46+
47+
Assert.NotNull(newR);
48+
Assert.NotEmpty(newR.Attachments);
49+
Assert.NotNull(newR.Attachments["luke.txt"].Uri);
50+
4651
}
4752

4853
[Fact]
@@ -51,10 +56,10 @@ public async Task FindWithConflicts()
5156
using var httpTest = new HttpTest();
5257
httpTest.RespondWithJson(new
5358
{
54-
Attachments = new Dictionary<string, object>
55-
{
56-
{ "luke.txt", new { ContentType = "text/plain" } }
57-
}
59+
_attachments = new Dictionary<string, object>
60+
{
61+
{ "luke.txt", new { ContentType = "text/plain" } }
62+
}
5863
});
5964

6065
var newR = await _rebels.FindAsync("1", true);

0 commit comments

Comments
 (0)