finished updating some tests for default inheritance

This commit is contained in:
David Sparer
2018-04-06 15:02:14 -05:00
parent 924f1f1e48
commit a37b5deaa1
6 changed files with 55 additions and 50 deletions

View File

@@ -26,19 +26,6 @@ namespace mRemoteNGTests.Connection
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
}
//TODO - finish test
//[TestCaseSource(nameof(GetInheritanceProperties))]
public void LoadingDefaultInfoUpdatesAllInheritanceProperties(PropertyInfo property)
{
DefaultConnectionInfo.Instance.Inheritance.TurnOffInheritanceCompletely();
_randomizedConnectionInfo.Inheritance.TurnOnInheritanceCompletely();
DefaultConnectionInfo.Instance.LoadFrom(_randomizedConnectionInfo);
var valueInDestination = property.GetValue(DefaultConnectionInfo.Instance.Inheritance);
var valueInSource = property.GetValue(_randomizedConnectionInfo.Inheritance);
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
}
[TestCaseSource(nameof(GetConnectionInfoProperties))]
public void SavingDefaultConnectionInfoExportsAllProperties(PropertyInfo property)
{
@@ -67,14 +54,9 @@ namespace mRemoteNGTests.Connection
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
}
private static IEnumerable<PropertyInfo> GetConnectionInfoProperties()
private static IEnumerable<PropertyInfo> GetConnectionInfoProperties()
{
return new ConnectionInfo().GetSerializableProperties();
}
private static IEnumerable<PropertyInfo> GetInheritanceProperties()
{
return new ConnectionInfoInheritance(new object(), true).GetProperties();
}
}
}

View File

@@ -1,34 +1,40 @@
using mRemoteNG.Connection;
using System.Collections.Generic;
using System.Reflection;
using mRemoteNG.Connection;
using NUnit.Framework;
namespace mRemoteNGTests.Connection
{
public class DefaultConnectionInheritanceTests
public class DefaultConnectionInheritanceTests
{
[SetUp]
public void Setup()
[TestCaseSource(nameof(GetInheritanceProperties))]
public void LoadingDefaultInheritanceUpdatesAllProperties(PropertyInfo property)
{
DefaultConnectionInheritance.Instance.TurnOffInheritanceCompletely();
}
[Test]
public void LoadingDefaultInheritanceUpdatesAllProperties()
{
var inheritanceSource = new ConnectionInfoInheritance(new object(), true);
var inheritanceSource = new ConnectionInfoInheritance(new object(), true);
inheritanceSource.TurnOnInheritanceCompletely();
DefaultConnectionInheritance.Instance.LoadFrom(inheritanceSource);
Assert.That(DefaultConnectionInheritance.Instance.EverythingInherited, Is.True);
}
DefaultConnectionInheritance.Instance.TurnOffInheritanceCompletely();
[Test]
public void SavingDefaultInheritanceExportsAllProperties()
DefaultConnectionInheritance.Instance.LoadFrom(inheritanceSource);
var valueInDestination = property.GetValue(DefaultConnectionInheritance.Instance);
var valueInSource = property.GetValue(inheritanceSource);
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
}
[TestCaseSource(nameof(GetInheritanceProperties))]
public void SavingDefaultInheritanceExportsAllProperties(PropertyInfo property)
{
var inheritanceDestination = new ConnectionInfoInheritance(new object(), true);
DefaultConnectionInheritance.Instance.AutomaticResize = true;
DefaultConnectionInheritance.Instance.SaveTo(inheritanceDestination);
Assert.That(inheritanceDestination.AutomaticResize, Is.True);
}
var saveTarget = new ConnectionInfoInheritance(new object(), true);
saveTarget.TurnOffInheritanceCompletely();
DefaultConnectionInheritance.Instance.TurnOnInheritanceCompletely();
DefaultConnectionInheritance.Instance.SaveTo(saveTarget);
var valueInDestination = property.GetValue(saveTarget);
var valueInSource = property.GetValue(DefaultConnectionInheritance.Instance);
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
}
[Test]
public void NewInheritanceInstancesCreatedWithDefaultInheritanceValues()
@@ -38,12 +44,20 @@ namespace mRemoteNGTests.Connection
Assert.That(inheritanceInstance.Domain, Is.True);
}
[Test]
public void NewInheritanceInstancesCreatedWithAllDefaultInheritanceValues()
[TestCaseSource(nameof(GetInheritanceProperties))]
public void NewInheritanceInstancesCreatedWithAllDefaultInheritanceValues(PropertyInfo property)
{
DefaultConnectionInheritance.Instance.TurnOnInheritanceCompletely();
var inheritanceInstance = new ConnectionInfoInheritance(new object());
Assert.That(inheritanceInstance.EverythingInherited, Is.True);
}
}
var valueInDestination = property.GetValue(inheritanceInstance);
var valueInSource = property.GetValue(DefaultConnectionInheritance.Instance);
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
}
private static IEnumerable<PropertyInfo> GetInheritanceProperties()
{
return new ConnectionInfoInheritance(new object(), true).GetProperties();
}
}
}

