Exemplo n.º 1
0
        public async Task AddOnAny_ResponseOK()
        {
            var server = new TestWebServer();

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

            server.RunAsync();

            Assert.AreEqual(Ok, await server.GetClient().GetAsync());
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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));
            }
        }