Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

Commit 9fbcb93

Browse files
Support for getting design docs (#203)
Fixes support for retrieving _design docs No matter what infra there is. Replaces the Follow construct, but keeps that fix in as a fallback.
1 parent 38bb3a2 commit 9fbcb93

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = crlf
5+
insert_final_newline = true
6+
indent_style = space
7+
8+
[*.props, *.csproj, *.yml, *.json]
9+
indent_size = 2
10+
11+
[*.cs]
12+
indent_size = 4

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
*.local.json
1818
*.local.ini
1919

20-
# deploy
21-
[Aa]rtifacts/
22-
2320
# misc
2421
*~
2522
*.swp
2623
*.sdf
2724
*.orig
2825
*.pfx
2926

27+
# rider
28+
.idea
29+
30+
# vs-code
31+
.vscode
32+
3033
# resharper
3134
_ReSharper.*
3235
*.resharper*

clean.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git clean -dfx -e clean.sh -e source/tests/IntegrationTests/integrationtests.local.ini -e .env
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
User=sample_user
1+
User=sample_user
22
Pass=sample_password

source/projects/MyCouch/Net/Connection.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ protected virtual void OnAfterSend(HttpResponseMessage httpResponse)
164164

165165
protected virtual string GenerateRequestUri(HttpRequest httpRequest)
166166
{
167-
return $"{Address.ToString().TrimEnd('/')}/{httpRequest.RelativeUrl.TrimStart('/')}";
167+
var relative = httpRequest.RelativeUrl.TrimStart('/');
168+
169+
return relative.StartsWith("_design%2F")
170+
? $"{Address.ToString().TrimEnd('/')}/{Uri.UnescapeDataString(relative)}"
171+
: $"{Address.ToString().TrimEnd('/')}/{relative}";
168172
}
169173
}
170174
}

source/tests/IntegrationTests/CoreTests/ViewsTests.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
using System.Threading.Tasks;
23
using FluentAssertions;
34
using IntegrationTests.TestFixtures;
45
using MyCouch;
@@ -21,6 +22,16 @@ public ViewsTests(ViewsFixture data)
2122
ArtistsById = data.Init(Environment);
2223
SUT = DbClient.Views;
2324
}
25+
26+
[MyFact(TestScenarios.ViewsContext)]
27+
public async Task Can_retrieve_views()
28+
{
29+
var id = $"_design/{ClientTestData.Views.ArtistsAlbumsViewId.DesignDocument}";
30+
31+
var response = await DbClient.Documents.GetAsync(id);
32+
33+
response.Should().BeSuccessfulGetAnyRev(id);
34+
}
2435

2536
[MyFact(TestScenarios.ViewsContext)]
2637
public void When_no_key_with_sum_reduce_for_string_response_It_will_be_able_to_sum()
@@ -378,4 +389,4 @@ public void When_query_as_for_raw_It_shall_return_raw_result()
378389
response.Should().BeGetOfJson();
379390
}
380391
}
381-
}
392+
}

source/tests/Testing/Shoulds.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public DocumentResponseAssertions(DocumentResponse response)
492492
Response = response;
493493
}
494494

495-
public void BeSuccessfulGet(string id, string rev)
495+
private void SuccessfulGet(string id, string rev = null)
496496
{
497497
Response.RequestMethod.Should().Be(HttpMethod.Get);
498498
Response.IsSuccess.Should().BeTrue("StatusCode:" + Response.StatusCode);
@@ -503,8 +503,13 @@ public void BeSuccessfulGet(string id, string rev)
503503
Response.Content.Should().NotBeNullOrEmpty();
504504
Response.Id.Should().NotBeNullOrEmpty().And.Be(id);
505505
Response.Rev.Should().NotBeNullOrEmpty();
506-
Response.Rev.Should().Be(rev);
506+
if(rev != null)
507+
Response.Rev.Should().Be(rev);
507508
}
509+
510+
public void BeSuccessfulGet(string id, string rev) => SuccessfulGet(id, rev);
511+
512+
public void BeSuccessfulGetAnyRev(string id) => SuccessfulGet(id);
508513
}
509514

510515
public class AttachmentResponseAssertions
@@ -689,4 +694,4 @@ public void BeSuccessfulGet()
689694
Response.LastSeq.Should().NotBeNullOrEmpty();
690695
}
691696
}
692-
}
697+
}

0 commit comments

Comments
 (0)