hibri / HttpMock

A library for creating Http servers on the fly in tests and stubbing responses
MIT License
128 stars 44 forks source link

WithURLConstraint is not stub-specific #51

Closed neoistheone123 closed 8 years ago

neoistheone123 commented 8 years ago
        IHttpServer serverA = null;

        serverA = HttpMockRepository.At("http://localhost:10100");
        serverA.Stub(x => x.Get("/PingList")).WithUrlConstraint(u => u.Contains("date=1-2")).Return("1").OK();
        serverA.Stub(x => x.Get("/PingList")).WithUrlConstraint(u => u.Contains("date=1-2-3")).Return("2").OK();

        var client = new RestClient("http://localhost:10100");
        var request = new RestRequest("PingList", Method.GET);
        request.AddQueryParameter("date", "1-2");
        var resp = client.Execute(request);
        resp.Content.Should().Contain("1");

        request = new RestRequest("PingList", Method.GET);
        request.AddQueryParameter("date", "1-2-3");
        resp = client.Execute(request);
        resp.Content.Should().Contain("2");

        serverA = serverA.WithNewContext();
        serverA.Stub(x => x.Get("/PingList")).WithUrlConstraint(u => u.Contains("date=1-2")).Return("1").OK();
        serverA.Stub(x => x.Get("/PingList")).WithUrlConstraint(u => u.Contains("date=1-2-3")).Return("2").OK();

        request = new RestRequest("PingList", Method.GET);
        request.AddQueryParameter("date", "1-2");
        resp = client.Execute(request);
        resp.Content.Should().Contain("1");

        request = new RestRequest("PingList", Method.GET);
        request.AddQueryParameter("date", "1-2-3");
        resp = client.Execute(request);
        resp.Content.Should().Contain("2");

        serverA.Dispose();

Result Message: Expected string "1" to contain "2".

neoistheone123 commented 8 years ago
       IHttpServer serverA = null;

        serverA = HttpMockRepository.At("http://localhost:10100");
        serverA.Stub(x => x.Get("/PingList")).WithUrlConstraint(u => u.Contains("date=1-2")).Return("1").OK();
        serverA.Stub(x => x.Get("/PingList")).WithUrlConstraint(u => u.Contains("date=1-2-3")).Return("2").OK();

        var client = new RestClient("http://localhost:10100");
        var request = new RestRequest("PingList", Method.GET);
        request.AddQueryParameter("date", "1-2");
        var resp = client.Execute(request);
        resp.Content.Should().Contain("1");

        request = new RestRequest("PingList", Method.GET);
        request.AddQueryParameter("date", "1-2-3");
        resp = client.Execute(request);
        resp.Content.Should().Contain("2");

        serverA.Dispose();

Result Message: Expected string "1" to contain "2".