Esempio n. 1
0
 public void SetupSingleTest()
 {
     dbname = "prova" + DateTime.UtcNow.Ticks;
     // to make this test work, you should configure couchdb to bind 0.0.0.0
     // not using 127.0.0.1 or localhost to enable capturing traffic with fiddler2
     client = new Cuscino.CouchClient("http://localhost:5984", dbname, "", "");
     client.CreateDatabaseIfNotExists();
 }
Esempio n. 2
0
        public async Task PropertyName_JsonProperty()
        {
            using var httpTest = new HttpTest();
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var rebels = client.GetDatabase <OtherRebel>();
            var json   = rebels.Where(r => r.BirthDate == new DateTime(2000, 1, 1)).ToString();

            Assert.Equal(@"{""selector"":{""rebel_bith_date"":""2000-01-01T00:00:00""}}", json);
        }
Esempio n. 3
0
        public void Setup()
        {
            client = new CouchClient(host, port, username, password, false, AuthenticationType.Cookie);
            if (!client.HasDatabase(baseDatabase))
            {
                client.CreateDatabase(baseDatabase);
            }

            var uriBuilder = new UriBuilder("http", host, port, baseDatabase);

            db = new CouchDatabase(uriBuilder.Uri);
        }
Esempio n. 4
0
        public static async Task RunAsync()
        {
            var cs     = CouchDB.Client.Helper.GetConnectionString();
            var client = new CouchClient(cs);

            // get database
            var db = await client.GetDatabaseAsync("temp");

            var d = await db.SelectAsync();

            Thread.Sleep(Timeout.Infinite);
        }
Esempio n. 5
0
 public void Setup()
 {
     client = new CouchClient(host, port, username, password, false, AuthenticationType.Cookie);
     if (!client.HasDatabase(baseDatabase))
     {
         client.CreateDatabase(baseDatabase);
     }
     if (!client.HasDatabase(replicateDatabase))
     {
         client.CreateDatabase(replicateDatabase);
     }
 }
Esempio n. 6
0
        public async Task PropertyName_Camelization()
        {
            using var httpTest = new HttpTest();
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var rebels = client.GetDatabase <Rebel>();
            var json   = rebels.Where(r => r.Age == 19).ToString();

            Assert.Equal(@"{""selector"":{""age"":19}}", json);
        }
Esempio n. 7
0
        public async Task CreateDatabase_402_ThrowsException()
        {
            using var httpTest = new HttpTest();
            // Operation result
            httpTest.RespondWith((string)null, 412);
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            Func <Task> action = () => client.CreateDatabaseAsync <Rebel>();
            await Assert.ThrowsAsync <CouchException>(action);
        }
        public DataAccess(AuthorContext context, IMongoDbSettings settings, CouchClient couchclient)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));


            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            _books = database.GetCollection <Book>(settings.CollectionName);

            _couchclient       = couchclient;
            _publisherdatabase = _couchclient.GetDatabase <Publisher>();
        }
Esempio n. 9
0
        public override async Task InsertTest()
        {
            var connectionString = "http://localhost:5984/";
            var client           = new CouchClient(connectionString);
            var db = await client.GetDatabaseAsync("benchmark");

            var fakesUsers = UserUtility.GetFakeUsers(Times);

            foreach (var userList in UserUtility.SpiltBySize(fakesUsers, 10000))
            {
                await db.BulkInsertAsync(userList.ToArray());
            }
        }
Esempio n. 10
0
        public void Creation_CookieAuthentication()
        {
            using (var httpTest = new HttpTest())
            {
                // Logout
                httpTest.RespondWithJson(new { ok = true });

                using (var client = new CouchClient("http://localhost", s =>
                                                    s.UseCookieAuthentication("root", "relax")))
                {
                    Assert.Equal("http://localhost", client.ConnectionString);
                }
            }
        }
Esempio n. 11
0
        public async Task GetDatabase_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");
            Action action = () => client.GetDatabase <Rebel>("rebel.");
            var    ex     = Assert.Throws <ArgumentException>(action);

            Assert.Contains("invalid characters", ex.Message);
        }
Esempio n. 12
0
 public RoomEditorDb()
 {
     using (JtTimer pt = new JtTimer("RoomEditorDb ctor"))
     {
         if (null == _client)
         {
             _client = new CouchClient(_url_local, 5984);
         }
         if (null == _db)
         {
             _db = _client.GetDatabase(_database_name, true);
         }
     }
 }
Esempio n. 13
0
        public CouchDBClientAdapter LoveSeat(
            string databaseName,
            string host,
            int port,
            string username,
            string password,
            bool ssl)
        {
            // TODO: Load configuration from app.config
            CouchClient   client = new CouchClient(host, port, username, password, ssl, AuthenticationType.Basic);
            CouchDatabase db     = client.GetDatabase(databaseName);

            return(new LoveSeatClientAdapter(db));
        }
