Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,33 @@ namespace TestCentric.Gui.Dialogs
internal class SettingsDialogBaseTests
{
[Test]
public void ApplySettings_IsAppliedToProject()
public void ApplySettings_SubPackageChanges_AreAppliedToProject()
{
// 1. Arrange
ITestModel model = Substitute.For<ITestModel>();
TestCentricProject project = new TestCentricProject(model);
model.TestCentricProject.Returns(project);

SettingsDialogBase settingsDialog = new SettingsDialogBase(null, model);
settingsDialog.PackageSettingChanges.Add(SettingDefinitions.DebugTests.Name, true);
settingsDialog.SubPackageSettingChanges.Add(SettingDefinitions.DebugTests.WithValue(true));

// 2. Act
settingsDialog.ApplySettings();

// 3. Assert
Assert.That(project.Settings.HasSetting(SettingDefinitions.DebugTests.Name), Is.True);
}

[Test]
public void ApplySettings_TopLevelPackageChanges_AreAppliedToProject()
{
// 1. Arrange
ITestModel model = Substitute.For<ITestModel>();
TestCentricProject project = new TestCentricProject(model);
model.TestCentricProject.Returns(project);

SettingsDialogBase settingsDialog = new SettingsDialogBase(null, model);
settingsDialog.TopLevelPackageSettingChanges.Add(SettingDefinitions.DebugTests.WithValue(true));

// 2. Act
settingsDialog.ApplySettings();
Expand All @@ -41,7 +59,8 @@ public void ApplySettings_ProjectIsNull_SettingIsNotApplied()
model.TestCentricProject.Returns((TestCentricProject)null);

SettingsDialogBase settingsDialog = new SettingsDialogBase(null, model);
settingsDialog.PackageSettingChanges.Add(SettingDefinitions.DebugTests.Name, true);
settingsDialog.TopLevelPackageSettingChanges.Add(SettingDefinitions.DebugTests.WithValue(true));
settingsDialog.SubPackageSettingChanges.Add(SettingDefinitions.DebugTests.WithValue(true));

// 2. Act
settingsDialog.ApplySettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void UpdateMenuItems_SpecificAgentIsSelected_ChecksAgentMenuItem()
"NUnit.TestAdapter.Agent2"
});

project.AddSetting(SettingDefinitions.SelectedAgentName.WithValue("NUnit.TestAdapter.Agent2"));
project.SetSubPackageSetting(SettingDefinitions.SelectedAgentName.WithValue("NUnit.TestAdapter.Agent2"));

