Пример #1
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);
            }
        }
Пример #2
0
        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.CreateOrUpdateAsync(r);

                Types.CouchAttachment lukeTxt = r.Attachments.First();
                var newPath = await _rebels.DownloadAttachment(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", "xxx");

                Assert.Equal(@"anyfolder\luke.txt", newPath);
            }
        }