Exemplo n.º 1
0
        public async void TestFillDB()
        {
            serversDatabase   = dbProvider.GetDatabase(DatabaseName);
            serversCollection = dbProvider.GetBsonDocumentCollection(DatabaseName, CollectionName);

            await serversDatabase.DropCollectionAsync(CollectionName); // очистка коллекции БД

            for (var i = 0; i < 15; i++)
            {
                var doc = new BsonDocument
                {
                    { "Id", i > 3 && i <= 5 ? i + 30 : i },
                    { "Name", $"Server number {-2*((-2) ^ i)}" },
                    { "IP", "127.0.0.1" }, //$"127.0.{2*i}.{50 - i}"},
                    { "Port", 7777 },      //7777 - i},
                    { "Region", i },
                    { "PlayersCount", 95 - i },
                    { "PlayersMax", 100 },
                    { "MinutesToNextLevelChange", 120 - i },
                    { "LastUpdateDateTime", DateTime.Now.AddMinutes(-2 - (-2) ^ i).AddDays(1) }
                };

                await serversCollection.Collection.InsertOneAsync(doc);
            }

            //MessageBox.Show($"[{CollectionName}]: Test filling completed.\nComment this function and restart application",
            //    "Done", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //MediaTypeNames.Application.Exit();
        }
 public PlayersProvider(IMongoDbProvider dbProvider,
                        IMongoDbDefinitionBuilder mongoDbDefinitionBuilder,
                        IEncryptor encryptor)
 {
     this.dbProvider = dbProvider;
     this.mongoDbDefinitionBuilder = mongoDbDefinitionBuilder;
     this.encryptor    = encryptor;
     playersDatabase   = dbProvider.GetDatabase(DatabaseName);
     playersCollection = dbProvider.GetBsonDocumentCollection(DatabaseName, CollectionName);
 }
        public async void TestFillDB()
        {
            playersDatabase   = dbProvider.GetDatabase(DatabaseName);
            playersCollection = dbProvider.GetBsonDocumentCollection(DatabaseName, CollectionName);

            await playersDatabase.DropCollectionAsync(CollectionName); // очистка коллекции БД

            var random = new Random(0);

            for (var i = 0; i < 50; i++)
            {
                // Unlocked Skins
                var unlockedSkins = new List <short>();
                for (var j = 0; j < (i + 17) / 20; j++)
                {
                    unlockedSkins.Add((short)(random.Next(0, 15)));
                }
                unlockedSkins.Sort();

                var unlockedSkinsJson = JsonConvert.SerializeObject(unlockedSkins);

                // Unlocked Abilities
                var unlockedAbilities = new List <short>();
                for (var j = 0; j < (i + 8) / 10; j++)
                {
                    unlockedAbilities.Add((short)(random.Next(0, 35)));
                }
                unlockedAbilities.Sort();

                var unlockedAbilitiesJson = JsonConvert.SerializeObject(unlockedAbilities);

                var doc = new BsonDocument
                {
                    { "Id", i },
                    { "PersonId", encryptor.SHA256($"email{i}@gmail.com") },
                    { "Nickname", $"Player random-n{i - 102*((-3) ^ (i/5))}" },
                    { "Country", CultureInfo.GetCultures(CultureTypes.SpecificCultures)[i * 7].Name },
                    { "Money", 2250 - 20 * i - (-2) ^ (i / 5) },
                    { "ScoreMax", 1150 + (-3) ^ (i / 5) },
                    { "LastSessionDateTime", DateTime.Now.AddMinutes(-1.25f * i) },
                    { "FirstSessionDateTime", DateTime.Now.AddDays(-50f / (i + 1)) },
                    { "SelectedSkin", i / 4 },
                    { "UnlockedSkins", unlockedSkinsJson },
                    { "SelectedAbility", 25 / (i + 1) },
                    { "UnlockedAbilities", unlockedAbilitiesJson }
                };

                playersCollection.InsertOneAsync(doc);
            }

            //MessageBox.Show($"[{CollectionName}]: Test filling completed.\nComment this function and restart application",
            //    "Done", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //MediaTypeNames.Application.Exit();
        }
Exemplo n.º 4
0
        public void GetDatabase_ReturnsDatabase()
        {
            // arrange
            _provider = new MongoDbProvider(_connStr, _mockMongo);
            var dbName = "db name";

            // act
            var db = _provider.GetDatabase(dbName);

            // assert
            Assert.IsNotNull(db);
            Assert.AreEqual(db.DatabaseNamespace.DatabaseName, dbName);
        }