question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extensions for HttpResponseMessage

See original GitHub issue

Extensions for HttpResonseMessage to be used in rest api tests

I have written a few custom extensions that can be used in integration tests targeting rest apis. They are meant to be used in typically these scenarios:

var model= new RestModel();
PostResource(model);
HttpResonseMessage response = GetResource();

//assert
response.Should().Be200();
response.Should().HaveBody(model);

Since testing rest apis is quite common, I would like to contribute those into fluentassertions in some forms. However, i am not sure if this repository is the best place, or if they should be compiled into a separate library with a dependency on the core fluentassertions package. Unfortunately i don’t have the time to maintain a github project on my own.

Here are some examples, that you will hopefully find useful.

_httpResponseMessage.Should().Be200(); // there is support for even more common status codes
_httpResponseMessage.Should().HaveBody(restModel); 
_httpResponseMessage.Should().HaveBodyExcluding(_restModel, x => x.PropertyToExclude); 
_httpResponseMessage.Should().HaveBodyIncluding(_restModel, x => x.PropertyToInclude); 
_httpResponseMessage.Should().HaveBodyWithProperty<RestModel>(x => x.MyProperty, expectedValue);
_httpResponseMessage.Should().ContainText("\"MyProperty\":5");
_httpResponseMessage.Should().NotContainText("\"MyProperty\":5");

This targets the full .net framework, and tested on net461 I am using FluentAssertions 5.4.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
balanikascommented, Feb 4, 2019

Thanks for feedback, and I agree with your reasoning. I created this separate package instead, https://www.nuget.org/packages/FluentAssertions.Http/1.0.0-beta1

Can I close this issue now? Or should I leave it?

0reactions
balanikascommented, Feb 4, 2019

Thanks @dennisdoomen I will let it mature a bit and then let you know

Read more comments on GitHub >

github_iconTop Results From Across the Web

HttpResponseMessageExtensio...
Creates a Message instance from an HttpResponseMessage instance. ... HttpResponseMessage instance by calling the ToHttpResponseMessage extension method.
Read more >
HttpResponseMessage Class (System.Net.Http)
Creates a shallow copy of the current Object. (Inherited from Object). ToString(). Returns a string that represents the current object. Extension Methods ...
Read more >
Class HttpResponseMessageExtensions
Extensions for HttpResponseMessage class. ... Methods. GetHttpAndContentHeaders(HttpResponseMessage). Gets headers from the http response and the content.
Read more >
Soenneker.Extensions.HttpResponseMessage 1.0.56
Version Downloads Last updated 1.0.160 41 a day ago 1.0.159 34 a day ago 1.0.158 47 2 days ago
Read more >
Soenneker.Extensions.HttpResponseMessage 1.0.151
Version Downloads Last updated 1.0.155 43 a day ago 1.0.154 33 4 days ago 1.0.153 62 5 days ago
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found