From 38ab1ae79467a40f218b94fe54234b6bb03cd856 Mon Sep 17 00:00:00 2001 From: jbe2277 Date: Tue, 24 Sep 2024 21:22:15 +0200 Subject: [PATCH] UITest/InfoMan: reset container file --- .../Tests/AddressBookTest.cs | 22 ++++++++++--------- .../InformationManager.Test/UITest.cs | 10 ++++++++- .../Views/ContactListView.cs | 5 +++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs b/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs index 3316a90b..7052237e 100644 --- a/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs +++ b/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs @@ -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().FirstnameLabel.Text, contactListView.ContactItems[0].FirstnameLabel.Text); AssertContactItem(contactListView.ContactItems[0], contactView, "Jesper", "Aaberg", "jesper.aaberg@example.com", "(111) 555-0100"); AssertContactItem(contactListView.ContactItems[^1], null, "Miles", "Reid", "miles.reid@adventure-works.com", "(444) 555-0123"); @@ -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)); } } } diff --git a/src/Samples.UITest/InformationManager.Test/UITest.cs b/src/Samples.UITest/InformationManager.Test/UITest.cs index ce3d5b4e..229d27fb 100644 --- a/src/Samples.UITest/InformationManager.Test/UITest.cs +++ b/src/Samples.UITest/InformationManager.Test/UITest.cs @@ -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) @@ -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); diff --git a/src/Samples.UITest/InformationManager.Test/Views/ContactListView.cs b/src/Samples.UITest/InformationManager.Test/Views/ContactListView.cs index 90b5eabb..c4bfaeea 100644 --- a/src/Samples.UITest/InformationManager.Test/Views/ContactListView.cs +++ b/src/Samples.UITest/InformationManager.Test/Views/ContactListView.cs @@ -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); + } } \ No newline at end of file