Пример #1
0
        public void ShouldReturnCorrectResourceWhenMatchingParameters()
        {
            _server.OnGet("/stuff").RespondWith("yes, tc1");
            _server.OnGet("/stuff", new { p = "1" }).RespondWith("yes, tc2");
            _server.OnGet("/stuff", new { p = "(2+4)*10=60" }).RespondWith("yes, tc3");
            _server.OnGet("/stuff", new { p = ParamIs.Equal("2") }).RespondWith("yes, tc4");
            _server.OnGet("/stuff", new { p = ParamIs.AllOf("3", "4") }).RespondWith("yes, tc5");
            _server.OnGet("/stuff", new { p = ParamIs.AnyOf("5", "6", "7") }).RespondWith("yes, tc6");
            _server.OnGet("/stuff", new { p = ParamIs.Like("^9[0-5]$") }).RespondWith("yes, tc7");
            _server.OnGet("/stuff", new { p = ParamIs.Like(new Regex("^9[6-9]$")) }).RespondWith("yes, tc8");
            _server.OnGet("/stuff", new { i = ParamIs.Int() }).RespondWith("yes, tc9");
            _server.OnGet("/stuff", new { j = ParamIs.Int().GreaterThanZero() }).RespondWith("yes, tc10");
            _server.OnGet("/stuff", new { k = ParamIs.Int().GreaterThanOrEqualToZero() }).RespondWith("yes, tc11");
            _server.OnGet("/stuff", new { m = ParamIs.Int().LessThanZero() }).RespondWith("yes, tc12");
            _server.OnGet("/stuff", new { g = ParamIs.Int().LessThanOrEqualToZero() }).RespondWith("yes, tc13");
            _server.OnGet("/stuff", new { id = 901, myKey = ParamIs.Equal("Yes").Optional() }).RespondWith("yes, tc101");
            _server.OnGet("/stuff", new { id = 902, myKey = ParamIs.Equal("Yes").Optional().IgnoreCase() }).RespondWith("yes, tc102");
            var client = new HttpClient();

            Assert.That(client.GetAsync(Url("/stuff")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc1"));
            Assert.That(client.GetAsync(Url("/stuff?p=1")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc2"));
            Assert.That(client.GetAsync(Url("/stuff?p=(2%2b4)*10%3d60")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc3"));
            Assert.That(client.GetAsync(Url("/stuff?p=2")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc4"));
            Assert.That(client.GetAsync(Url("/stuff?p=3&p=4")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc5"));
            Assert.That(client.GetAsync(Url("/stuff?p=5&p=7")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc6"));
            Assert.That(client.GetAsync(Url("/stuff?p=91")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc7"));
            Assert.That(client.GetAsync(Url("/stuff?p=99")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc8"));
            Assert.That(client.GetAsync(Url("/stuff?i=123")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc9"));
            Assert.That(client.GetAsync(Url("/stuff?i=-123")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc9"));
            Assert.That(client.GetAsync(Url("/stuff?j=1")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc10"));
            Assert.That(client.GetAsync(Url("/stuff?j=2")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc10"));
            Assert.That(client.GetAsync(Url("/stuff?k=0")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc11"));
            Assert.That(client.GetAsync(Url("/stuff?k=1")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc11"));
            Assert.That(client.GetAsync(Url("/stuff?m=-1")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc12"));
            Assert.That(client.GetAsync(Url("/stuff?m=-2")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc12"));
            Assert.That(client.GetAsync(Url("/stuff?g=0")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc13"));
            Assert.That(client.GetAsync(Url("/stuff?g=-1")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc13"));
            Assert.That(client.GetAsync(Url("/stuff?id=901")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc101"));
            Assert.That(client.GetAsync(Url("/stuff?id=901&myKey=Yes")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc101"));
            Assert.That(client.GetAsync(Url("/stuff?id=902")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc102"));
            Assert.That(client.GetAsync(Url("/stuff?id=902&myKey=Yes")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc102"));
            Assert.That(client.GetAsync(Url("/stuff?id=902&myKey=yes")).Result.Content.ReadAsStringAsync().Result, Is.EqualTo("yes, tc102"));
        }