markvincze / Stubbery

Library for creating Api stubs in .NET. https://markvincze.github.io/Stubbery/
MIT License
74 stars 14 forks source link

handling template parse failure #35

Open jkone27 opened 3 years ago

jkone27 commented 3 years ago

This ignores invalid routes passed to stubs, so allows this new test to pass (before was red, as one failing parse fails all others after it)

[Fact]
        public async Task MultipleSetups_OneHasWrongRoute_OthersStillMatch()
        {
            using var sut = new ApiStub();

            sut.Get("/testget/one", (req, args) => "testresponse1");
            sut.Get("/testget//two", (req, args) => "doesn't match"); /////// THIS ONE HERE would let last one fail without this fix
            sut.Get("/testget/three", (req, args) => "testresponse3");

            sut.Start();

            var result3 = await httpClient.GetAsync(new UriBuilder(new Uri(sut.Address))
            {
                Path = "/testget/three"
            }.Uri);

            Assert.Equal(HttpStatusCode.OK, result3.StatusCode);

            var resultString = await result3.Content.ReadAsStringAsync();

            Assert.Equal("testresponse3", resultString);
        }

a future improvement could be to add validation at route condition setup, so that a validation exception is thrown there...

but this require some other changes here and there i suppose

 public RouteCondition(string route)
        {
            this.route = route.TrimStart('/');
        }