Beispiel #1
0
        public void DeleteCommentByCloudId_WhenEmptyContext_ReturnsUnsuccessfulOperation()
        {
            // Arrange
            var commentsCount = _appDbContext.Comments.Count();
            var cloudId       = 1;

            // Act
            var operationResult             = _commentManager.DeleteByCloudIdAsync(cloudId).GetAwaiter().GetResult();
            var commentsCountAfterOperation = _appDbContext.Comments.Count();

            // Assert
            Assert.Equal(0, operationResult);
            Assert.Equal(commentsCount, commentsCountAfterOperation);
        }
        /// <inheritdoc/>
        public async Task DeleteAsync()
        {
            _logger.LogInformation(SyncMessage.CommentDeleteStart);

            var commentsCloud = await _cloudManager.GetComments().ToListAsync();

            var commentsApp = (await _commentManager.GetAllAsync()).ToList();

            var commentCloudIds = commentsCloud.Select(c => c.Id);
            var commentAppIds   = commentsApp.Select(c => c.CloudId);

            var deleteIds = commentAppIds.Except(commentCloudIds);

            if (deleteIds.Any())
            {
                foreach (var id in deleteIds)
                {
                    await _commentManager.DeleteByCloudIdAsync(id);
                }
            }

            _logger.LogInformation(SyncMessage.CommentDeleteEnd);
        }