Beispiel #1
0
        public void GetPostByCloudId_WhenEmptyContext_ReturnsNull()
        {
            // Arrange
            var cloudId = 1;

            // Act
            var postDto = _postManager.GetByCloudIdAsync(cloudId).GetAwaiter().GetResult();

            // Assert
            Assert.Null(postDto);
        }
        /// <inheritdoc/>
        public async Task UpdateAsync()
        {
            _logger.LogInformation(SyncMessage.CommentUpdateStart);

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

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

            foreach (var commentApp in commentsApp)
            {
                var commentCloud = commentsCloud.FirstOrDefault(c => c.Id == commentApp.CloudId);
                var postApp      = await _postManager.GetAsync(commentApp.PostId);

                var isUpdated = false;

                if (postApp.CloudId != commentCloud.PostId)
                {
                    var postId = (await _postManager.GetByCloudIdAsync(commentCloud.Id)).Id;
                    commentApp.PostId = postId;
                    isUpdated         = true;
                }

                if (commentApp.Name != commentCloud.Name)
                {
                    commentApp.Name = commentCloud.Name;
                    isUpdated       = true;
                }

                if (commentApp.Email != commentCloud.Email)
                {
                    commentApp.Email = commentCloud.Email;
                    isUpdated        = true;
                }

                if (commentApp.Body != commentCloud.Body)
                {
                    commentApp.Body = commentCloud.Body;
                    isUpdated       = true;
                }

                if (isUpdated)
                {
                    await _commentManager.UpdateAsync(commentApp);
                }
            }

            _logger.LogInformation(SyncMessage.CommentUpdateEnd);
        }