本文整理汇总了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);
}
示例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);
});
}
示例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);
}
});
}