Ejemplo n.º 1
0
 public void InsertFriendInvitation(FriendInvitationDocument doc)
 {
     try
     {
         friendInvitations.Insert(doc);
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Ejemplo n.º 2
0
 public void AddAlert(IInternalAlert alert)
 {
     try
     {
         string        type          = AlertTypeUtils.ToString(alert.Type);
         string        level         = alert.Level.ToString();
         AlertDocument alertDocument = GetAlertDocument(alert.AlertId);
         if (alertDocument == null)
         {
             AlertDocument alertDocument2 = new AlertDocument();
             alertDocument2.AlertId = alert.AlertId;
             alertDocument2.Type    = type;
             alertDocument2.Level   = level;
             alertDocument          = alertDocument2;
             alerts.Insert(alertDocument);
         }
         else
         {
             alertDocument.Type  = type;
             alertDocument.Level = level;
             alerts.Update(alertDocument);
         }
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Ejemplo n.º 3
0
        public async Task CreateReadTestWithDatabaseInConnectionString()
        {
            const string connectionDatabaseName = "TestIndexDatabase2";

            string            connectionString = Constants.CreateConnectionString(connectionDatabaseName);
            IDocumentDatabase db = new DocumentDatabase(connectionString);
            IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName);

            TestDocument test = CreateTestDocument(0);

            await collection.Insert(_workContext, test);

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(1);

            TestDocument result = results.First();

            result.Should().NotBeNull();
            result.Index.Should().Be(test.Index);
            result.FirstName.Should().Be(test.FirstName);
            result.LastName.Should().Be(test.LastName);
            result.Birthdate.ToString("s").Should().Be(test.Birthdate.ToString("s"));
            result.Address1.Should().Be(test.Address1);
            result.Address2.Should().Be(test.Address2);
            result.City.Should().Be(test.City);
            result.State.Should().Be(test.State);
            result.ZipCode.Should().Be(test.ZipCode);

            await db.DocumentServer.DropDatabase(_workContext, connectionDatabaseName);
        }
Ejemplo n.º 4
0
        public async Task CreateReadTest()
        {
            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);
            IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName);

            TestDocument test = CreateTestDocument(0);

            await collection.Insert(_workContext, test);

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(1);

            TestDocument result = results.First();

            result.Should().NotBeNull();
            result.Index.Should().Be(test.Index);
            result.FirstName.Should().Be(test.FirstName);
            result.LastName.Should().Be(test.LastName);
            result.Birthdate.ToString("s").Should().Be(test.Birthdate.ToString("s"));
            result.Address1.Should().Be(test.Address1);
            result.Address2.Should().Be(test.Address2);
            result.City.Should().Be(test.City);
            result.State.Should().Be(test.State);
            result.ZipCode.Should().Be(test.ZipCode);
        }
Ejemplo n.º 5
0
 public void InsertUserDocument(UserDocument userDocument)
 {
     try
     {
         users.Insert(userDocument);
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Ejemplo n.º 6
0
 public void InsertFriend(FriendDocument doc)
 {
     try
     {
         if (!Contains(friends, doc.Swid))
         {
             friends.Insert(doc);
         }
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Ejemplo n.º 7
0
        public async Task SmallCappedOverFiveCollectionTest()
        {
            const int maxDocuments        = 10;
            const int maxSizeInBytes      = maxDocuments * 1000;
            const int createDocumentCount = maxDocuments + 5;

            var model = new CappedCollectionModel
            {
                CollectionName       = _collectionName,
                MaxSizeInBytes       = maxSizeInBytes,
                MaxNumberOfDocuments = maxDocuments,
            };

            var package = new CollectionModelPackage(_documentDatabase, model, new CollectionModelSettings {
                ReCreate = true
            });

            bool result = await package.Apply(_workContext);

            result.Should().BeTrue();

            IDocumentCollection <TestDocument> collection = _documentDatabase.GetCollection <TestDocument>(_collectionName);

            foreach (var index in Enumerable.Range(0, createDocumentCount))
            {
                TestDocument doc = CreateTestDocument(index);
                await collection.Insert(_workContext, doc);
            }

            long count = await collection.Count(_workContext);

            count.Should().Be(maxDocuments);

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(maxDocuments);

            int testIndex = createDocumentCount - maxDocuments;

            foreach (var item in results.OrderBy(x => x.Index))
            {
                TestDocument compareDoc = CreateTestDocument(testIndex++);
                item.IsEqual(compareDoc).Should().BeTrue();
            }
        }
Ejemplo n.º 8
0
        public async Task CreateMultipleReadDeleteTest()
        {
            const int count = 10;

            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);
            IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName);

            var documentList = new List <TestDocument>();

            foreach (var index in Enumerable.Range(0, count))
            {
                TestDocument test = CreateTestDocument(index);
                await collection.Insert(_workContext, test);

                documentList.Add(test);
            }

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(count);

            // Create filter to delete odd records
            var builder = Builders <TestDocument> .Filter;
            var filter  = builder.In("Index", new int[] { 1, 3, 5, 7, 9 });

            await collection.Delete(_workContext, filter);

            results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(count - 5);

            filter = builder.Gte("Index", 0);
            await collection.Delete(_workContext, filter);

            results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(0);
        }
Ejemplo n.º 9
0
        public async Task CreateReadDeleteTest()
        {
            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);
            IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName);

            TestDocument test = CreateTestDocument(0);

            await collection.Insert(_workContext, test);

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(1);

            TestDocument result = results.First();

            result.Should().NotBeNull();
            result.Index.Should().Be(test.Index);
            result.FirstName.Should().Be(test.FirstName);
            result.LastName.Should().Be(test.LastName);
            result.Birthdate.ToString("s").Should().Be(test.Birthdate.ToString("s"));
            result.Address1.Should().Be(test.Address1);
            result.Address2.Should().Be(test.Address2);
            result.City.Should().Be(test.City);
            result.State.Should().Be(test.State);
            result.ZipCode.Should().Be(test.ZipCode);

            var builder = Builders <TestDocument> .Filter;
            var filter  = builder.Eq("_id", result._id);

            await collection.Delete(_workContext, filter);

            List <TestDocument> currentList = collection.MongoCollection
                                              .AsQueryable()
                                              .Where(x => x._id == result._id)
                                              .ToList();

            currentList.Count.Should().Be(0);
        }
Ejemplo n.º 10
0
        public async Task CreateMultipleReadTest()
        {
            const int count = 10;

            IDocumentDatabase db = _documentServer.GetDatabase(_workContext, _dbName);
            IDocumentCollection <TestDocument> collection = db.GetCollection <TestDocument>(_collectionName);

            var documentList = new List <TestDocument>();

            foreach (var index in Enumerable.Range(0, count))
            {
                TestDocument test = CreateTestDocument(index);
                await collection.Insert(_workContext, test);

                documentList.Add(test);
            }

            IEnumerable <TestDocument> results = await collection.Find(_workContext, new BsonDocument());

            results.Should().NotBeNull();
            results.Count().Should().Be(count);

            int docIndex = 0;

            foreach (var result in results.OrderBy(x => x.Index))
            {
                var test = documentList[docIndex++];

                result.FirstName.Should().Be(test.FirstName);
                result.LastName.Should().Be(test.LastName);
                result.Birthdate.ToString("s").Should().Be(test.Birthdate.ToString("s"));
                result.Address1.Should().Be(test.Address1);
                result.Address2.Should().Be(test.Address2);
                result.City.Should().Be(test.City);
                result.State.Should().Be(test.State);
                result.ZipCode.Should().Be(test.ZipCode);
            }
        }