Esempio n. 14
0
        public async Task GetDatabase_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 = client.GetDatabase <Rebel>(databaseName);

            Assert.Equal(databaseName, rebels.Database);
        }
Esempio n. 15
0
        public void BadRequestException()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(@"{error: ""no_usable_index""}", (int)HttpStatusCode.BadRequest);

                using (var client = new CouchClient("http://localhost"))
                {
                    var db             = client.GetDatabase <Rebel>();
                    var couchException = Assert.Throws <CouchNoIndexException>(() => db.UseIndex("aoeu").ToList());
                    Assert.IsType <Flurl.Http.FlurlHttpException>(couchException.InnerException);
                }
            }
        }
        public async Task Basic()
        {
            using var httpTest = new HttpTest();
            SetupListResponse(httpTest);

            await using var client = new CouchClient("http://localhost", s => s.UseBasicAuthentication("root", "relax"));
            var rebels = client.GetDatabase <Rebel>();
            var all    = await rebels.ToListAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_find")
            .WithVerb(HttpMethod.Post)
            .WithBasicAuth("root", "relax");
        }
Esempio n. 17
0
        public async Task NotFoundException()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(status: (int)HttpStatusCode.NotFound);

                using (var client = new CouchClient("http://localhost"))
                {
                    var couchException = await Assert.ThrowsAsync <CouchNotFoundException>(() => client.DeleteDatabaseAsync <Rebel>());

                    Assert.IsType <Flurl.Http.FlurlHttpException>(couchException.InnerException);
                }
            }
        }
Esempio n. 18
0
        public async Task ActiveTasks()
        {
            using var httpTest = new HttpTest();
            // Tasks
            httpTest.RespondWithJson(new List <CouchActiveTask>());
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var dbs = await client.GetActiveTasksAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/_active_tasks")
            .WithVerb(HttpMethod.Get);
        }
Esempio n. 19
0
        public async Task DeleteDatabase_CustomCharacterName()
        {
            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");
            await client.DeleteDatabaseAsync("rebel0_$()+/-");

            httpTest
            .ShouldHaveCalled("http://localhost/rebel0_%24%28%29%2B%2F-")
            .WithVerb(HttpMethod.Delete);
        }
Esempio n. 20
0
        public async Task DeleteDatabase_CustomName()
        {
            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");
            await client.DeleteDatabaseAsync("some_rebels");

            httpTest
            .ShouldHaveCalled("http://localhost/some_rebels")
            .WithVerb(HttpMethod.Delete);
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        public async Task CreateDatabaseAsync_Params_Default()
        {
            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.CreateDatabaseAsync <Rebel>(8, 3, false);

            httpTest
            .ShouldHaveCalled("http://localhost/rebels")
            .WithVerb(HttpMethod.Put);
            Assert.Equal("rebels", rebels.Database);
        }
Esempio n. 23
0
        public async Task GenericExceptionNoMessage()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith(status: (int)HttpStatusCode.InternalServerError);

                using (var client = new CouchClient("http://localhost"))
                {
                    var db             = client.GetDatabase <Rebel>();
                    var couchException = await Assert.ThrowsAsync <CouchException>(() => db.FindAsync("aoeu"));

                    Assert.IsType <Flurl.Http.FlurlHttpException>(couchException.InnerException);
                }
            }
        }
        public async Task Proxy()
        {
            using var httpTest = new HttpTest();
            SetupListResponse(httpTest);

            await using var client = new CouchClient("http://localhost", s => s.UseProxyAuthentication("root", new[] { "role1", "role2" }));
            var rebels = client.GetDatabase <Rebel>();
            var all    = await rebels.ToListAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_find")
            .WithVerb(HttpMethod.Post)
            .WithHeader("X-Auth-CouchDB-UserName", "root")
            .WithHeader("X-Auth-CouchDB-Roles", "role1,role2");
        }
Esempio n. 25
0
        public async Task PropertyNullValueHandling_Ignore()
        {
            using var httpTest = new HttpTest();
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost", x => x.JsonNullValueHandling(NullValueHandling.Ignore));
            var rebels = client.GetDatabase <Rebel>();
            await rebels.AddAsync(new Rebel());

            var call = httpTest.CallLog.First();

            Assert.NotNull(call);
            Assert.Equal(@"{""_conflicts"":[],""age"":0,""isJedi"":false,""species"":0,""guid"":""00000000-0000-0000-0000-000000000000""}", call.RequestBody);
        }
