WEB API 2 - MSPEC ShouldEqual Issue

46 views
Skip to first unread message

Imran Azad

unread,
Jan 9, 2016, 12:39:39 PM1/9/16
to machine_users

 have a controller with the following method signature

public IHttpActionResult GetResults(string searchQuery, int from = 0)

Now before people start complaining why I've not included the rest of the body of the controller, I can assure you it's because it is not relevant. The next relevant bit is the exception handler:

        catch (Exception ex)
        {
            Exceptions.Failed(ex, Request);
            var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent("Elasticsearch is down"),
            };
                throw new HttpResponseException(resp);
        }  

Here is my unit test:

    public class when_elastic_is_down : setup_controller
    {
        private Because of = () => results = controller.GetResults("moxi");

        private It should_not_return_500 =
            () => (results as HttpResponseMessage).StatusCode.ShouldEqual(500);

    }

The problem I'm having is that intellisense reports the following error on ShouldEqual:

 The type arguments for method 'T Machine.Specification.ShouldExtensionMethods.ShouldEqual<T>(this, T,T)' cannot be inferred from the usage. Try specifying the arguments explicitly.


Can someone explain why I'm not able to check the property of StatusCode?


Alexander Groß

unread,
Jan 9, 2016, 12:44:15 PM1/9/16
to machin...@googlegroups.com
HttpResponseMessage.StatusCode is of type HttpStatusCode. Try the comparison against a member of that type.

(results as HttpResponseMessage).StatusCode.ShouldEqual(HttpStatusCode.InternalServerError);

Beste Grüße,

Alex
-- 
Alexander Groß
http://therightstuff.de/

--
You received this message because you are subscribed to the Google Groups "machine_users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to machine_user...@googlegroups.com.
To post to this group, send email to machin...@googlegroups.com.
Visit this group at https://groups.google.com/group/machine_users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages