当前位置: 首页>>代码示例>>C#>>正文


C# App.AddStaticStringView方法代码示例

本文整理汇总了C#中System.App.AddStaticStringView方法的典型用法代码示例。如果您正苦于以下问题:C# App.AddStaticStringView方法的具体用法?C# App.AddStaticStringView怎么用?C# App.AddStaticStringView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.App的用法示例。


在下文中一共展示了App.AddStaticStringView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Requests_ParallelRequests

        public void Requests_ParallelRequests()
        {
            var expectedResponse = "Hello World";

            var app = new App();
            app.AddStaticStringView("/", (c) => expectedResponse);

            Action InnerTest = () =>
            {
                var clientThreads = new Thread[10];
                for (int i = 0; i < 10; i++)
                {
                    clientThreads[i] = new Thread(() =>
                    {
                        var client = new WebClient();
                        var actualResponse = client.DownloadString(TestUtils.AppPrefix);
                        Assert.AreEqual(expectedResponse, actualResponse);
                    });
                }

                for (int i = 0; i < 10; i++)
                    clientThreads[i].Start();
                for (int i = 0; i < 10; i++)
                    clientThreads[i].Join();
            };

            // First, test without async request processing
            app.EnableAsyncProcessing = false;
            TestUtils.AppTest(app, InnerTest);

            app.EnableAsyncProcessing = true;
            TestUtils.AppTest(app, InnerTest);
        }
开发者ID:RailPhase,项目名称:RailPhase,代码行数:33,代码来源:Requests.cs

示例2: Requests_SimpleRequest

        public void Requests_SimpleRequest()
        {
            var expectedResponse = "Hello World";

            var app = new App();
            app.AddStaticStringView("/", (c) => expectedResponse);

            TestUtils.AppTest(app, () =>
            {
                var client = new WebClient();
                var actualResponse = client.DownloadString(TestUtils.AppPrefix);
                Assert.AreEqual(expectedResponse, actualResponse);
            });
        }
开发者ID:RailPhase,项目名称:RailPhase,代码行数:14,代码来源:Requests.cs

示例3: UrlPatterns_ConstUrls

        public void UrlPatterns_ConstUrls()
        {
            // Generate many random strings and make sure they work correctly with the app.AddUrl view.
            var urls = new Dictionary<string, int>();

            var app = new App();

            for (int i = 0; i < 100; i++)
            {
                var randomString = TestUtils.GenerateRandomURL(100);
                if (!urls.ContainsKey(randomString))
                {
                    int response = i;
                    urls[randomString] = response;
                    app.AddStaticStringView(randomString, (c) => response.ToString());
                }
            }

            TestUtils.AppTest(app, () =>
            {
                var client = new WebClient();

                foreach (var url in urls.Keys)
                {
                    var expectedResult = urls[url].ToString();
                    string result = null;
                    try
                    {
                        result = client.DownloadString(TestUtils.AppPrefix + url);
                    }
                    catch(WebException webException)
                    {
                        throw new WebException($"Failure on URL '{TestUtils.AppPrefix + url}': {webException.Message}", webException);
                    }
                    Assert.AreEqual(expectedResult, result);
                }
            });
        }
开发者ID:RailPhase,项目名称:RailPhase,代码行数:38,代码来源:UrlPatterns.cs


注:本文中的System.App.AddStaticStringView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。