Exemple #1
0
 public void Client_QueryView_ReturnsValues(string values, int greaterThen, int count) => Wrap(async() =>
 {
     var dbName   = GenerateDbName();
     var client   = CreateClient();
     var splitted = values.Split(',');
     await client.CreateDatabase(dbName);
     for (var i = 0; i < splitted.Length; i++)
     {
         await client.Create(dbName, new SimpleObject
         {
             Name  = splitted[0],
             Value = i
         });
     }
     var mapReduce = new CouchMapReduce
     {
         Map = $"function(doc) {{ if(doc.Value > {greaterThen}) {{ emit(doc.Name, doc); }} }}"
     };
     const string designName = "design0";
     const string viewName   = "greater_view";
     await client.CreateDesign(dbName, designName, new[]
     {
         new CouchViewDefinition
         {
             Mapping = mapReduce,
             Name    = viewName
         }
     });
     var result = await client.QueryView <SimpleObject>(dbName, designName, viewName);
     Assert.True(result.Rows.Length == count);
 });
Exemple #2
0
 public void Client_CreateAndQueryTemporaryView_ReturnsValues(string values, int greaterThen, int count)
 => Wrap(async() =>
 {
     var dbName   = GenerateDbName();
     var client   = CreateClient();
     var splitted = values.Split(',');
     await client.CreateDatabase(dbName);
     for (var i = 0; i < splitted.Length; i++)
     {
         await client.Create(dbName, new SimpleObject
         {
             Name  = splitted[0],
             Value = i
         });
     }
     var mapReduce = new CouchMapReduce
     {
         Map = $"function(doc) {{ if(doc.Value > {greaterThen}) {{ emit(doc.Name, doc); }} }}"
     };
     var result = await client.CreateAndQueryTemporaryView <SimpleObject>(dbName, mapReduce);
     Assert.True(result.Rows.Length == count);
 });
Exemple #3
0
        public async Task <CouchView <T> > CreateAndQueryTemporaryView <T>(string db, CouchMapReduce couchMapReduce, string fromKey = null, string toKey = null)
        {
            try
            {
                var result = await RequestDatabase(new Uri(_host, $"{db}/_temp_view" + GetKeysPart(fromKey, toKey)), "POST", JsonConvert.SerializeObject(couchMapReduce), "application/json");

                return(JsonConvert.DeserializeObject <CouchView <T> >(result));
            }
            catch (Exception e)
            {
                throw new CouchException($"Can`t get temporary view details: {e.Message}", e);
            }
        }
Exemple #4
0
 public CouchViewDefinition()
 {
     Mapping = new CouchMapReduce();
 }