_model.AvailableAgents.Returns(new List<string>
{
Expand Down Expand Up @@ -479,8 +479,8 @@ public void ClickingDefaultMenuItem_RemovesAgentSettings()
// 1. Arrange
var project = new TestCentricProject(_model);
_model.TestCentricProject.Returns(project);
project.AddSetting(SettingDefinitions.SelectedAgentName.WithValue("SomeAgent"));
project.AddSetting(SettingDefinitions.RequestedAgentName.WithValue("SomeAgent"));
project.SetSubPackageSetting(SettingDefinitions.SelectedAgentName.WithValue("SomeAgent"));
project.SetSubPackageSetting(SettingDefinitions.RequestedAgentName.WithValue("SomeAgent"));

_model.GetAgentsForPackage(project).Returns(new List<string>
{
Expand Down
22 changes: 14 additions & 8 deletions src/GuiRunner/TestCentric.Gui/Dialogs/SettingsDialogBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TestCentric.Gui.Dialogs
using System;
using Model;
using Model.Settings;
using NUnit.Engine;
using Presenters;

/// <summary>
Expand Down Expand Up @@ -43,14 +44,16 @@ public SettingsDialogBase(TestCentricPresenter presenter, ITestModel model) : th
Presenter = presenter;
Model = model;
Settings = model.Settings;
PackageSettingChanges = new Dictionary<string, object>();
SubPackageSettingChanges = new List<PackageSetting>();
TopLevelPackageSettingChanges = new List<PackageSetting>();
}

protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);

PackageSettingChanges.Clear();
SubPackageSettingChanges.Clear();
TopLevelPackageSettingChanges.Clear();
}

public SettingsDialogBase()
Expand Down Expand Up @@ -143,7 +146,9 @@ private void InitializeComponent()

public IUserSettings Settings { get; }

public IDictionary<string, object> PackageSettingChanges { get; }
public IList<PackageSetting> SubPackageSettingChanges { get; }

public IList<PackageSetting> TopLevelPackageSettingChanges { get; }

public SettingsPageCollection SettingsPages
{
Expand All @@ -159,10 +164,11 @@ public void ApplySettings()
if (page.SettingsLoaded)
page.ApplySettings();

foreach(var entry in PackageSettingChanges)
{
Model.TestCentricProject?.AddSetting(entry.Key, entry.Value);
}
foreach(PackageSetting setting in SubPackageSettingChanges)
Model.TestCentricProject?.SetSubPackageSetting(setting);

foreach (PackageSetting setting in TopLevelPackageSettingChanges)
Model.TestCentricProject?.SetTopLevelSetting(setting);
}
#endregion

Expand All @@ -180,7 +186,7 @@ private void okButton_Click(object sender, System.EventArgs e)

// NOTE: Currently, all changes require reload. If this changes
// we will need to add some filtering here.
if (Model.IsProjectLoaded && PackageSettingChanges.Count > 0)
if (Model.IsProjectLoaded && (SubPackageSettingChanges.Count > 0 || TopLevelPackageSettingChanges.Count > 0))
{
if (MessageDisplay.YesNo("Some changes will only take effect when you reload the test project. Do you want to reload now?"))
_reloadProjectOnClose = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ private void OnAgentMenuItemClicked(object sender, EventArgs e)
string itemTag = item.Tag as string;
if (itemTag is not null && itemTag != "DEFAULT")
{
_model.TestCentricProject.AddSetting(SettingDefinitions.SelectedAgentName.WithValue(itemTag));
_model.TestCentricProject.AddSetting(SettingDefinitions.RequestedAgentName.WithValue(itemTag));
_model.TestCentricProject.SetSubPackageSetting(SettingDefinitions.SelectedAgentName.WithValue(itemTag));
_model.TestCentricProject.SetSubPackageSetting(SettingDefinitions.RequestedAgentName.WithValue(itemTag));
}

// Even though the _model has a Reload method, we cannot use it because Reload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,19 @@ public override void ApplySettings()
int numAgents = numberOfAgentsCheckBox.Checked
? (int)numberOfAgentsUpDown.Value : 0;
if (numAgents != Settings.Engine.Agents)
PackageSettingChanges[SettingDefinitions.MaxAgents.Name] = numAgents;
TopLevelPackageSettingChanges.Add(SettingDefinitions.MaxAgents.WithValue(numAgents));
Settings.Engine.Agents = numAgents;

bool shadowCopyFiles = !disableShadowCopyCheckBox.Checked;
if (shadowCopyFiles != Settings.Engine.ShadowCopyFiles)
PackageSettingChanges[SettingDefinitions.ShadowCopyFiles.Name] = shadowCopyFiles;
SubPackageSettingChanges.Add(SettingDefinitions.ShadowCopyFiles.WithValue(shadowCopyFiles));
Settings.Engine.ShadowCopyFiles = shadowCopyFiles;

string principalPolicy = principalPolicyCheckBox.Checked
? (string)principalPolicyListBox.SelectedItem
: nameof(PrincipalPolicy.UnauthenticatedPrincipal);
if (principalPolicy != Settings.Engine.PrincipalPolicy)
PackageSettingChanges[SettingDefinitions.PrincipalPolicy.Name] = principalPolicy;
SubPackageSettingChanges.Add(SettingDefinitions.PrincipalPolicy.WithValue(principalPolicy));
Settings.Engine.PrincipalPolicy = principalPolicy;

Settings.Engine.SetPrincipalPolicy = principalPolicyCheckBox.Checked;
Expand Down
7 changes: 5 additions & 2 deletions src/GuiRunner/TestCentric.Gui/SettingsPages/SettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TestCentric.Gui
using Dialogs;
using Model;
using Model.Settings;
using NUnit.Engine;

/// <summary>
/// SettingsPage is the base class for all pages used
Expand Down Expand Up @@ -89,7 +90,8 @@ public IMessageDisplay MessageDisplay
protected ITestModel Model { get; private set; }
protected IUserSettings Settings { get; private set; }

protected IDictionary<string, object> PackageSettingChanges { get; private set; }
protected IList<PackageSetting> SubPackageSettingChanges { get; private set; }
protected IList<PackageSetting> TopLevelPackageSettingChanges { get; private set; }

#endregion

Expand Down Expand Up @@ -134,7 +136,8 @@ protected override void OnLoad(EventArgs e)

Model = dlg.Model;
Settings = dlg.Settings;
PackageSettingChanges = dlg.PackageSettingChanges;
SubPackageSettingChanges = dlg.SubPackageSettingChanges;
TopLevelPackageSettingChanges = dlg.TopLevelPackageSettingChanges;

LoadSettings();
}
Expand Down
25 changes: 15 additions & 10 deletions src/GuiRunner/TestModel.Tests/CreateNewProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace TestCentric.Gui.Model
{
using NUnit.Engine;

public class CreateNewProjectTests
{
private TestModel _model;
Expand Down Expand Up @@ -41,17 +43,21 @@ public void PackageContainsOneSubPackagePerTestFile(params string[] testFiles)
Assert.That(_model.TestCentricProject.TestFiles, Is.EqualTo(testFiles));
}

// TODO: Remove? Use and test fluent methods?
[TestCase(nameof(SettingDefinitions.RequestedRuntimeFramework), "net-2.0")]
[TestCase(nameof(SettingDefinitions.MaxAgents), 8)]
[TestCase(nameof(SettingDefinitions.ShadowCopyFiles), false)]
public void PackageReflectsPackageSettings(string key, object value)
private static TestCaseData[] PackageSettingTestCases = new TestCaseData[]
{
new TestCaseData(SettingDefinitions.RequestedFrameworkName.WithValue("net-2.0")),
new TestCaseData(SettingDefinitions.MaxAgents.WithValue(8)),
new TestCaseData(SettingDefinitions.ShadowCopyFiles.WithValue(false)),
};

[TestCaseSource(nameof(PackageSettingTestCases))]
public void PackageReflectsPackageSettings(PackageSetting setting)
{
var package = _model.CreateNewProject(new[] { "my.dll" });
package.AddSetting(key, value);
package.SetTopLevelSetting(setting);

Assert.That(package.Settings.HasSetting(key));
Assert.That(package.Settings.GetSetting(key), Is.EqualTo(value));
Assert.That(package.Settings.HasSetting(setting.Name));
Assert.That(package.Settings.GetSetting(setting.Name), Is.EqualTo(setting.Value));
}

// TODO: Remove? Use and test fluent methods?
Expand All @@ -64,8 +70,7 @@ public void PackageReflectsTestParameters()
{ "parm2", "value2" }
};
var package = _model.CreateNewProject(new[] { "my.dll" });
package.AddSetting("TestParametersDictionary", testParms);

package.SetTopLevelSetting(SettingDefinitions.TestParametersDictionary.WithValue(testParms));
Assert.That(package.Settings.HasSetting("TestParametersDictionary"));
var parms = package.Settings.GetSetting("TestParametersDictionary") as IDictionary<string, string>;
Assert.That(parms, Is.Not.Null);
Expand Down
87 changes: 77 additions & 10 deletions src/GuiRunner/TestModel.Tests/TestCentricProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,52 @@ public void IsDirty_NewProject_IsFalse()
}

