Skip to content

Commit

Permalink
enable internet server for development
Browse files Browse the repository at this point in the history
  • Loading branch information
tian-lt committed Nov 25, 2024
1 parent 6370f28 commit b159a89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/Calculator/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="internetClientServer"/>
</Capabilities>
</Package>
10 changes: 9 additions & 1 deletion src/CalculatorUITestFramework/MockedCurrencyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ private void DisposeImpl()
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))
Expand Down
24 changes: 0 additions & 24 deletions src/CalculatorUITests/CurrencyConverterFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
_currencyServer = new MockedCurrencyServer();
Thread.Sleep(5000);
CalculatorDriver.Instance.SetupCalculatorSession(context);
}

Expand All @@ -47,10 +46,7 @@ public static void ClassCleanup()
[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();
Expand All @@ -62,26 +58,6 @@ public void TestCleanup()
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;
Expand Down

0 comments on commit b159a89

Please sign in to comment.