示例#1
0
        public void DbRefIndex_Test()
        {
            var mapper = new BsonMapper();

            mapper.Entity<DCustomer>()
                .Id(x => x.Login)
                .Field(x => x.Name, "customer_name");

            mapper.Entity<DOrder>()
                .Id(x => x.OrderNumber)
                .Field(x => x.Customer, "cust")
                .DbRef(x => x.Customer, "customers");

            using (var db = new LiteDatabase(new MemoryStream(), mapper))
            {
                var customer = new DCustomer { Login = "******", Name = "John Doe" };
                var order = new DOrder { OrderNumber = 1, Customer = customer };

                var customers = db.GetCollection<DCustomer>("Customers");
                var orders = db.GetCollection<DOrder>("Orders");

                customers.Insert(customer);
                orders.Insert(order);

                // create an index in Customer.Id ref
                // x.Customer.Login == "Customer.$id"
                orders.EnsureIndex(x => x.Customer.Login);

                var query = orders
                    .Include(x => x.Customer)
                    .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
示例#2
0
        public void Linq_Visitor_Wit_DbRef()
        {
            var m = new BsonMapper();

            m.Entity <UserDomain>()
            .Id(x => x.DomainName);

            m.Entity <User>()
            .DbRef(x => x.Domain)
            .Field(x => x.Domain, "current-domain")
            .DbRef(x => x.Domains);

            // Json PATH

            Assert.AreEqual("$.Age", m.GetPath <User>(x => x.Age));
            Assert.AreEqual("$._id", m.GetPath <User>(x => x.Id));
            Assert.AreEqual("$.current-domain", m.GetPath <User>(x => x.Domain));
            Assert.AreEqual("$.Domains[*]", m.GetPath <User>(x => x.Domains));
            Assert.AreEqual("$.Domains[*].Age", m.GetPath <User>(x => x.Domains[0].Age));
            Assert.AreEqual("$.Domains[*].Age", m.GetPath <User>(x => x.Domains.Select(z => z.Age)));
            Assert.AreEqual("$.Domains[*].$id", m.GetPath <User>(x => x.Domains[0].DomainName));

            // Bson Field
            Assert.AreEqual("Domains", m.GetField <User>(x => x.Domains));
            Assert.AreEqual("Domains.Age", m.GetField <User>(x => x.Domains[0].Age));
            Assert.AreEqual("Domains.$id", m.GetField <User>(x => x.Domains[0].DomainName));

            // Query
            Assert.AreEqual("(_id = 123)", m.GetQuery <User>(x => x.Id == 123).ToString());
            Assert.AreEqual("(_id between [1 and 2])", m.GetQuery <User>(x => x.Id >= 1 && x.Id <= 2).ToString());
            Assert.AreEqual("(Domains.$id = \"admin\")", m.GetQuery <User>(x => x.Domains[0].DomainName == "admin").ToString());
        }
示例#3
0
        public IDatabaseManager Initialize()
        {
            // relational mappings
            _mapper.Entity <VpdbGame>()
            .Id(g => g.Id, false)
            .DbRef(g => g.Backglass, VpdbFiles)
            .DbRef(g => g.Logo, VpdbFiles);
            _mapper.Entity <VpdbRelease>()
            .Id(r => r.Id, false)
            .DbRef(r => r.Game, VpdbGames);
            _mapper.Entity <VpdbTableFile>()
            .DbRef(f => f.Reference, VpdbFiles)
            .DbRef(f => f.PlayfieldImage, VpdbFiles)
            .DbRef(f => f.PlayfieldVideo, VpdbFiles);
            _mapper.Entity <VpdbAuthor>()
            .DbRef(r => r.User, VpdbUsers);
            _mapper.Entity <VpdbFile>()
            .Id(f => f.Id, false);

            // db & collections
            _db       = new LiteDatabase(Path.Combine(_settingsManager.Settings.PinballXFolder, @"Databases\vpdb.db"));
            _jobs     = _db.GetCollection <Job>(Jobs);
            _messages = _db.GetCollection <Message>(Messages);
            _releases = _db.GetCollection <VpdbRelease>(VpdbReleases);
            _files    = _db.GetCollection <VpdbFile>(VpdbFiles);

            _logger.Info("Global database with {0} release(s) loaded.", _releases.Count());
            _initialized.OnNext(true);
            return(this);
        }
示例#4
0
        public Database(string path, IReadonlyDependencyResolver dr)
        {
            scheduler   = dr.GetService <IScheduler>() ?? RxApp.MainThreadScheduler;
            authService = new Lazy <IAuthService>(() => dr.GetService <IAuthService>());
            logger      = this.GetLogger(dr);

            // we use new BsonMapper() instead of BsonMapper.Global because in tests the same mapper cannot .Ignore the same field twice
            mapper = new BsonMapper();
            mapper.Entity <User>();
            mapper.Entity <Log>().DbRef(l => l.User);
            mapper.EmptyStringToNull = false;

            // We set mode to exclusive because the default value is shared and mac os doesn't support shared mode
            // We need this because unit tests run on mac os build machine and we don't need to support access to the same db file from several processes
            var connectionString = new ConnectionString(path)
            {
                Mode = FileMode.Exclusive
            };

            db = new LiteDatabase(connectionString, mapper);

            collections = new Dictionary <Type, object>
            {
                { typeof(User), db.GetCollection <User>() },
                { typeof(Log), db.GetCollection <Log>() },
            };
        }
        public static void Configure()
        {
            _global.Entity <Student>().Id(p => p.UserName);
            _global.Entity <Food>().Id(p => p.PersianDate);

            _global.Entity <Student>().DbRef(p => p.Foods);

            _global.Entity <ReserveLog>().DbRef(p => p.Food);
        }
示例#6
0
        public mapdb()
        {
            this.maper = BsonMapper.Global;

            maper.Entity <Post>()
            .Id(p => p.ID);

            maper.Entity <User>()
            .DbRef(x => x.Roles, "role");
        }
示例#7
0
        protected override void OnModelCreating(BsonMapper mapper)
        {
            mapper.Entity <DCustomer>()
            .Id(x => x.Login)
            .Field(x => x.Name, "customer_name");

            mapper.Entity <DOrder>()
            .Id(x => x.OrderNumber)
            .Field(x => x.Customer, "cust")
            .DbRef(x => x.Customer, "customers");
        }
示例#8
0
        protected override void OnModelCreating(BsonMapper mapper)
        {
            mapper.Entity<DCustomer>()
                .Id(x => x.Login)
                .Field(x => x.Name, "customer_name");

            mapper.Entity<DOrder>()
                .Id(x => x.OrderNumber)
                .Field(x => x.Customer, "cust")
                .DbRef(x => x.Customer, "customers");
        }
示例#9
0
 protected override void OnModelCreating(BsonMapper mapper)
 {
     mapper.Entity <Mensalidades>()
     .Id(x => x.Id)
     .DbRef(x => x.Socio, "Socios");
     mapper.Entity <Animal>()
     .Id(x => x.Id)
     .DbRef(x => x.Clinica, "Clinicas");
     mapper.Entity <EmprestimoCaixaTransporte>()
     .Id(x => x.Id)
     .DbRef(x => x.CaixaTransporte, "CaixaTransportes");
 }
示例#10
0
        static ConnectionFactory()
        {
            mapper = BsonMapper.Global;

            mapper.Entity <Domain.Server>()
            .Id(server => server.Endpoint);

            mapper.Entity <BaseServerStatistics>()
            .Id(statistics => statistics.EndPoint);
            mapper.Entity <BasePlayerStatistics>()
            .Id(statistics => statistics.Name);
        }
示例#11
0
        public static void StartLiteDB()
        {
            BsonMapper bsonMapper = BsonMapper.Global;

            bsonMapper.Entity <TodayAnimes>().Id(todayAnimes => todayAnimes.Id);
            bsonMapper.Entity <RecommendationAnimes>().Id(recommendation => recommendation.Id);

            string completePath = $"Filename={GetLiteDBPath(LiteDataName)}";

            App.liteDB = new LiteDatabase(completePath, bsonMapper);

            App.liteDB.Checkpoint();
        }
示例#12
0
 public BsonMapper InitMapper()
 {
     _bsonMapperMain = new CustomMapper();
     _bsonMapperMain
     .Entity <TypeContainer>()
     .Id(ip => ip.Id)
     .DbRef(f => f.AllowedThresholds, ThresholdTypeCollectionName);
     _bsonMapperMain
     .Entity <IThresholdType>();
     _bsonMapperMain
     .Entity <MixBO>()
     .Id(m => m.Id)
     .DbRef(m => m.MeasurementFunctionType);
     return(_bsonMapperMain);
 }
示例#13
0
文件: Program.cs 项目: v-kabanov/PIM
        static void TestLitedb()
        {
            var mapper = new BsonMapper();

            mapper.Entity <Note>()
            .Ignore(n => n.Name)
            .Ignore(n => n.IsTransient);
            //.Id(n => n.Id)
            //.Ignore(n => n.Id);

            //https://github.com/mbdavid/LiteDB/wiki/Connection-String
            var connectionString = "Filename=..\\MyLitedb.dat; Password=posvord; Initial Size=5MB; Upgrade=true";

            string id;

            using (var repo = new LiteRepository(connectionString, mapper))
            {
                var note = Note.Create("Blah blah");
                note.Id = ObjectId.NewObjectId().ToString();

                repo.Upsert(note);
                //var bsonDocument = adapter.ToBson(note);
                //repo.Database.Engine.Upsert(nameof(Note), bsonDocument);
                id = note.Id;
            }

            using (var repo = new LiteRepository(connectionString, mapper))
            {
                //var bson = repo.Engine.FindById(nameof(Note), id);
                //var note = adapter.Read(bson);
                var note = repo.SingleById <Note>(id);

                Console.WriteLine($"{note.Name} - {note.CreateTime} - {note.LastUpdateTime}");
            }
        }
示例#14
0
 protected override void OnModelCreating(BsonMapper mapper)
 {
     mapper.Entity<Patient>()
         //.Index(x => x.Ward.Id)
         //.Index("Ward.Id")
         .DbRef(x => x.Ward, "Ward");
 }
示例#15
0
        public void DbRef_ToDeleted_ThrowsNullReferenceException()
        {
            var mapper = new BsonMapper();

            mapper.Entity <Pipeline>().DbRef(x => x.Jobs, "jobs");

            using (var db = new LiteDatabase(new MemoryStream(), mapper))
            {
                var pipelineCollection = db.GetCollection <Pipeline>("pipelines");
                var jobCollection      = db.GetCollection <Job>("jobs");

                var pipeline = new Pipeline();
                pipelineCollection.Insert(pipeline);

                var job = new Job();
                jobCollection.Insert(job);

                pipeline.Jobs.Add(job);
                pipelineCollection.Update(pipeline);

                jobCollection.Delete(job.Id);

                var pipelines = db.GetCollection <Pipeline>("pipelines").Include(p => p.Jobs).FindAll().ToArray();
                Assert.AreEqual(1, pipelines.Length);

                pipeline = pipelines.Single();
                Assert.AreEqual(0, pipeline.Jobs.Count);
            }
        }
示例#16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OfflineDatabase"/> class.
        /// </summary>
        /// <param name="itemType"> The item type which is used to determine the database file name.  </param>
        /// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
        public ConcurrentOfflineDatabase(Type itemType, string filenameModifier)
        {
            var fullName = this.GetFileName(itemType.ToString());

            if (fullName.Length > 100)
            {
                fullName = fullName.Substring(0, 100);
            }

            BsonMapper mapper = BsonMapper.Global;

            mapper.Entity <OfflineEntry>().Id(o => o.Key);

            string root     = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string filename = fullName + filenameModifier + ".db";
            var    path     = Path.Combine(root, filename);

            this.db = new LiteRepository(new LiteDatabase(path, mapper));

            var cache = db.Database
                        .GetCollection <OfflineEntry>()
                        .FindAll()
                        .ToDictionary(o => o.Key, o => o);

            this.ccache = new ConcurrentDictionary <string, OfflineEntry>(cache);
        }
示例#17
0
 protected override void OnModelCreating(BsonMapper mapper)
 {
     mapper.Entity <Patient>()
     //.Index(x => x.Ward.Id)
     //.Index("Ward.Id")
     .DbRef(x => x.Ward, "Ward");
 }
示例#18
0
        private static void ConfigureDatabase()
        {
            BsonMapper mapper = BsonMapper.Global;

            mapper.Entity <Video>()
            .Id(x => x.VideoId);
        }
示例#19
0
 public BsonMapper InitMapper()
 {
     _bsonMapperMain = new CustomMapper();
     _bsonMapperMain
     .Entity <INode>()
     .Id(n => n.Id);
     _bsonMapperMain
     .Entity <Leaf>()
     .Id(leaf => leaf.Id);
     _bsonMapperMain
     .Entity <Branch>()
     .Id(branch => branch.Id)
     .DbRef(branch => branch.NodeLeft)
     .DbRef(branch => branch.NodeRight)
     ;
     return(_bsonMapperMain);
 }
示例#20
0
        public static void Map(BsonMapper mapper)
        {
            Check.DoRequireArgumentNotNull(mapper, nameof(mapper));

            mapper.Entity <Note>()
            .Ignore(n => n.Name)
            .Ignore(n => n.IsTransient);
        }
示例#21
0
 public override void Register(BsonMapper bsonMapper)
 {
     bsonMapper.Entity <WalletAddress>()
     .Id(w => w.UniqueId)
     .Ignore(w => w.Id)
     .Ignore(w => w.PublicKey)
     .Ignore(w => w.ProofOfPossession)
     .Ignore(w => w.Nonce);
 }
示例#22
0
 public override void Register(BsonMapper bsonMapper)
 {
     bsonMapper.Entity <TezosTransaction>()
     .Id(tx => tx.UniqueId)
     .Field(tx => tx.Id, "TxId")
     .Ignore(tx => tx.Operations)
     .Ignore(tx => tx.Head)
     .Ignore(tx => tx.SignedMessage);
 }
示例#23
0
        public WebCache(string databaseDirectory)
        {
            if (string.IsNullOrWhiteSpace(databaseDirectory))
            {
                throw new ArgumentException("The argument can't be null or empty.", nameof(databaseDirectory));
            }

            _databaseDirectory = databaseDirectory;
            _databaseFilePath  = Path.Combine(_databaseDirectory, "sci-cache-db");

            _bsonMapper = BsonMapper.Global;

            _bsonMapper.Entity <RequestData>()
            .Id(x => x.RequestId);

            _bsonMapper.Entity <ResponseData>()
            .Id(x => x.RequestId);
        }
示例#24
0
        /// <summary>
        /// Método para iniciar o liteErrorLogDB
        /// </summary>
        public static void StartErrorLogLiteDB()
        {
            BsonMapper bsonMapper = BsonMapper.Global;

            bsonMapper.Entity <ErrorLog>().Id(errorLog => errorLog.Id);

            App.liteErrorLogDB = new LiteDatabase($"Filename={GetLiteDBPath(LiteErrordbLog)}", bsonMapper);

            App.liteErrorLogDB.Checkpoint();
        }
示例#25
0
 protected override void OnModelCreating(BsonMapper mapper)
 {
     mapper.Entity <Order>()
     .DbRef(x => x.Products, "products")
     .DbRef(x => x.ProductArray, "products")
     .DbRef(x => x.ProductColl, "products")
     .DbRef(x => x.ProductEmpty, "products")
     .DbRef(x => x.ProductsNull, "products")
     .DbRef(x => x.Customer, "customers")
     .DbRef(x => x.CustomerNull, "customers");
 }
示例#26
0
 protected override void OnModelCreating(BsonMapper mapper)
 {
     mapper.Entity<Order>()
         .DbRef(x => x.Products, "products")
         .DbRef(x => x.ProductArray, "products")
         .DbRef(x => x.ProductColl, "products")
         .DbRef(x => x.ProductEmpty, "products")
         .DbRef(x => x.ProductsNull, "products")
         .DbRef(x => x.Customer, "customers")
         .DbRef(x => x.CustomerNull, "customers");
 }
示例#27
0
 static IncludeDatabase()
 {
     _mapper.Entity <Order>()
     .DbRef(x => x.Products, "products")
     .DbRef(x => x.ProductArray, "products")
     .DbRef(x => x.ProductColl, "products")
     .DbRef(x => x.ProductEmpty, "products")
     .DbRef(x => x.ProductsNull, "products")
     .DbRef(x => x.Customer, "customers")
     .DbRef(x => x.CustomerNull, "customers");
 }
        public UpscallingService(bool shallClearData = false)
        {
            _mqBus = RabbitHutch.CreateBus("host=localhost");

            Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), _dataFolder));
            _dbFilePath = Path.Combine(Directory.GetCurrentDirectory(), _dataFolder, _dbName);

            if (shallClearData)
            {
                ClearData();
            }

            _dbMapper = new BsonMapper();
            _dbMapper.Entity <TaskProgress>().Id(tp => tp.MessageId);
            _dbMapper.Entity <TaskFinished>().Id(tp => tp.TaskId).Ignore(tp => tp.Image);

            progressReceiver = _mqBus.Receive <TaskProgress>(MqUtils.UpscallingProgressQueue, m => OnProgress(m));
            resultReceiver   = _mqBus.Receive <TaskFinished>(MqUtils.UpscallingResultQueue, m => OnResult(m));

            _db = new LiteDatabase(new MemoryStream(), _dbMapper);
        }
