Skip to content

Commit

Permalink
UITest/InfoMan: reset container file
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Sep 24, 2024
1 parent 1943ed8 commit 38ab1ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public void ShowContactsTest() => Run(() =>

var contactListView = window.ContactLayoutView.ContactListView;
var contactView = window.ContactLayoutView.ContactView;
Assert.Equal(5, contactListView.ContactItems.Count);
var count = contactListView.ContactItems.Count;
Assert.Equal(5, count);
Log.WriteLine($"List of Contacts ({count})");
for (int i = 0; i < count; i++)
{
var (f, l, e, p) = contactListView.ContactItems[i];
Log.WriteLine($"{i:00}: {f} {l}; {e} {p}");
}

Assert.Equal(contactListView.ContactList.SelectedItem.As<ContactListItem>().FirstnameLabel.Text, contactListView.ContactItems[0].FirstnameLabel.Text);
AssertContactItem(contactListView.ContactItems[0], contactView, "Jesper", "Aaberg", "[email protected]", "(111) 555-0100");
AssertContactItem(contactListView.ContactItems[^1], null, "Miles", "Reid", "[email protected]", "(444) 555-0123");
Expand All @@ -36,17 +44,11 @@ public void ShowContactsTest() => Run(() =>

private static void AssertContactItem(ContactListItem contactItem, ContactView? contactView, string firstName, string lastName, string email, string phone)
{
Assert.Equal(firstName, contactItem.FirstnameLabel.Text);
Assert.Equal(lastName, contactItem.LastnameLabel.Text);
Assert.Equal(email, contactItem.EmailLabel.Text);
Assert.Equal(phone, contactItem.PhoneLabel.Text);

var (f, l, e, p) = contactItem;
Assert.Equal((firstName, lastName, email, phone), (f, l, e, p));
if (contactView is not null)
{
Assert.Equal(firstName, contactView.FirstnameBox.Text);
Assert.Equal(lastName, contactView.LastnameBox.Text);
Assert.Equal(email, contactView.EmailBox.Text);
Assert.Equal(phone, contactView.PhoneBox.Text);
Assert.Equal((f, l, e, p), (contactView.FirstnameBox.Text, contactView.LastnameBox.Text, contactView.EmailBox.Text, contactView.PhoneBox.Text));
}
}
}
10 changes: 9 additions & 1 deletion src/Samples.UITest/InformationManager.Test/UITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class UITest(ITestOutputHelper log) : UITestBase(log, "Informati
Environment.GetEnvironmentVariable("UITestExePath") ?? "out/InformationManager/Release/net8.0-windows/",
Environment.GetEnvironmentVariable("UITestOutputPath") ?? "out/Samples.UITest/InformationManager/")
{
public Application Launch(LaunchArguments? arguments = null, bool resetSettings = true)
public Application Launch(LaunchArguments? arguments = null, bool resetSettings = true, bool resetContainer = true)
{
Log.WriteLine("");
if (resetSettings)
Expand All @@ -23,6 +23,14 @@ public Application Launch(LaunchArguments? arguments = null, bool resetSettings
if (File.Exists(settingsFile)) File.Delete(settingsFile);
Log.WriteLine($"Delete settings: {settingsFile}");
}
if (resetContainer)
{
var companyName = FileVersionInfo.GetVersionInfo(Executable).CompanyName ?? throw new InvalidOperationException("Could not read the CompanyName from the exe.");
var productName = FileVersionInfo.GetVersionInfo(Executable).ProductName ?? throw new InvalidOperationException("Could not read the ProductName from the exe.");
var containerFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), companyName, productName, "InformationManager.datx");
if (File.Exists(containerFile)) File.Delete(containerFile);
Log.WriteLine($"Delete file: {containerFile}");
}
var args = (arguments ?? new LaunchArguments()).ToArguments();
Log.WriteLine($"Launch: {args}");
return App = Application.Launch(Executable, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class ContactListItem(FrameworkAutomationElementBase element) : ListBoxIt
public Label EmailLabel => this.Find("EmailLabel").AsLabel();

public Label PhoneLabel => this.Find("PhoneLabel").AsLabel();

public void Deconstruct(out string firstname, out string lastname, out string email, out string phone)
{
(firstname, lastname, email, phone) = (FirstnameLabel.Text, LastnameLabel.Text, EmailLabel.Text, PhoneLabel.Text);
}
}

0 comments on commit 38ab1ae

Please sign in to comment.