コード例 #1
0
ファイル: HostUtilsTests.cs プロジェクト: dmitriyse/ClrCoder
        public async Task HostControllerTest()
        {
            var baseUrl = "http://localhost:5082";

            using (IWebHost host = HostUtils.HostController <RightController>(baseUrl))
            {
                (await new Url(baseUrl).AppendPathSegment("/tst").GetAsync().ReceiveString())
                .Should()
                .Be("RightController");
            }
        }
コード例 #2
0
        public async Task FlurlHttpExtensionsTest(string host, string dnsOrIp, string pathSegment)
        {
            try
            {
                using (HostUtils.HostController <TestFlurlController>(host))
                {
                    string response = await new Url(dnsOrIp).AppendPathSegment(pathSegment).GetAsync().ReceiveString();
                    if ((pathSegment == "Flurl") && (host == "http://localhost:5062"))
                    {
                        response.Should().BeEquivalentTo("Hello");
                    }
                }
            }
            catch (FlurlHttpTimeoutException)
            {
                TestContext.WriteLine("FlurlHttpTimeoutException");
            }
            catch (FlurlHttpException ex)
            {
                if (dnsOrIp == "http://nobody-knows-me-99923.com")
                {
                    ex.IsDnsResolveError().Should().Be(true);
                }
                else
                {
                    ex.IsDnsResolveError().Should().Be(false);
                }

                if ((dnsOrIp == "http://10.110.110.110/") || (dnsOrIp == "http://46.20.65.243:22222/"))
                {
                    ex.IsIpNotAvailable().Should().Be(true);
                }
                else
                {
                    ex.IsIpNotAvailable().Should().Be(false);
                }
            }
        }
コード例 #3
0
        public async Task SendJsonAsyncWithDumpTest()
        {
            var data = new MethodInfoDto
            {
                Name         = "name",
                TypeFullName = "fullname"
            };

            IJsonLogger logger = new NUnitJsonLogger(SyncHandler.Instance);

            using (HostUtils.HostController <TestFlurlController>("http://localhost:5062"))
            {
                string response = await new Url("http://localhost:5062")
                                  .AppendPathSegment("Flurl")
                                  .WithDump(logger)
                                  .PostJsonAsync(data)
                                  .ReceiveString();

                var responseData = JsonConvert.DeserializeObject <MethodInfoDto>(response);
                responseData.Should().NotBeNull();
                responseData.Name.Should().Be(data.Name);
                responseData.TypeFullName.Should().Be(data.TypeFullName);
            }
        }