Example #1
0
        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);
            }
        }
Example #2
0
        public async Task Find()
        {
            using (var httpTest = new HttpTest())
            {
                var a    = new List <Rebel>();
                var newR = await _rebels.FindAsync("1");

                httpTest
                .ShouldHaveCalled("http://localhost/rebels/1")
                .WithoutQueryParam("conflicts")
                .WithVerb(HttpMethod.Get);
            }
        }
Example #3
0
        public async Task Attachment()
        {
            using (var client = new CouchClient("http://*****:*****@"{runningPath}\Assets\luke.txt", MediaTypeNames.Text.Plain);
                luke = await rebels.CreateAsync(luke).ConfigureAwait(false);

                Assert.Equal("Luke", luke.Name);
                Assert.NotEmpty(luke.Attachments);

                CouchAttachment attachment = luke.Attachments.First();
                Assert.NotNull(attachment);
                Assert.NotNull(attachment.Uri);

                // Download
                var downloadFilePath = await rebels.DownloadAttachment(attachment, $@"{runningPath}\Assets", "luke-downloaded.txt");

                Assert.True(File.Exists(downloadFilePath));
                File.Delete(downloadFilePath);

                // Find
                luke = await rebels.FindAsync(luke.Id).ConfigureAwait(false);

                Assert.Equal(19, luke.Age);
                attachment = luke.Attachments.First();
                Assert.NotNull(attachment);
                Assert.NotNull(attachment.Uri);
                Assert.NotNull(attachment.Digest);
                Assert.NotNull(attachment.Length);

                // Update
                luke.Surname = "Skywalker";
                luke         = await rebels.CreateOrUpdateAsync(luke).ConfigureAwait(false);

                Assert.Equal("Skywalker", luke.Surname);

                await client.DeleteDatabaseAsync <Rebel>().ConfigureAwait(false);
            }
        }
Example #4
0
        public async Task Find()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new
                {
                    Attachments = new Dictionary <string, object>
                    {
                        { "luke.txt", new { ContentType = "text/plain" } }
                    }
                });

                var a    = new List <Rebel>();
                var newR = await _rebels.FindAsync("1");

                httpTest
                .ShouldHaveCalled("http://localhost/rebels/1")
                .WithoutQueryParam("conflicts")
                .WithVerb(HttpMethod.Get);
            }
        }
Example #5
0
        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 <Publisher> GetPublisher(string publisherId)
        {
            var publisher = await _publisherdatabase.FindAsync(publisherId.ToString());

            return(publisher);
        }