the inheritance button will now be shown on items whose parent is the root node

This commit is contained in:
David Sparer
2019-05-10 15:41:43 -05:00
parent fb68d0bff3
commit af24e3b284
7 changed files with 72 additions and 76 deletions

View File

@@ -1,77 +1,91 @@
using mRemoteNG.Connection;
using mRemoteNG.Container;
using NUnit.Framework;
using System.Collections;
using System.Collections;
using System.Linq;
using System.Reflection;
using mRemoteNG.Connection;
using mRemoteNG.Container;
using mRemoteNG.Tree.Root;
using NUnit.Framework;
namespace mRemoteNGTests.Connection
{
[TestFixture]
[TestFixture]
public class ConnectionInfoInheritanceTests
{
private ConnectionInfo _connectionInfo;
private ConnectionInfoInheritance _inheritance;
private PropertyInfo[] _inheritanceProperties = typeof(ConnectionInfoInheritance).GetProperties();
private readonly PropertyInfo[] _inheritanceProperties = typeof(ConnectionInfoInheritance).GetProperties();
[SetUp]
public void Setup()
{
_connectionInfo = new ConnectionInfo();
_inheritance = new ConnectionInfoInheritance(_connectionInfo);
}
[TearDown]
public void Teardown()
{
_connectionInfo = null;
_inheritance = null;
}
[Test]
[Test]
public void TurnOffInheritanceCompletely()
{
_inheritance.Username = true;
_inheritance.TurnOffInheritanceCompletely();
Assert.That(AllInheritancePropertiesAreFalse(), Is.True);
var inheritance = new ConnectionInfoInheritance(new ConnectionInfo()) {Username = true};
inheritance.TurnOffInheritanceCompletely();
Assert.That(AllInheritancePropertiesAreFalse(inheritance), Is.True);
}
[Test]
public void TurnOnInheritanceCompletely()
{
_inheritance.TurnOnInheritanceCompletely();
Assert.That(AllInheritancePropertiesAreTrue(), Is.True);
var inheritance = new ConnectionInfoInheritance(new ConnectionInfo());
inheritance.TurnOnInheritanceCompletely();
Assert.That(AllInheritancePropertiesAreTrue(inheritance), Is.True);
}
[Test]
public void DisableInheritanceTurnsOffAllInheritance()
public void InheritanceIsDisabledWhenAttachedToARootNode()
{
_inheritance.Username = true;
_inheritance.DisableInheritance();
Assert.That(AllInheritancePropertiesAreFalse(), Is.True);
var inheritance = new ConnectionInfoInheritance(new RootNodeInfo(RootNodeType.Connection));
Assert.That(inheritance.InheritanceActive, Is.False);
}
[Test]
public void EnableInheritanceRestoresPreviousInheritanceValues()
public void InheritanceIsDisabledWhenAttachedToAPuttyRootNode()
{
_inheritance.Username = true;
_inheritance.DisableInheritance();
_inheritance.EnableInheritance();
Assert.That(_inheritance.Username, Is.True);
var inheritance = new ConnectionInfoInheritance(new RootNodeInfo(RootNodeType.PuttySessions));
Assert.That(inheritance.InheritanceActive, Is.False);
}
[Test]
public void InheritanceIsDisabledWhenAttachedToAPuttyNode()
{
var inheritance = new ConnectionInfoInheritance(new RootPuttySessionsNodeInfo());
Assert.That(inheritance.InheritanceActive, Is.False);
}
[Test]
public void InheritanceIsDisabledWhenAttachedToANodeDirectlyUnderTheRootNode()
{
var con = new ConnectionInfo();
new RootNodeInfo(RootNodeType.Connection).AddChild(con);
Assert.That(con.Inheritance.InheritanceActive, Is.False);
}
[Test]
public void InheritanceIsEnabledWhenAttachedToNormalConnectionInfo()
{
var inheritance = new ConnectionInfoInheritance(new ConnectionInfo());
Assert.That(inheritance.InheritanceActive, Is.True);
}
[Test]
public void InheritanceIsEnabledWhenAttachedToNormalContainerInfo()
{
var inheritance = new ConnectionInfoInheritance(new ContainerInfo());
Assert.That(inheritance.InheritanceActive, Is.True);
}
[Test]
public void GetPropertiesReturnsListOfSettableProperties()
{
var hasIconProperty = _inheritance.GetProperties().Contains(typeof(ConnectionInfoInheritance).GetProperty("Icon"));
var inheritance = new ConnectionInfoInheritance(new ConnectionInfo());
var hasIconProperty = inheritance.GetProperties().Contains(typeof(ConnectionInfoInheritance).GetProperty("Icon"));
Assert.That(hasIconProperty, Is.True);
}
[Test]
public void GetPropertiesExludesPropertiesThatShouldNotBeSet()
{
var hasEverythingInheritedProperty = _inheritance.GetProperties().Contains(typeof(ConnectionInfoInheritance).GetProperty("EverythingInherited"));
var inheritance = new ConnectionInfoInheritance(new ConnectionInfo());
var hasEverythingInheritedProperty = inheritance.GetProperties().Contains(typeof(ConnectionInfoInheritance).GetProperty("EverythingInherited"));
Assert.That(hasEverythingInheritedProperty, Is.False);
}
@@ -91,23 +105,25 @@ namespace mRemoteNGTests.Connection
Assert.That(con1.AutomaticResize, Is.EqualTo(expectedSetting));
}
private bool AllInheritancePropertiesAreTrue()
private bool AllInheritancePropertiesAreTrue(ConnectionInfoInheritance inheritance)
{
var allPropertiesTrue = true;
foreach (var property in _inheritanceProperties)
{
if (PropertyIsBoolean(property) && PropertyIsChangedWhenSettingInheritAll(property) && BooleanPropertyIsSetToFalse(property))
if (PropertyIsBoolean(property) && PropertyIsChangedWhenSettingInheritAll(property) &&
BooleanPropertyIsSetToFalse(property, inheritance))
allPropertiesTrue = false;
}
return allPropertiesTrue;
}
private bool AllInheritancePropertiesAreFalse()
private bool AllInheritancePropertiesAreFalse(ConnectionInfoInheritance inheritance)
{
var allPropertiesFalse = true;
foreach (var property in _inheritanceProperties)
{
if (PropertyIsBoolean(property) && PropertyIsChangedWhenSettingInheritAll(property) && BooleanPropertyIsSetToTrue(property))
if (PropertyIsBoolean(property) && PropertyIsChangedWhenSettingInheritAll(property) &&
BooleanPropertyIsSetToTrue(property, inheritance))
allPropertiesFalse = false;
}
return allPropertiesFalse;
@@ -124,14 +140,14 @@ namespace mRemoteNGTests.Connection
return (property.PropertyType.Name == typeof(bool).Name);
}
private bool BooleanPropertyIsSetToFalse(PropertyInfo property)
private bool BooleanPropertyIsSetToFalse(PropertyInfo property, ConnectionInfoInheritance inheritance)
{
return (bool)property.GetValue(_inheritance) == false;
return (bool)property.GetValue(inheritance) == false;
}
private bool BooleanPropertyIsSetToTrue(PropertyInfo property)
private bool BooleanPropertyIsSetToTrue(PropertyInfo property, ConnectionInfoInheritance inheritance)
{
return (bool)property.GetValue(_inheritance);
return (bool)property.GetValue(inheritance);
}
}
}

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.13.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.13.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -344,6 +345,7 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.13.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.13.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -13,6 +13,7 @@
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net46" />
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.5" targetFramework="net46" />
<package id="NUnit.Extension.VSProjectLoader" version="3.8.0" targetFramework="net46" />
<package id="NUnit3TestAdapter" version="3.13.0" targetFramework="net46" />
<package id="ObjectListView.Official" version="2.9.1" targetFramework="net46" />
<package id="OpenCover" version="4.6.519" targetFramework="net46" />
<package id="ReportGenerator" version="3.0.2" targetFramework="net46" />

