예제 #1
0
        public async Task Create_ServiceError_BadRequest()
        {
            // Setup
            var id    = "some_id";
            var input = new CreatePublicationModel
            {
                Content = "some content"
            };

            var publication = new Publication(id, input.Content, Enumerable.Empty <string>(), null, DateTimeOffset.Now, DateTimeOffset.Now);

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.UpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(DomainResult.Error("Some error"));

            serviceMock
            .Setup(s => s.GetByIdAsync(id))
            .ReturnsAsync(publication);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
예제 #2
0
        public async Task Create_EmptyContent_BadRequest()
        {
            // Setup
            var input = new CreatePublicationModel
            {
                Content = null
            };

            var serviceMock = new Mock <IPublicationService>();

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PostAsync("/publications/", input.AsJsonContent());

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