From a52981af9b4727fd7cf776357c39aaeac2fb7c21 Mon Sep 17 00:00:00 2001 From: Dhiren Sham Date: Thu, 30 May 2024 17:03:56 +0200 Subject: [PATCH 1/2] Get/Set _revs_limit --- src/CouchDB.Driver/CouchDatabase.cs | 29 +++++++++++++++++++ src/CouchDB.Driver/ICouchDatabase.cs | 15 ++++++++++ .../Database_Tests.cs | 23 +++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/src/CouchDB.Driver/CouchDatabase.cs b/src/CouchDB.Driver/CouchDatabase.cs index 9430c92..2bfcb00 100644 --- a/src/CouchDB.Driver/CouchDatabase.cs +++ b/src/CouchDB.Driver/CouchDatabase.cs @@ -27,6 +27,7 @@ using System.Text.RegularExpressions; using CouchDB.Driver.Views; using CouchDB.Driver.DatabaseApiMethodOptions; +using System.Net.Mail; namespace CouchDB.Driver { @@ -717,6 +718,34 @@ public async Task GetInfoAsync(CancellationToken cancellation .ConfigureAwait(false); } + /// + public async Task GetRevisionLimitAsync(CancellationToken cancellationToken = default) + { + return Convert.ToInt32(await NewRequest() + .AppendPathSegment("_revs_limit") + .GetStringAsync(cancellationToken) + .SendRequestAsync() + .ConfigureAwait(false)); + } + + /// + public async Task SetRevisionLimitAsync(int limit, CancellationToken cancellationToken = default) + { + using var content = new StringContent(limit.ToString()); + + OperationResult result = await NewRequest() + .AppendPathSegment("_revs_limit") + .PutAsync(content, cancellationToken) + .ReceiveJson() + .SendRequestAsync() + .ConfigureAwait(false); + + if (!result.Ok) + { + throw new CouchException("Something wrong happened while updating the revision limit."); + } + } + #endregion #region Override diff --git a/src/CouchDB.Driver/ICouchDatabase.cs b/src/CouchDB.Driver/ICouchDatabase.cs index 3103566..2596dde 100644 --- a/src/CouchDB.Driver/ICouchDatabase.cs +++ b/src/CouchDB.Driver/ICouchDatabase.cs @@ -295,6 +295,21 @@ Task DownloadAttachmentAsync(CouchAttachment attachment, string localFol /// A task that represents the asynchronous operation. The task result contains the database information. Task GetInfoAsync(CancellationToken cancellationToken = default); + /// + /// Gets the revision limit for the specified database. + /// + /// A to observe while waiting for the task to complete. + /// A task that represents the asynchronous operation. The task result contains the database information. + Task GetRevisionLimitAsync(CancellationToken cancellationToken = default); + + /// + /// Sets the revision limit for the specified database. + /// + /// The limit to set. + /// A to observe while waiting for the task to complete. + /// A task that represents the asynchronous operation. The task result contains the database information. + Task SetRevisionLimitAsync(int limit, CancellationToken cancellationToken = default); + /// /// Get an empty request that targets the current database. /// diff --git a/tests/CouchDB.Driver.UnitTests/Database_Tests.cs b/tests/CouchDB.Driver.UnitTests/Database_Tests.cs index f37653e..803564c 100644 --- a/tests/CouchDB.Driver.UnitTests/Database_Tests.cs +++ b/tests/CouchDB.Driver.UnitTests/Database_Tests.cs @@ -709,6 +709,29 @@ public async Task SecurityInfo_Put() .WithRequestJson(securityInfo); } + + [Fact] + public async Task GetRevLimit() + { + using var httpTest = new HttpTest(); + await _rebels.GetRevisionLimitAsync(); + httpTest + .ShouldHaveCalled("http://localhost/rebels/_rev_limit") + .WithVerb(HttpMethod.Get); + } + + [Fact] + public async Task SetRevLimit() + { + using var httpTest = new HttpTest(); + // Operation response + httpTest.RespondWithJson(new { ok = true }); + + await _rebels.SetRevisionLimitAsync(10); + httpTest + .ShouldHaveCalled("http://localhost/rebels/_rev_limit") + .WithVerb(HttpMethod.Put); + } #endregion public ValueTask DisposeAsync() From d1a6c7628614649db0b99fc558fb57efa1477998 Mon Sep 17 00:00:00 2001 From: Dhiren Sham Date: Thu, 30 May 2024 17:07:11 +0200 Subject: [PATCH 2/2] Remove accidental using statement --- src/CouchDB.Driver/CouchDatabase.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CouchDB.Driver/CouchDatabase.cs b/src/CouchDB.Driver/CouchDatabase.cs index 2bfcb00..79a54ec 100644 --- a/src/CouchDB.Driver/CouchDatabase.cs +++ b/src/CouchDB.Driver/CouchDatabase.cs @@ -27,7 +27,6 @@ using System.Text.RegularExpressions; using CouchDB.Driver.Views; using CouchDB.Driver.DatabaseApiMethodOptions; -using System.Net.Mail; namespace CouchDB.Driver {