View File

@@ -3,6 +3,7 @@ using System.ComponentModel;
using System.Linq;
using System.Reflection;
using mRemoteNG.Tools;
using mRemoteNG.Tree.Root;
namespace mRemoteNG.Connection
{
@@ -398,7 +399,7 @@ namespace mRemoteNG.Connection
/// settings for individual properties.
/// </summary>
[Browsable(false)]
public bool InheritanceActive { get; set; } = true;
public bool InheritanceActive => !(Parent is RootNodeInfo || Parent.Parent is RootNodeInfo);
#endregion
@@ -418,16 +419,6 @@ namespace mRemoteNG.Connection
return newInheritance;
}
public void EnableInheritance()
{
InheritanceActive = true;
}
public void DisableInheritance()
{
InheritanceActive = false;
}
public void TurnOnInheritanceCompletely()
{
SetAllValues(true);

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using mRemoteNG.Connection;
using mRemoteNG.Container;
@@ -67,17 +67,5 @@ namespace mRemoteNG.Tree.Root
}
#endregion
public override void AddChildAt(ConnectionInfo newChildItem, int index)
{
newChildItem.Inheritance.DisableInheritance();
base.AddChildAt(newChildItem, index);
}
public override void RemoveChild(ConnectionInfo removalTarget)
{
removalTarget.Inheritance.EnableInheritance();
base.RemoveChild(removalTarget);
}
}
}

View File

@@ -138,8 +138,8 @@ namespace mRemoteNG.UI.Controls
_cMenTreeSep4,
_cMenTreeAddConnection,
_cMenTreeAddFolder,
_cMenTreeApplyInheritanceToChildren,
_cMenTreeApplyDefaultInheritance,
_cMenTreeApplyInheritanceToChildren,
_toolStripSeparator1,
_cMenTreeToolsSort,
_cMenTreeMoveUp,

View File

@@ -207,10 +207,8 @@ namespace mRemoteNG.UI.Window
public bool CanShowProperties => SelectedTreeNode != null;
public bool InheritanceVisible => _btnShowInheritance.Checked;
public bool CanShowInheritance => !_pGrid.RootNodeSelected &&
SelectedTreeNode != null &&
_pGrid.SelectedConnectionInfo?.Parent != null &&
!(_pGrid.SelectedConnectionInfo.Parent is RootNodeInfo);
public bool CanShowInheritance => SelectedTreeNode != null &&
_pGrid.SelectedConnectionInfo?.Parent != null;
public bool DefaultPropertiesVisible => _btnShowDefaultProperties.Checked;
public bool CanShowDefaultProperties => true;