Esempio n. 1
0
        public async Task AddOnGet_ResponseOK()
        {
            var server = new TestWebServer();

            server
            .OnGet((ctx, ct) => ctx.StringResponseAsync(Ok, cancellationToken: ct));

            server.RunAsync();

            Assert.AreEqual(Ok, await server.GetClient().GetAsync());
        }
Esempio n. 2
0
        public async Task AddOnOptions_ResponseOK()
        {
            var server = new TestWebServer();

            server
            .OnOptions((ctx, ct) => ctx.StringResponseAsync(Ok, cancellationToken: ct));

            server.RunAsync();

            var response = await server.GetClient().SendAsync(new TestHttpRequest(Constants.HttpVerbs.Options));

            Assert.AreEqual(Ok, response.GetBodyAsString());
        }
Esempio n. 3
0
        public async Task RunsServerAndRequestData_ReturnsValidData()
        {
            using (var webserver = new TestWebServer())
            {
                webserver.RegisterModule(new FallbackModule((ctx, ct) => ctx.JsonResponse(new Person {
                    Name = "Test"
                })));
                webserver.RunAsync();

                var client = webserver.GetClient();

                var data = await client.GetAsync("http://test/");

                Assert.IsNotNull(data);

                var person = Json.Deserialize <Person>(data);
                Assert.IsNotNull(person);

                Assert.AreEqual(person.Name, "Test");
            }
        }
Esempio n. 4
0
        public async Task RunsServerAndRequestData_ReturnsValidData()
        {
            var webserver = new TestWebServer();

            webserver.OnAny((ctx, ct) => ctx.JsonResponse(new Person {
                Name = nameof(Person)
            }));

            webserver.RunAsync();

            var client = webserver.GetClient();

            var data = await client.GetAsync("/");

            Assert.IsNotNull(data);

            var person = Json.Deserialize <Person>(data);

            Assert.IsNotNull(person);

            Assert.AreEqual(person.Name, nameof(Person));
        }
Esempio n. 5
0
        public async Task RunsServerAndRequestData_ReturnsValidData()
        {
            using (var webserver = new TestWebServer())
            {
                webserver.OnAny((ctx, ct) => ctx.JsonResponseAsync(new Person {
                    Name = nameof(Person)
                }, ct));

#pragma warning disable 4014
                webserver.RunAsync();
#pragma warning restore 4014

                var client = webserver.GetClient();

                var data = await client.GetAsync("/");

                Assert.IsNotNull(data);

                var person = Json.Deserialize <Person>(data);
                Assert.IsNotNull(person);

                Assert.AreEqual(person.Name, nameof(Person));
            }
        }