Example #1
0
        public async void should_handle_search_employee_request()
        {
            var server = new TestServer(WebApplication.CreateWebHost());
            var client = server.CreateClient();

            var response = await client.GetAsync("/employees/search/im");

            var employeeString = await response.Content.ReadAsStringAsync();

            Assert.Contains("Jim", employeeString);
        }
Example #2
0
        public async void should_handle_web_request()
        {
            var server = new TestServer(WebApplication.CreateWebHost());
            var client = server.CreateClient();

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

            var indexString = await response.Content.ReadAsStringAsync();

            Assert.Equal("Hello ASP.NET Core Application.", indexString);
        }
Example #3
0
        private static IServiceProvider SetupApplication(SqliteConnection sqliteConnection, out HttpClient client)
        {
            IServiceProvider appServices = null;

            var server = new TestServer(WebApplication.CreateWebHost(
                                            services =>
            {
                services.AddDbContext <ApplicationDbContext>(options => { options.UseSqlite(sqliteConnection); });
            }, null,
                                            app => appServices = app.ApplicationServices));

            client = server.CreateClient();
            return(appServices);
        }
        public async void should_handle_web_request_with_mocked_component()
        {
            var mockedHttpInvoker = new Mock <IHttpInvoker>();

            mockedHttpInvoker.Setup(s => s.InvokeHttp(It.IsAny <string>())).Returns("{\"color\":\"olive\",\"value\":\"#ab9900\"}");

            var server = new TestServer(WebApplication.CreateWebHost(null, services => services.AddSingleton(typeof(IHttpInvoker), mockedHttpInvoker.Object)));
            var client = server.CreateClient();

            var response = await client.GetAsync("/color");

            var indexString = await response.Content.ReadAsStringAsync();

            Assert.Equal("olive:#ab9900", indexString);
        }
Example #5
0
        public async void should_handle_web_request_with_mocked_service()
        {
            void ConfigServices(IServiceCollection services)
            {
                var helloService = new Mock <HelloWorldService>();

                helloService.Setup(s => s.SayHello()).Returns("Hello from mocked service.");
                services.AddSingleton(helloService.Object);
            }

            var server = new TestServer(WebApplication.CreateWebHost(null, ConfigServices));
            var client = server.CreateClient();

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

            var indexString = await response.Content.ReadAsStringAsync();

            Assert.Equal("Hello from mocked service.", indexString);
        }