public void Map2PocoTests_NewObjectsInArray() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var query = from brewery in bucket.Queryable <Brewery>() where brewery.Type == "brewery" select new { name = brewery.Name, list = new[] { new { part = brewery.City }, new { part = brewery.State }, new { part = brewery.Code } } }; foreach (var brewery in query.Take(10)) { Console.WriteLine("Brewery {0} has address parts {1}", brewery.name, String.Join(", ", brewery.list.Select(p => p.part))); } } } }
public void Test_POCO_Basic() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { } } }
public void AggregateTests_SimpleCount() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var count = bucket.Queryable <Beer>().Count(p => p.Type == "beer"); Console.WriteLine("Number of beers is {0}", count); } } }
public void AnyAllTests_AllOnMainDocument_ReturnsFalse() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var isAllBreweries = bucket.Queryable <Brewery>().All(p => p.Type == "brewery"); Assert.False(isAllBreweries); } } }
public void AggregateTests_SimpleAverage() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var avg = bucket.Queryable <Beer>().Where(p => p.Type == "beer" && N1Ql.IsValued(p.Abv)).Average(p => p.Abv); Console.WriteLine("Average ABV of all beers is {0}", avg); } } }
protected void InitializeCluster(IContractResolver contractResolver = null) { if (contractResolver != null) { _contractResolver = contractResolver; } var config = TestConfigurations.DefaultConfig(); //var config = new ClientConfiguration(); //config.Servers.Add(new Uri("http://127.0.0.1:8091")); config.DeserializationSettings.ContractResolver = _contractResolver; config.SerializationSettings.ContractResolver = _contractResolver; ClusterHelper.Initialize(config); }
public void Single_HasResult() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from beer in bucket.Queryable <Beer>() where beer.Name == "21A IPA" select new { beer.Name }; Console.WriteLine(beers.Single().Name); } } }
public void Test_Select_Children() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket()) { var query = from c in bucket.Queryable <Contact>() select c.Children; const string expected = "SELECT `Extent1`.`children` FROM `default` as `Extent1`"; Assert.AreEqual(expected, CreateN1QlQuery(bucket, query.Expression)); } } }
public void Map2PocoTests_Simple_Projections_TypeFilterAttribute() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = (from b in bucket.Queryable <BeerFiltered>() select new { type = b.Type }). AsEnumerable(); Assert.True(beers.All(p => p.type == "beer")); } } }
public void Map2PocoTests_Explain() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var explanation = (from b in bucket.Queryable <Beer>() where b.Type == "beer" select b). Explain(); Console.WriteLine(explanation); } } }
public void SingleOrDefault_Empty() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from beer in bucket.Queryable <Beer>() where beer.Type == "abcdefg" select new { beer.Name }; var aBeer = beers.SingleOrDefault(); Assert.IsNull(aBeer); } } }
public void AnyAllTests_AnyOnMainDocument_ReturnsFalse() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var hasFaketype = (from b in bucket.Queryable <Brewery>() where b.Type == "faketype" select new { name = b.Name, address = b.Address }). Any(); Assert.False(hasFaketype); } } }
public void AnyAllTests_AllOnMainDocument_ReturnsTrue() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var allBreweriesHaveAddress = (from b in bucket.Queryable <Brewery>() where b.Type == "brewery" select new { b.Name }) .All(p => p.Name != ""); Assert.True(allBreweriesHaveAddress); } } }
public void Map2PocoTests_Simple_Projections_TypeFilterRuntime() { DocumentFilterManager.SetFilter(new BreweryFilter()); using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var breweries = (from b in bucket.Queryable <Brewery>() select new { type = b.Type }) .AsEnumerable(); Assert.True(breweries.All(p => p.type == "brewery")); } } }
public void FirstOrDefault_HasResult() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from beer in bucket.Queryable <Beer>() where beer.Type == "beer" select new { beer.Name }; var aBeer = beers.FirstOrDefault(); Assert.IsNotNull(aBeer); Console.WriteLine(aBeer.Name); } } }
public void Map2PocoTests_Simple_Projections() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from b in bucket.Queryable <Beer>() select new { name = b.Name, abv = b.Abv }; foreach (var b in beers) { Console.WriteLine("{0} has {1} ABV", b.name, b.abv); } } } }
public void AnyAllTests_AnyNestedArray() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var breweries = (from b in bucket.Queryable <Brewery>() where b.Type == "brewery" && b.Address.Any() select new { name = b.Name, address = b.Address }). ToList(); Assert.IsNotEmpty(breweries); Assert.True(breweries.All(p => p.address.Any())); } } }
public void NestTests_Unnest_Simple() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var breweries = from brewery in bucket.Queryable <Brewery>() from address in brewery.Address select new { name = brewery.Name, address }; foreach (var b in breweries.Take(10)) { Console.WriteLine("Brewery {0} has address line {1}", b.name, b.address); } } } }
public void Map2PocoTests() { using (var cluster = new Cluster( TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from b in bucket.Queryable <Beer>() select b; foreach (var beer in beers) { Console.WriteLine(beer.Name); } } } }
public void Map2PocoTests_Simple_Projections_WhereDateTime() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from b in bucket.Queryable <Beer>() where (b.Type == "beer") && (b.Updated >= new DateTime(2010, 1, 1)) select new { name = b.Name, updated = b.Updated }; foreach (var b in beers.Take(20)) { Console.WriteLine("{0} last updated {1:g}", b.name, b.updated); } } } }
public void Map2PocoTests_Simple_Projections_MetaWhere() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = (from b in bucket.Queryable <Beer>() where b.Type == "beer" && N1Ql.Meta(b).Type == "json" select new { name = b.Name }). Take(10); foreach (var b in beers) { Console.WriteLine("{0} is a JSON document", b.name); } } } }
public void UseKeys_SelectDocuments() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var query = from brewery in bucket.Queryable <Brewery>().UseKeys(new[] { "21st_amendment_brewery_cafe", "357" }) select new { name = brewery.Name }; foreach (var brewery in query) { Console.WriteLine("Brewery {0}", brewery.name); } } } }
public void SingleOrDefault_HasManyResults() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from beer in bucket.Queryable <Beer>() where beer.Type == "beer" select new { beer.Name }; Assert.Throws <InvalidOperationException>(() => { // ReSharper disable once UnusedVariable var temp = beers.SingleOrDefault(); }); } } }
public void Map2PocoTests_Simple_Projections_MetaId() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = (from b in bucket.Queryable <Beer>() where b.Type == "beer" select new { name = b.Name, id = N1Ql.Meta(b).Id }). Take(10); foreach (var b in beers) { Console.WriteLine("{0} has id {1}", b.name, b.id); } } } }
public void JoinTests_InnerJoin_Simple() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from beer in bucket.Queryable <Beer>() join brewery in bucket.Queryable <Brewery>() on beer.BreweryId equals N1Ql.Key(brewery) select new { beer.Name, beer.Abv, BreweryName = brewery.Name }; foreach (var b in beers.Take(10)) { Console.WriteLine("Beer {0} with ABV {1} is from {2}", b.Name, b.Abv, b.BreweryName); } } } }
public void SubqueryTests_ArraySubqueryWithFilter() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var breweries = from brewery in bucket.Queryable <Brewery>() where brewery.Type == "brewery" orderby brewery.Name select new { name = brewery.Name, addresses = brewery.Address.Where(p => p.Length > 3) }; foreach (var b in breweries.Take(10)) { Console.WriteLine("Brewery {0} has address {1}", b.name, string.Join(", ", b.addresses)); } } } }
public void JoinTests_InnerJoin_Prefiltered() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var beers = from beer in bucket.Queryable <Beer>().Where(p => p.Type == "beer") join brewery in bucket.Queryable <Brewery>().Where(p => p.Type == "brewery") on beer.BreweryId equals N1Ql.Key(brewery) where brewery.Geo.Longitude > -80 orderby beer.Name select new { beer.Name, beer.Abv, BreweryName = brewery.Name }; foreach (var b in beers.Take(10)) { Console.WriteLine("Beer {0} with ABV {1} is from {2}", b.Name, b.Abv, b.BreweryName); } } } }
public void Test_AnonymousType_In_Projection() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket()) { var query = from c in QueryFactory.Queryable <Contact>(bucket) select new { age = c.Age, fname = c.FirstName }; const string expected = "SELECT `Extent1`.`age` as `age`, `Extent1`.`fname` as `fname` FROM `default` as `Extent1`"; var N1QLQuery = CreateN1QlQuery(bucket, query.Expression); Assert.AreEqual(expected, N1QLQuery); } } }
public void AggregateTests_JoinBeforeGroupByAndMultipartKey() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var breweries = from beer in bucket.Queryable <Beer>() join brewery in bucket.Queryable <Brewery>() on beer.BreweryId equals N1Ql.Key(brewery) where beer.Type == "beer" group beer by new { breweryid = beer.BreweryId, breweryName = brewery.Name } into g select new { g.Key.breweryName, count = g.Count(), avgAbv = g.Average(p => p.Abv) }; foreach (var brewery in breweries) { Console.WriteLine("Brewery {0} has {1} beers with {2:f2} average ABV", brewery.breweryName, brewery.count, brewery.avgAbv); } } } }
public void AggregateTests_OrderByAggregate() { using (var cluster = new Cluster(TestConfigurations.DefaultConfig())) { using (var bucket = cluster.OpenBucket("beer-sample")) { var breweries = from beer in bucket.Queryable <Beer>() where beer.Type == "beer" group beer by beer.BreweryId into g orderby g.Count() descending select new { breweryid = g.Key, count = g.Count(), avgAbv = g.Average(p => p.Abv) }; foreach (var brewery in breweries) { Console.WriteLine("Brewery {0} has {1} beers with {2:f2} average ABV", brewery.breweryid, brewery.count, brewery.avgAbv); } } } }