View File

@@ -8,7 +8,7 @@ using NUnit.Framework;
namespace mRemoteNGTests.Tree
{
public class NodeSearcherTests
public class NodeSearcherTests
{
private NodeSearcher _nodeSearcher;
private ContainerInfo _folder1;
@@ -104,6 +104,14 @@ namespace mRemoteNGTests.Tree
_con4 = new ConnectionInfo { Name = "con4", Description="description6", Hostname="hostname6" };
_con5 = new ConnectionInfo { Name = "con5", Description="description7", Hostname="hostname7" };
_folder1.Inheritance.TurnOffInheritanceCompletely();
_con1.Inheritance.TurnOffInheritanceCompletely();
_con2.Inheritance.TurnOffInheritanceCompletely();
_folder2.Inheritance.TurnOffInheritanceCompletely();
_con3.Inheritance.TurnOffInheritanceCompletely();
_con4.Inheritance.TurnOffInheritanceCompletely();
_con5.Inheritance.TurnOffInheritanceCompletely();
connectionTreeModel.AddRootNode(root);
root.AddChildRange(new [] { _folder1, _folder2, _con5 });
_folder1.AddChildRange(new [] { _con1, _con2 });

View File

@@ -12,6 +12,7 @@ namespace mRemoteNG.Connection
private DefaultConnectionInfo()
{
IsDefault = true;
Inheritance = DefaultConnectionInheritance.Instance;
}
public void LoadFrom<TSource>(TSource sourceInstance, Func<string, string> propertyNameMutator = null)

View File

@@ -8,7 +8,7 @@ using mRemoteNG.Tree.Root;
namespace mRemoteNG.Tree
{
public sealed class ConnectionTreeModel : INotifyCollectionChanged, INotifyPropertyChanged
public sealed class ConnectionTreeModel : INotifyCollectionChanged, INotifyPropertyChanged
{
public List<ContainerInfo> RootNodes { get; } = new List<ContainerInfo>();
@@ -30,7 +30,7 @@ namespace mRemoteNG.Tree
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, rootNode));
}
public IEnumerable<ConnectionInfo> GetRecursiveChildList()
public IReadOnlyList<ConnectionInfo> GetRecursiveChildList()
{
var list = new List<ConnectionInfo>();
foreach (var rootNode in RootNodes)

View File

@@ -5,7 +5,7 @@ using mRemoteNG.Connection;
namespace mRemoteNG.Tree
{
public class NodeSearcher
public class NodeSearcher
{
private readonly ConnectionTreeModel _connectionTreeModel;
@@ -22,7 +22,7 @@ namespace mRemoteNG.Tree
{
ResetMatches();
if (searchText == "") return Matches;
var nodes = (List<ConnectionInfo>)_connectionTreeModel.GetRecursiveChildList();
var nodes = _connectionTreeModel.GetRecursiveChildList();
var searchTextLower = searchText.ToLowerInvariant();
foreach (var node in nodes)
{