public async Task Users() { using (var client = new CouchClient("http://localhost:5984")) { IEnumerable <string> dbs = await client.GetDatabasesNamesAsync().ConfigureAwait(false); CouchDatabase <CouchUser> users = client.GetUsersDatabase(); if (!dbs.Contains(users.Database)) { users = await client.CreateDatabaseAsync <CouchUser>().ConfigureAwait(false); } CouchUser luke = await users.CreateAsync(new CouchUser(name : "luke", password : "******")).ConfigureAwait(false); Assert.Equal("luke", luke.Name); luke = await users.FindAsync(luke.Id).ConfigureAwait(false); Assert.Equal("luke", luke.Name); await users.DeleteAsync(luke).ConfigureAwait(false); luke = await users.FindAsync(luke.Id).ConfigureAwait(false); Assert.Null(luke); await client.DeleteDatabaseAsync <CouchUser>().ConfigureAwait(false); } }
public async Task <JsonResult> DeleteAsync(string id, string rev) { try { //se não houve campos para serem listados, deverá retornar a lista vazia. if (Guid.Equals(id, Guid.Empty)) { throw new Exception("Parâmetros inválidos!"); } //conectar no banco de dados. CouchClient couchClient = new CouchClient(connectionString); CouchDatabase couchDataBase = await couchClient.GetDatabaseAsync(dataBase); //remove o documento. CouchResponse couchResponse = await couchDataBase.DeleteAsync(id, rev); //verifica se houve a exclusão if (couchResponse.StatusCode == HttpStatusCode.Accepted || couchResponse.StatusCode == HttpStatusCode.OK) { return(new JsonResult("Ok")); } else { //retorna o erro ocorrido durante a pesquisa do CouchDB return(new JsonResult(couchResponse.Content)); } } catch (Exception ex) { return(new JsonResult(ex.Message)); } }
public async Task Delete() { using (var httpTest = new HttpTest()) { // Operation response httpTest.RespondWithJson(new { ok = true }); var r = new Rebel { Name = "Luke", Id = "1", Rev = "1" }; await _rebels.DeleteAsync(r); httpTest .ShouldHaveCalled("http://localhost/rebels/1?rev=1") .WithVerb(HttpMethod.Delete); } }
public async Task Crud_SpecialCharacters() { var databaseName = "rebel0_$()+/-"; using (var client = new CouchClient("http://localhost:5984")) { IEnumerable <string> dbs = await client.GetDatabasesNamesAsync().ConfigureAwait(false); CouchDatabase <Rebel> rebels = client.GetDatabase <Rebel>(databaseName); if (dbs.Contains(rebels.Database)) { await client.DeleteDatabaseAsync <Rebel>(databaseName).ConfigureAwait(false); } rebels = await client.CreateDatabaseAsync <Rebel>(databaseName).ConfigureAwait(false); Rebel luke = await rebels.CreateAsync(new Rebel { Name = "Luke", Age = 19 }).ConfigureAwait(false); Assert.Equal("Luke", luke.Name); luke.Surname = "Skywalker"; luke = await rebels.CreateOrUpdateAsync(luke).ConfigureAwait(false); Assert.Equal("Skywalker", luke.Surname); luke = await rebels.FindAsync(luke.Id).ConfigureAwait(false); Assert.Equal(19, luke.Age); await rebels.DeleteAsync(luke).ConfigureAwait(false); luke = await rebels.FindAsync(luke.Id).ConfigureAwait(false); Assert.Null(luke); await client.DeleteDatabaseAsync <Rebel>(databaseName).ConfigureAwait(false); } }
public async Task DeletePublisher(Publisher publisher) { await _publisherdatabase.DeleteAsync(publisher); }