{"action":"created","issue":{"url":"https://api.github.com/repos/shouldly/shouldly/issues/190","labels_url":"https://api.github.com/repos/shouldly/shouldly/issues/190/labels{/name}","comments_url":"https://api.github.com/repos/shouldly/shouldly/issues/190/comments","events_url":"https://api.github.com/repos/shouldly/shouldly/issues/190/events","html_url":"https://github.com/shouldly/shouldly/issues/190","id":63850817,"number":190,"title":"Allow custom/additional message to ShouldlyMessage","user":{"login":"aaronpowell","id":434140,"avatar_url":"https://avatars.githubusercontent.com/u/434140?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronpowell","html_url":"https://github.com/aaronpowell","followers_url":"https://api.github.com/users/aaronpowell/followers","following_url":"https://api.github.com/users/aaronpowell/following{/other_user}","gists_url":"https://api.github.com/users/aaronpowell/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronpowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronpowell/subscriptions","organizations_url":"https://api.github.com/users/aaronpowell/orgs","repos_url":"https://api.github.com/users/aaronpowell/repos","events_url":"https://api.github.com/users/aaronpowell/events{/privacy}","received_events_url":"https://api.github.com/users/aaronpowell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-03-23T22:39:40Z","updated_at":"2015-03-25T23:25:43Z","closed_at":null,"body":"I think this is related to #52 but figured I'd like to add it anyway.\r\n\r\nI'd **really** like a way to provide a custom message to the 'assert' that is executed.\r\n\r\nScenario:\r\n\r\n> I am doing a HTTP Request, I expect an `OK` response, I get `Internal Server Error`. I'd like to add to the message the server response.\r\n\r\nHere's a sample of how I'd see the API working:\r\n\r\n    [Fact]\r\n    public async Task Should_return_OK() {\r\n        var response = await GetAsync(\"/api/something\");\r\n        \r\n        response.StatusCode.ShouldBe(HttpStatusCode.OK, () => response.Content.ReadAsStringAsync().Result);\r\n    }\r\n\r\nNotice the use of the lambda for the additional message, this prevents the code from being executed unless the Should fails, so if you're doing something complex or that has side effects (ie - reading the a HTTP response) it will only be done if needed.\r\n\r\nThe invocation of the lambda should be in a `try/catch` itself and if it throws just do a `Debug.WriteLine` with the exception (or something similar) and add something to the output message that the additional message failed."},"comment":{"url":"https://api.github.com/repos/shouldly/shouldly/issues/comments/86251089","html_url":"https://github.com/shouldly/shouldly/issues/190#issuecomment-86251089","issue_url":"https://api.github.com/repos/shouldly/shouldly/issues/190","id":86251089,"user":{"login":"aaronpowell","id":434140,"avatar_url":"https://avatars.githubusercontent.com/u/434140?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronpowell","html_url":"https://github.com/aaronpowell","followers_url":"https://api.github.com/users/aaronpowell/followers","following_url":"https://api.github.com/users/aaronpowell/following{/other_user}","gists_url":"https://api.github.com/users/aaronpowell/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronpowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronpowell/subscriptions","organizations_url":"https://api.github.com/users/aaronpowell/orgs","repos_url":"https://api.github.com/users/aaronpowell/repos","events_url":"https://api.github.com/users/aaronpowell/events{/privacy}","received_events_url":"https://api.github.com/users/aaronpowell/received_events","type":"User","site_admin":false},"created_at":"2015-03-25T23:25:43Z","updated_at":"2015-03-25T23:25:43Z","body":"@xerxesb Sure, I get that that's what Shouldly is about, useful messages without you having to write them yourself. The problem that can happen comes back to what you mention, context. Sometimes context requires more information than can be gained from the particular object you're asserting against, as in my original example.\r\n\r\nHere's an example from our build server:\r\n\r\n    Shouldly.ChuckedAWobbly : \r\n         var messages = await message.Content.ReadAsAsync<IEnumerable<ApiMessage>>();\r\n\r\n                 messages.Count()\r\n             should be\r\n         HttpStatusCode.BadRequest\r\n             but was\r\n         HttpStatusCode.Forbidden\r\n\r\nThe test body looks like so:\r\n\r\n    var message = await PutAsync(Urls.Administration.Alert(Id), new EventAlertDefinitionModel\r\n                {\r\n                    ...\r\n                });\r\n    message.StatusCode.ShouldBe(HttpStatusCode.BadRequest);\r\n\r\n    var messages = await message.Content.ReadAsAsync<IEnumerable<ApiMessage>>();\r\n\r\n    messages.Count().ShouldBe(1);\r\n\r\nThere's a bit of context lost here that I'd like to add in the event of failure, what was the response body for example.\r\n\r\nSure I could use some other assert framework but then that means I've got two ways to do asserts which is just a PIA.\r\n\r\nI understand and respect the goals of Shouldly, I'm just looking for options on how to make it even better for those edge-cases where context is more uniquely defined."}}