enable internet server for development

This commit is contained in:
Tian Liao 2024-11-25 15:47:56 +08:00
commit b159a89570
3 changed files with 10 additions and 25 deletions

View file

@ -63,5 +63,6 @@
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="internetClientServer"/>
</Capabilities>
</Package>

View file

@ -40,7 +40,15 @@ namespace CalculatorUITestFramework
private static void OnGetContext(IAsyncResult result)
{
var listener = (HttpListener)result.AsyncState;
var context = listener.EndGetContext(result);
HttpListenerContext context;
try
{
context = listener.EndGetContext(result);
}
catch (HttpListenerException)
{
return;
}
var request = context.Request;
var response = context.Response;
if (request.HttpMethod == "GET" && TryGetServerFile(request.Url, out var content))

View file

@ -26,7 +26,6 @@ namespace CalculatorUITests
{
// Create session to launch a Calculator window
_currencyServer = new MockedCurrencyServer();
Thread.Sleep(5000);
CalculatorDriver.Instance.SetupCalculatorSession(context);
}
@ -47,10 +46,7 @@ namespace CalculatorUITests
[TestInitialize]
public void TestInit()
{
VerifyConnection("http://localhost/calctesting/file/?id=currency+converter+data&localCurrency=en-US");
VerifyConnection("http://localhost/calctesting/file/?id=currency+static+data&localizeFor=en-US");
CalculatorApp.EnsureCalculatorHasFocus();
Thread.Sleep(5000);
page.EnsureCalculatorIsCurrencyMode();
page.EnsureCalculatorResultTextIsZero();
page.EnsureSameUnitsAreSelected();
@ -62,26 +58,6 @@ namespace CalculatorUITests
page.ClearAll();
}
private static void VerifyConnection(string url)
{
Console.WriteLine($"VerifyConnection begins: url: {url}");
var process = new Process();
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = @$"/C curl ""{url}""",
RedirectStandardOutput = true, // Redirect the standard output
UseShellExecute = false,
CreateNoWindow = true
};
process.StartInfo = startInfo;
process.Start();
var debug = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine($"VerifyConnection ends: exitcode: {process.ExitCode}, curl result: {debug}");
}
private string NormalizeCurrencyText(string realValue, int fractionDigits)
{
if (!realValue.Contains('.')) return realValue;