[Test]
public void IsDirty_AfterAddSetting_IsTrue()
public void IsDirty_AfterSetTopLevelSetting_IsTrue()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);

// 2. Act
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));

// 3. Assert
Assert.That(project.IsDirty, Is.True);
}

[Test]
public void IsDirty_AfterRemoveSetting_IsTrue()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);

// 2. Act
project.RemoveSetting(SettingDefinitions.DebugTests.Name);

// 3. Assert
Assert.That(project.IsDirty, Is.True);
}

[Test]
public void IsDirty_AfterSetSubPackageSetting_IsTrue()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);

// 2. Act
project.SetSubPackageSetting(SettingDefinitions.DebugTests.WithValue(true));

// 3. Assert
Assert.That(project.IsDirty, Is.True);
}

[Test]
public void IsDirty_AfterAddPackageSetting_IsTrue()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);

// 2. Act
project.SetSubPackageSetting(SettingDefinitions.DebugTests.WithValue(true));

// 3. Assert
Assert.That(project.IsDirty, Is.True);
Expand Down Expand Up @@ -177,7 +216,7 @@ public void IsDirty_AfterSave_IsFalse()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));
Assert.That(project.IsDirty, Is.True);

// 2. Act
Expand All @@ -192,10 +231,10 @@ public void IsDirty_AfterLoad_IsFalse()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));
project.SaveAs("TestCentricTestProject.tcproj");

