コード例 #1
0
        public async Task Comment_NotFound()
        {
            // Setup
            var userId    = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C6");
            var commentId = Guid.NewGuid().ToString();

            const string content = "New Content";

            NewsFeedCommentsStorageMock
            .Setup(s => s.GetByIdAsync(commentId))
            .ReturnsAsync(default(PublicationComment));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => NewsFeedStorageMock.Object);
            });

            var input = new UpdateNewsFeedComment {
                Content = content
            };

            // Act
            var response = await client.PutAsync($"/newsfeed/comments/{commentId}", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
コード例 #2
0
        public async Task Comment_BadRequest()
        {
            // Setup
            var userId        = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C6");
            var publicationId = Guid.NewGuid().ToString();
            var commentId     = Guid.NewGuid().ToString();

            const string oldContent = "Old Content";
            string       newContent = string.Empty;

            NewsFeedCommentsStorageMock
            .Setup(s => s.GetByIdAsync(commentId))
            .ReturnsAsync(
                new PublicationComment(
                    commentId,
                    oldContent,
                    publicationId,
                    new UserInfo(userId, string.Empty, null),
                    DateTimeOffset.Now));

            NewsFeedCommentsStorageMock
            .Setup(s => s.UpdateAsync(commentId, newContent))
            .ThrowsAsync(new ApiException {
                ErrorCode = (int)HttpStatusCode.BadRequest
            });

            CurrentUserProviderMock
            .Setup(s => s.UserId)
            .Returns(userId.ToString());

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => NewsFeedStorageMock.Object);
                collection.AddScoped(_ => CurrentUserProviderMock.Object);
            });

            var input = new UpdateNewsFeedComment {
                Content = newContent
            };

            // Act
            var response = await client.PutAsync($"/newsfeed/comments/{commentId}", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }