Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public Task <int> Delete(IWorkContext context, string roleId, string eTag = null)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotEmpty(nameof(roleId), roleId);
            context = context.WithTag(_tag);

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId))) == roleId);

            if (eTag.IsNotEmpty())
            {
                query += (new Field(nameof(HeaderDoc <UserRoleDoc> .ETag)) == eTag);
            }

            return(_collection.Delete(context, query.ToDocument()));
        }
Exemplo n.º 3
0
 public void DeleteFriend(string swid)
 {
     try
     {
         uint[] array = EnumerateFriendDocumentIds(friends, swid).ToArray();
         foreach (uint documentId in array)
         {
             friends.Delete(documentId);
         }
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Exemplo n.º 4
0
 public void RemoveAlert(long alertId)
 {
     try
     {
         uint[] array = EnumerateAlertIds(alertId).ToArray();
         foreach (uint documentId in array)
         {
             alerts.Delete(documentId);
         }
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Exemplo n.º 5
0
        public Task <int> Delete(IWorkContext context, string userName, string eTag = null)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotEmpty(nameof(userName), userName);
            context = context.WithTag(_tag);

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserDoc.NormalizedUserName))) == userName.ToLowerInvariant());

            if (eTag.IsNotEmpty())
            {
                query += (new Field(nameof(HeaderDoc <UserDoc> .ETag)) == eTag);
            }

            return(_collection.Delete(context, query.ToDocument()));
        }
Exemplo n.º 6
0
 public void DeleteFriendInvitation(long invitationId)
 {
     try
     {
         uint[] array  = friendInvitations.FindDocumentIdsEqual(FriendInvitationDocument.FriendInvitationIdFieldName, invitationId).ToArray();
         uint[] array2 = array;
         foreach (uint documentId in array2)
         {
             friendInvitations.Delete(documentId);
         }
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public void Handle(TableArchived e)
 {
     _tables.Delete(e.Id);
 }
Exemplo n.º 9
0
 public void Handle(UserDeleted e)
 {
     _users.Delete(e.Id);
 }
Exemplo n.º 10
0
 public void Delete(string key)
 {
     _collection.Delete(key);
 }