Example #1
0
 public void SetupInMemoryWebServer_ReturnsValidInstance()
 {
     using (var webserver = new TestWebServer())
     {
         Assert.IsNotNull(webserver);
     }
 }
        public void RegisterSessionModule_ReturnsValidInstance()
        {
            var webserver = new TestWebServer();

            webserver.RegisterModule(new LocalSessionModule());

            Assert.NotNull(webserver.SessionModule);
        }
        public void RegisterWebModule_ReturnsValidInstance()
        {
            var webserver = new TestWebServer();

            webserver.RegisterModule(new FallbackModule((ctx, ct) => ctx.JsonResponse(nameof(TestWebServer))));

            Assert.AreEqual(1, webserver.Modules.Count);
        }
Example #4
0
        public void UnregisterSessionModule_ReturnsValidInstance()
        {
            using (var webserver = new TestWebServer())
            {
                webserver.RegisterModule(new LocalSessionModule());
                webserver.UnregisterModule(typeof(LocalSessionModule));

                Assert.IsNull(webserver.SessionModule);
            }
        }
Example #5
0
        public void UnregisterWebModule_ReturnsValidInstance()
        {
            using (var webserver = new TestWebServer())
            {
                webserver.RegisterModule(new FallbackModule((ctx, ct) => ctx.JsonResponseAsync(nameof(TestWebServer), ct)));
                webserver.UnregisterModule(typeof(FallbackModule));

                Assert.AreEqual(0, webserver.Modules.Count);
            }
        }
Example #6
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());
        }
Example #7
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());
        }
Example #8
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");
            }
        }
        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));
        }
Example #10
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));
            }
        }