Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to assert invoked Uris? #31

Open
Kralizek opened this issue Feb 13, 2018 · 4 comments
Open

Possibility to assert invoked Uris? #31

Kralizek opened this issue Feb 13, 2018 · 4 comments

Comments

@Kralizek
Copy link

Hi,

I'm using your library to author some tests and I got myself in the situation where my API client is forming a URL by adding many components both in the path and the querystring.

My test is targeting only a subsection of the requested URI and I would like to "test" it. Ideally on the used option.

To make a concrete example

var option = new HttpMessageOptions
{
    HttpMethod = HttpMethod.Get,
    HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
    {
        Content = new StringContent(JsonConvert.SerializeObject(contact))
    },
    RequestUri = null 
};

var sut = CreateSystemUnderTest(option);

var response = await sut.GetByIdAsync(contactId);

Assert.That(option.InvokedUri, Contains.SubString($"/contacts/v1/contact/vid/{contactId}"));

Right now I am forced to do:

var options = new HttpMessageOptions
{
    HttpMethod = HttpMethod.Get,
    HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
    {
        Content = new StringContent(JsonConvert.SerializeObject(contact))
    },
    RequestUri = new Uri($"https://api.hubapi.com/contacts/v1/contact/vid/{contactId}/profile?formSubmissionMode=all&propertyMode=value_and_history&showListMemberships=true")
};

which is really outside of the scope of my unit test.

@PureKrome PureKrome self-assigned this May 24, 2019
@PureKrome PureKrome added this to the 7.0.0 milestone May 24, 2019
@PureKrome
Copy link
Owner

Hi again @Kralizek 👋

Hmm .. lets see here ...I first added this way back in #12 over here.

I just need to add some documentation to show how to do this.

In the mean time, here's an example using your code-example, above:

// Act.
var response = await sut.GetByIdAsync(contactId);

// Assert.
Assert.That(option.NumberOfTimesCalled, 1);

So what is happening is that we check that all the conditions of the Options was met and passed and the number of times it was met.

Does this help?

@Kralizek
Copy link
Author

I'm not sure it would help my case (although I barely remember what I was working on back then).

I guess this would go in hand with the default registration we are discussing in #32.

Let RequestUri be optional and allow the test on the actual call.

Back to the first snippet, you could read its assertion as "I will receive a GET request whose URI will contain a subscring matching this pattern".

@PureKrome
Copy link
Owner

Currently, options.RequestUri is optional. 👍

"I will receive a GET request whose URI will contain a substring matching this pattern".

kewl! to do that, then you do exactly as you did, above ... and make then test that the option you just made, was called :)

which is the code I did above. Kewl!

@Kralizek
Copy link
Author

Thanks! I'll check later :)

@PureKrome PureKrome modified the milestones: 7.0.0, Backlog Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants