コード例 #1
0
        public async Task GetOrCreateDatabase_InvalidCharacters_ThrowsArgumentException()
        {
            using var httpTest = new HttpTest();
            // Operation result
            httpTest.RespondWithJson(new { ok = true });
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            Func <Task> action = () => client.GetOrCreateDatabaseAsync <Rebel>("rebel.");
            var         ex     = await Assert.ThrowsAsync <ArgumentException>(action);

            Assert.Contains("invalid characters", ex.Message);
        }
コード例 #2
0
        public async Task GetOrCreateDatabase_CustomName()
        {
            using var httpTest = new HttpTest();
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            httpTest.RespondWithJson(new { ok = true });
            var rebels = await client.GetOrCreateDatabaseAsync <Rebel>("some_rebels");

            httpTest
            .ShouldHaveCalled("http://localhost/some_rebels")
            .WithVerb(HttpMethod.Put);
            Assert.Equal("some_rebels", rebels.Database);
        }
コード例 #3
0
        public async Task GetOrCreateDatabase_CustomCharacterName()
        {
            var databaseName = "rebel0_$()+/-";

            using var httpTest = new HttpTest();
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            httpTest.RespondWithJson(new { ok = true });
            var rebels = await client.GetOrCreateDatabaseAsync <Rebel>(databaseName);

            httpTest
            .ShouldHaveCalled("http://localhost/rebel0_%24%28%29%2B%2F-")
            .WithVerb(HttpMethod.Put);
            Assert.Equal(databaseName, rebels.Database);
        }
コード例 #4
0
        public async Task GetOrCreateDatabase_402_ReturnDatabase()
        {
            using var httpTest = new HttpTest();
            // Operation result
            httpTest.RespondWith(string.Empty, 412);
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var rebels = await client.GetOrCreateDatabaseAsync <Rebel>();

            Assert.NotNull(rebels);

            httpTest
            .ShouldHaveCalled("http://localhost/rebels")
            .WithVerb(HttpMethod.Put);
            Assert.Equal("rebels", rebels.Database);
        }