示例#29
0
        public IDatabaseManager Initialize()
        {
            _dbPath = Path.Combine(_settingsManager.Settings.PinballXFolder, @"Databases\vpdb-agent.db");
            _db     = new LiteDatabase(_dbPath, _mapper);

            _games    = _db.GetCollection <VpdbGame>(TableGames);
            _releases = _db.GetCollection <VpdbRelease>(TableReleases);
            _files    = _db.GetCollection <VpdbFile>(TableFiles);
            _builds   = _db.GetCollection <VpdbTableFile.VpdbCompatibility>(TableBuilds);
            _users    = _db.GetCollection <VpdbUser>(TableUsers);
            _jobs     = _db.GetCollection <Job>(TableJobs);
            _messages = _db.GetCollection <Message>(TableMessages);

            _mapper.UseLowerCaseDelimiter('_');
            _mapper.Entity <VpdbRelease>().Ignore(x => x.Changing).Ignore(x => x.Changed).Ignore(x => x.ThrownExceptions);
            _mapper.Entity <VpdbVersion>().Ignore(x => x.Changing).Ignore(x => x.Changed).Ignore(x => x.ThrownExceptions);
            _mapper.Entity <VpdbTableFile>().Ignore(x => x.Changing).Ignore(x => x.Changed).Ignore(x => x.ThrownExceptions);
            _mapper.Entity <VpdbThumb>().Ignore(x => x.Changing).Ignore(x => x.Changed).Ignore(x => x.ThrownExceptions);
            _mapper.Entity <VpdbImage>().Ignore(x => x.Changing).Ignore(x => x.Changed).Ignore(x => x.ThrownExceptions);
            _mapper.Entity <Job>().Ignore(x => x.Changing).Ignore(x => x.Changed).Ignore(x => x.ThrownExceptions);

            _logger.Info("LiteDB initialized at {0}.", _dbPath);
            _initialized.OnNext(true);
            return(this);
        }
