public async Task CreateOrUpdate() { using var httpTest = new HttpTest(); httpTest.RespondWithJson(new { Id = "xxx", Ok = true, Rev = "xxx" }); var r = new Rebel { Name = "Luke", Id = "1" }; var newR = await _rebels.AddOrUpdateAsync(r); httpTest .ShouldHaveCalled("http://localhost/rebels/1") .WithVerb(HttpMethod.Put); }
/// <summary> /// Change the password of the given user. /// </summary> /// <typeparam name="TCouchUser">The type of user.</typeparam> /// <param name="database">The users database.</param> /// <param name="user">The user to update.</param> /// <param name="password">The password.</param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param> /// <returns>A task that represents the asynchronous operation. The task result contains the updated user.</returns> public static Task <TCouchUser> ChangeUserPassword <TCouchUser>(this ICouchDatabase <TCouchUser> database, TCouchUser user, string password, CancellationToken cancellationToken = default) where TCouchUser : CouchUser { Check.NotNull(database, nameof(database)); Check.NotNull(user, nameof(user)); Check.NotNull(password, nameof(password)); user.Password = password; return(database.AddOrUpdateAsync(user, false, cancellationToken)); }
public async Task Crud() { Rebel luke = await _rebels.AddAsync(new Rebel { Name = "Luke", Age = 19 }); Assert.Equal("Luke", luke.Name); luke.Surname = "Skywalker"; luke = await _rebels.AddOrUpdateAsync(luke); Assert.Equal("Skywalker", luke.Surname); luke = await _rebels.FindAsync(luke.Id); Assert.Equal(19, luke.Age); await _rebels.RemoveAsync(luke); luke = await _rebels.FindAsync(luke.Id); Assert.Null(luke); }
public async Task DownloadAttachment() { using var httpTest = new HttpTest(); httpTest.RespondWithJson(new { Id = "1", Ok = true, Rev = "xxx", Attachments = new Dictionary <string, object> { { "luke.txt", new { ContentType = "text/plain" } } } }); httpTest.RespondWithJson(new { Id = "1", Ok = true, Rev = "xxx2", }); var r = new Rebel { Id = "1", Name = "Luke" }; r.Attachments.AddOrUpdate("Assets/luke.txt", MediaTypeNames.Text.Plain); r = await _rebels.AddOrUpdateAsync(r); Types.CouchAttachment lukeTxt = r.Attachments.First(); var newPath = await _rebels.DownloadAttachmentAsync(lukeTxt, "anyfolder"); httpTest .ShouldHaveCalled("http://localhost/rebels/1") .WithVerb(HttpMethod.Put); httpTest .ShouldHaveCalled("http://localhost/rebels/1/luke.txt") .WithVerb(HttpMethod.Put) .WithHeader("If-Match", "xxx"); httpTest .ShouldHaveCalled("http://localhost/rebels/1/luke.txt") .WithVerb(HttpMethod.Get) .WithHeader("If-Match", "xxx2"); Assert.Equal(@"anyfolder\luke.txt", newPath); }