Ejemplo n.º 1
0
 public BeerSample(IBucket bucket) : base(bucket)
 {
     //Two ways of applying a filter are included in this example.
     //This is by implementing IDocumentFilter and then adding explicitly.
     //adding it to the DocumentFilterManager
     DocumentFilterManager.SetFilter(new BreweryFilter());
 }
Ejemplo n.º 2
0
        private static void InitializeCouchbase()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddNLog(new NLogProviderOptions
            {
                CaptureMessageTemplates  = true,
                CaptureMessageProperties = true
            });
            NLog.LogManager.LoadConfiguration("nlog.config");

            _cluster = new Cluster
                       (
                new ClientConfiguration
            {
                LoggerFactory = loggerFactory,
                Servers       = new List <Uri> {
                    new Uri("http://localhost:8091/")
                },
                Serializer = () => new CustomIdEnabledSerializer()
            }
                       );

            var authenticator = new PasswordAuthenticator("Administrator", "trustno1");

            _cluster.Authenticate(authenticator);

            _bucket = _cluster.OpenBucket("test");

            _bucketContext = new BucketContext(_bucket);

            DocumentFilterManager.SetFilter(new TestDocumentFilter());

            TypeBasedSerializationConverterRegistry.Global.Add(typeof(JsonIdentityConverter), typeof(TestDocumentIdSerializationConverter));
        }
Ejemplo n.º 3
0
        public void Map2PocoTests_Simple_Projections_TypeFilterRuntime()
        {
            DocumentFilterManager.SetFilter(new BreweryFilter());

            var bucket  = ClusterHelper.GetBucket("beer-sample");
            var context = new BucketContext(bucket);

            var breweries = (from b in context.Query <Brewery>()
                             select new { type = b.Type })
                            .AsEnumerable();

            Assert.True(breweries.All(p => p.type == "brewery"));
        }
Ejemplo n.º 4
0
        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"));
                }
            }
        }