示例#30
0
        public async Task DbRef_Index()
        {
            var mapper = new BsonMapper();

            mapper.Entity <Customer>()
            .Id(x => x.Login)
            .Field(x => x.Name, "customer_name");

            mapper.Entity <Order>()
            .Id(x => x.OrderNumber)
            .Field(x => x.Customer, "cust")
            .DbRef(x => x.Customer, "customers");

            using (var db = new LiteDatabaseAsync(new MemoryStream(), mapper))
            {
                var customer = new Customer {
                    Login = "******", Name = "John Doe"
                };
                var order = new Order {
                    Customer = customer
                };

                var customers = db.GetCollection <Customer>("Customers");
                var orders    = db.GetCollection <Order>("Orders");

                await customers.InsertAsync(customer);

                await orders.InsertAsync(order);

                // create an index in Customer.Id ref
                // x.Customer.Login == "Customer.$id"
                await orders.EnsureIndexAsync(x => x.Customer.Login);

                var query = await orders
                            .Include(x => x.Customer)
                            .FindOneAsync(x => x.Customer.Login == "jd");

                query.Customer.Name.Should().Be(customer.Name);
            }
        }
示例#31
0
        public async Task fill_size()
        {
            var mapper = new BsonMapper();

            mapper.Entity <LiteDBChunk>()
            .Field(x => x.Index, "i")
            .Field(x => x.OperationId, "o")
            .Field(x => x.PartitionId, "s")
            .Field(x => x.Position, "po")
            .Field(x => x.StreamOperation, "so")
            .Field(x => x.StreamSequence, "se")
            .Field(x => x.Payload, "pa");

            var options = new LiteDBPersistenceOptions
                          (
                new LiteDBSerializer(),
                NStoreNullLoggerFactory.Instance,
                mapper
                          )
            {
                ConnectionString = "test_for_size.litedb"
            };

            if (File.Exists(options.ConnectionString))
            {
                File.Delete(options.ConnectionString);
            }

            var store = new LiteDBPersistence(options);

            store.DeleteDataFiles();

            store.Init();

            var tasks = Enumerable.Range(1, 10_000).
                        Select(x => store.AppendAsync(
                                   $"{x:D10}",
                                   x,
                                   null,
                                   null,
                                   CancellationToken.None
                                   )
                               );

            await Task.WhenAll(tasks);

            store.Dispose();

            var fi = new FileInfo(options.ConnectionString);

            _output.WriteLine($"File size is {fi.Length} bytes");
        }