project.AddSetting(SettingDefinitions.MaxAgents.Name, 5);
project.SetTopLevelSetting(SettingDefinitions.MaxAgents.WithValue(5));
Assert.That(project.IsDirty, Is.True);

// 2. Act
Expand Down Expand Up @@ -223,6 +262,34 @@ public void AddSetting_AddsSettingToProject()
Assert.That(project.Settings.GetSetting(SettingDefinitions.DebugTests.Name), Is.EqualTo(true));
}

[Test]
public void SetTopLevelSetting_Setting_IsSetInProject()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);

// 2. Act
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));

// 3. Assert
Assert.That(project.Settings.HasSetting(SettingDefinitions.DebugTests.Name), Is.True);
Assert.That(project.Settings.GetSetting(SettingDefinitions.DebugTests.Name), Is.EqualTo(true));
}

[Test]
public void SetSubPackageSetting_Setting_IsSetInProject()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);

// 2. Act
project.SetSubPackageSetting(SettingDefinitions.DebugTests.WithValue(true));

// 3. Assert
Assert.That(project.Settings.HasSetting(SettingDefinitions.DebugTests.Name), Is.True);
Assert.That(project.Settings.GetSetting(SettingDefinitions.DebugTests.Name), Is.EqualTo(true));
}

[Test]
public void AddSetting_WithVariousTypes_StoresCorrectly()
{
Expand All @@ -245,7 +312,7 @@ public void RemoveSetting_ByName_RemovesSettingFromProject()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));
Assert.That(project.Settings.HasSetting(SettingDefinitions.DebugTests.Name), Is.True);

// 2. Act
Expand All @@ -260,7 +327,7 @@ public void RemoveSetting_ByDefinition_RemovesSettingFromProject()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));
Assert.That(project.Settings.HasSetting(SettingDefinitions.DebugTests.Name), Is.True);

// 2. Act
Expand Down Expand Up @@ -350,7 +417,7 @@ public void SaveAs_CreatesFileWithProjectPath()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));

// 2. Act
project.SaveAs("TestCentricTestProject.tcproj");
Expand All @@ -368,7 +435,7 @@ public void Save_UpdatesExistingFile()
project.SaveAs("TestCentricTestProject.tcproj");

// 2. Act
project.AddSetting(SettingDefinitions.MaxAgents.Name, 5);
project.SetTopLevelSetting(SettingDefinitions.MaxAgents.WithValue(5));
project.Save();

// 3. Assert
Expand All @@ -381,7 +448,7 @@ public void Load_SavedProject_SettingsAreRestored()
{
// 1. Arrange
TestCentricProject project = new TestCentricProject(_model);
project.AddSetting(SettingDefinitions.DebugTests.Name, true);
project.SetTopLevelSetting(SettingDefinitions.DebugTests.WithValue(true));
project.SaveAs("TestCentricTestProject.tcproj");

// 2. Act
Expand Down
Loading