Esempio n. 26
0
        public async Task IsNotUp_Timeout()
        {
            using var httpTest = new HttpTest();
            httpTest.SimulateTimeout();
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var result = await client.IsUpAsync();

            Assert.False(result);

            httpTest
            .ShouldHaveCalled($"http://localhost/_up")
            .WithVerb(HttpMethod.Get);
        }
        public async Task Jwt()
        {
            using var httpTest = new HttpTest();
            SetupListResponse(httpTest);

            var jwt = Guid.NewGuid().ToString();

            await using var client = new CouchClient("http://localhost", s => s.UseJwtAuthentication(jwt));
            var rebels = client.GetDatabase <Rebel>();
            var all    = await rebels.ToListAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_find")
            .WithVerb(HttpMethod.Post)
            .WithHeader("Authorization", jwt);
        }
Esempio n. 28
0
        public async Task DocumentName_JsonObject()
        {
            using var httpTest = new HttpTest();
            // Find
            httpTest.RespondWithJson(new { Docs = new List <string>() });
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var rebels = client.GetDatabase <OtherRebel>();
            var all    = await rebels.ToListAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/custom_rebels/_find")
            .WithVerb(HttpMethod.Post);
        }
Esempio n. 29
0
        public async Task DocumentName_PluralizationDisabled()
        {
            using var httpTest = new HttpTest();
            // Find
            httpTest.RespondWithJson(new { Docs = new List <string>() });
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost", s => s.DisableDocumentPluralization());
            var rebels = client.GetDatabase <Rebel>();
            var all    = await rebels.ToListAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/rebel/_find")
            .WithVerb(HttpMethod.Post);
        }
Esempio n. 30
0
        public async Task DatabaseNames()
        {
            using var httpTest = new HttpTest();
            // Databases
            httpTest.RespondWithJson(new[] { "jedi", "sith" });
            // Logout
            httpTest.RespondWithJson(new { ok = true });

            await using var client = new CouchClient("http://localhost");
            var dbs = await client.GetDatabasesNamesAsync();

            httpTest
            .ShouldHaveCalled("http://localhost/_all_dbs")
            .WithVerb(HttpMethod.Get);
            Assert.Equal(new[] { "jedi", "sith" }, dbs);
        }
Esempio n. 31
0
        public async Task GenericExceptionWithMessage()
        {
            using var httpTest = new HttpTest();
            string message = "message text";
            string reason  = "reason text";

            httpTest.RespondWith($"{{error: \"{message}\", reason: \"{reason}\"}}", (int)HttpStatusCode.InternalServerError);

            await using var client = new CouchClient("http://localhost");
            var db             = client.GetDatabase <Rebel>();
            var couchException = await Assert.ThrowsAsync <CouchException>(() => db.CompactAsync());

            Assert.Equal(message, couchException.Message);
            Assert.Equal(reason, couchException.Reason);
            Assert.IsType <Flurl.Http.FlurlHttpException>(couchException.InnerException);
        }
        public void CreateDatabase()
        {
            // Arrange
              _client = new CouchClient(
            host: ConfigurationManager.AppSettings["Host"],
            port: Int32.Parse(ConfigurationManager.AppSettings["Port"]),
            username: ConfigurationManager.AppSettings["Username"],
            password: ConfigurationManager.AppSettings["Password"]
              );
              DeleteDatabase();

              // Act
              _client.GetDatabase(BASE_DB);

              // Assert
              Assert.IsTrue(_client.HasDatabase(BASE_DB));
        }
Esempio n. 33
0
		public static void Setup(TestContext o)
#endif
		{
			client = new CouchClient(aHost: couchdbHostName);

			if (client.HasDatabase(baseDatabase))
			{
				client.DeleteDatabase(baseDatabase);
			}
			client.CreateDatabase(baseDatabase);

			if (client.HasDatabase(replicateDatabase))
			{
				client.DeleteDatabase(replicateDatabase);
			}
			client.CreateDatabase(replicateDatabase);

			CouchDatabase db = client.GetDatabase(baseDatabase);
			CouchDesignDocument view = new CouchDesignDocument("testviewitem");
			view.Views.Add("testview", new CouchView("function(doc) {emit(doc._rev, doc)}"));
			db.CreateDocument(view);

		}
        public void CreateDatabase()
        {
            _client = new CouchClient(
            host: ConfigurationManager.AppSettings["Host"],
            port: Int32.Parse(ConfigurationManager.AppSettings["Port"]),
            username: ConfigurationManager.AppSettings["Username"],
            password: ConfigurationManager.AppSettings["Password"]
              );

              DeleteDatabase();
              _db = _client.GetDatabase(BASE_DB);
        }
Esempio n. 35
0
 public void BeforeEachTest()
 {
     couchClient = new CouchClient(mockConfiguration.Object, mockJsonClient.Object);
     mockConfiguration.Setup(c => c.ServerUri).Returns(testCouchServerUri);
 }