Пример #1
0
        public async Task Can_delete_resource()
        {
            // Arrange
            Chair existingChair = _fakers.Chair.Generate();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.Chairs.Add(existingChair);
                await dbContext.SaveChangesAsync();
            });

            string route = "/chairs/" + existingChair.StringId;

            // Act
            (HttpResponseMessage httpResponse, _) = await _testContext.ExecuteDeleteAsync <string>(route);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public async Task Cannot_update_resource()
        {
            // Arrange
            Chair existingChair = _fakers.Chair.Generate();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.Chairs.Add(existingChair);
                await dbContext.SaveChangesAsync();
            });

            var requestBody = new
            {
                data = new
                {
                    type       = "chairs",
                    id         = existingChair.StringId,
                    attributes = new
                    {
                    }
                }
            };

            string route = "/chairs/" + existingChair.StringId;

            // Act
            (HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync <ErrorDocument>(route, requestBody);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.MethodNotAllowed);

            responseDocument.Errors.Should().HaveCount(1);

            Error error = responseDocument.Errors[0];

            error.StatusCode.Should().Be(HttpStatusCode.MethodNotAllowed);
            error.Title.Should().Be("The request method is not allowed.");
            error.Detail.Should().Be("Resource does not support PATCH requests.");
        }