示例#32
0
        public void DbRefIndex_Test()
        {
            var mapper = new BsonMapper();

            mapper.Entity <DCustomer>()
            .Id(x => x.Login)
            .Field(x => x.Name, "customer_name");

            mapper.Entity <DOrder>()
            .Id(x => x.OrderNumber)
            .Field(x => x.Customer, "cust")
            .DbRef(x => x.Customer, "customers");

            using (var db = new LiteDatabase(new MemoryStream(), mapper))
            {
                var customer = new DCustomer {
                    Login = "******", Name = "John Doe"
                };
                var order = new DOrder {
                    OrderNumber = 1, Customer = customer
                };

                var customers = db.GetCollection <DCustomer>("Customers");
                var orders    = db.GetCollection <DOrder>("Orders");

                customers.Insert(customer);
                orders.Insert(order);

                // create an index in Customer.Id ref
                // x.Customer.Login == "Customer.$id"
                orders.EnsureIndex(x => x.Customer.Login);

                var query = orders
                            .Include(x => x.Customer)
                            .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
        private void OnModelCreating(BsonMapper modelBuilder)
        {
            #region ConfigureActivityView

            modelBuilder.Entity <ActivityProjection>()
            .Field(k => k.ActivityId, "activityId")
            .Field(p => p.ProjectId, "projectId")
            .Field(p => p.Description, "description")
            .Field(p => p.Status, "status")
            ;

            #endregion
        }
示例#34
0
        private static void InitDatabase(IConfiguration configuration)
        {
            BsonMapper mapper = BsonMapper.Global;

            mapper.Entity <PlayerEntity>()
            .Id(x => x.Id);
            mapper.Entity <GameEntity>()
            .Id(x => x.Id)
            .DbRef(x => x.PlayerWon, nameof(PlayerEntity));
            mapper.Entity <GamePlayerEntity>()
            .Id(x => x.Id)
            .DbRef(x => x.Player, nameof(PlayerEntity))
            .DbRef(x => x.Game, nameof(GameEntity));

            //seed database
            using (LiteDatabase db = new LiteDatabase(configuration["_CONNSTR"]))
            {
                //seed config
                ConfigRepository configDb = new ConfigRepository(db);

                ConfigEntity OFFER_COOLDOWN_config   = new ConfigEntity(nameof(KonluluModule.OFFER_COOLDOWN), KonluluModule.OFFER_COOLDOWN);
                ConfigEntity KON_TIME_config         = new ConfigEntity(nameof(KonluluModule.KON_TIME), KonluluModule.KON_TIME);
                ConfigEntity MAX_FUSE_TIME_config    = new ConfigEntity(nameof(KonluluModule.MAX_FUSE_TIME), KonluluModule.MAX_FUSE_TIME);
                ConfigEntity MIN_FUSE_TIME_config    = new ConfigEntity(nameof(KonluluModule.MIN_FUSE_TIME), KonluluModule.MIN_FUSE_TIME);
                ConfigEntity MAX_OFFER_config        = new ConfigEntity(nameof(KonluluModule.MAX_OFFER), KonluluModule.MAX_OFFER);
                ConfigEntity MIN_PLAYER_COUNT_config = new ConfigEntity(nameof(KonluluModule.MIN_PLAYER_COUNT), KonluluModule.MIN_PLAYER_COUNT);
                ConfigEntity IS_DEBUG_config         = new ConfigEntity(nameof(KonluluModule.IS_DEBUG), KonluluModule.IS_DEBUG);

                configDb.SaveWithoutUpdate(OFFER_COOLDOWN_config);
                configDb.SaveWithoutUpdate(KON_TIME_config);
                configDb.SaveWithoutUpdate(MAX_FUSE_TIME_config);
                configDb.SaveWithoutUpdate(MIN_FUSE_TIME_config);
                configDb.SaveWithoutUpdate(MAX_OFFER_config);
                configDb.SaveWithoutUpdate(MIN_PLAYER_COUNT_config);
                configDb.SaveWithoutUpdate(IS_DEBUG_config);

                //seed flavor text
            }
        }
示例#35
0
        public void Include_Test()
        {
            var mapper = new BsonMapper();

            mapper.Entity<Order>()
               .DbRef(x => x.Products, "products")
               .DbRef(x => x.ProductArray, "products")
               .DbRef(x => x.ProductColl, "products")
               .DbRef(x => x.ProductEmpty, "products")
               .DbRef(x => x.ProductsNull, "products")
               .DbRef(x => x.Customer, "customers")
               .DbRef(x => x.CustomerNull, "customers");

            mapper.Entity<Customer>()
                .DbRef(x => x.MainAddress, "addresses");

            mapper.Entity<Product>()
                .DbRef(x => x.SupplierAddress, "addresses");

            using (var file = new TempFile())
            using (var db = new LiteDatabase(file.Filename, mapper))
            {
                var address = new Address { StreetName = "3600 S Las Vegas Blvd" };
                var customer = new Customer { Name = "John Doe", MainAddress = address };

                var product1 = new Product { Name = "TV", Price = 800, SupplierAddress = address };
                var product2 = new Product { Name = "DVD", Price = 200 };

                var customers = db.GetCollection<Customer>("customers");
                var addresses = db.GetCollection<Address>("addresses");
                var products = db.GetCollection<Product>("products");
                var orders = db.GetCollection<Order>("orders");

                // insert ref documents
                addresses.Insert(address);
                customers.Insert(customer);
                products.Insert(new Product[] { product1, product2 });

                var order = new Order
                {
                    Customer = customer,
                    CustomerNull = null,
                    Products = new List<Product>() { product1, product2 },
                    ProductArray = new Product[] { product1 },
                    ProductColl = new List<Product>() { product2 },
                    ProductEmpty = new List<Product>(),
                    ProductsNull = null
                };

                orders.Insert(order);

                var query = orders
                    .Include(x => x.Customer)
                    .Include(x => x.Customer.MainAddress)
                    .Include(x => x.CustomerNull)
                    .Include(x => x.Products)
                    .Include(x => x.ProductArray)
                    .Include(x => x.ProductColl)
                    .Include(x => x.ProductsNull)
                    .FindAll()
                    .FirstOrDefault();

                Assert.AreEqual(customer.Name, query.Customer.Name);
                Assert.AreEqual(customer.MainAddress.StreetName, query.Customer.MainAddress.StreetName);
                Assert.AreEqual(product1.Price, query.Products[0].Price);
                Assert.AreEqual(product2.Name, query.Products[1].Name);
                Assert.AreEqual(product1.Name, query.ProductArray[0].Name);
                Assert.AreEqual(product2.Price, query.ProductColl.ElementAt(0).Price);
                Assert.AreEqual(null, query.ProductsNull);
                Assert.AreEqual(0, query.ProductEmpty.Count);
            }
        }