mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-26 03:58:45 +08:00
created a helper to ensure that all connectioninfo objects in an xdoc have IDs
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using mRemoteNG.Config.Serializers;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
namespace mRemoteNGTests.Config.Serializers
|
||||
{
|
||||
public class ConfConsEnsureConnectionsHaveIdsTests
|
||||
{
|
||||
private ConfConsEnsureConnectionsHaveIds _consEnsureConnectionsHaveIds;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_consEnsureConnectionsHaveIds = new ConfConsEnsureConnectionsHaveIds();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdAttributeIsAddedIfItDidntExist()
|
||||
{
|
||||
var xdoc = CreateTestDocument();
|
||||
_consEnsureConnectionsHaveIds.EnsureElementsHaveIds(xdoc);
|
||||
var attribute = xdoc.Root?.Element("Node")?.Attribute("Id");
|
||||
Assert.That(attribute, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NewIdAttributeShouldNotBeAnEmptyGuid()
|
||||
{
|
||||
var xdoc = CreateTestDocument();
|
||||
_consEnsureConnectionsHaveIds.EnsureElementsHaveIds(xdoc);
|
||||
var attribute = xdoc.Root?.Element("Node")?.Attribute("Id");
|
||||
Assert.That(attribute?.Value, Is.Not.EqualTo(Guid.Empty.ToString()));
|
||||
}
|
||||
|
||||
private XDocument CreateTestDocument()
|
||||
{
|
||||
var xdoc = new XDocument();
|
||||
xdoc.Add(new XElement("Root",
|
||||
new XElement("Node",
|
||||
new XAttribute("Thingy",""))));
|
||||
return xdoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,7 @@
|
||||
<Compile Include="App\UpdaterTests.cs" />
|
||||
<Compile Include="BinaryFileTests.cs" />
|
||||
<Compile Include="Config\CredentialHarvesterTests.cs" />
|
||||
<Compile Include="Config\Serializers\ConfConsEnsureConnectionsHaveIdsTests.cs" />
|
||||
<Compile Include="Config\Serializers\CredentialProviderSerializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\DataTableSerializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\PortScanDeserializerTests.cs" />
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
namespace mRemoteNG.Config.Serializers
|
||||
{
|
||||
public class ConfConsEnsureConnectionsHaveIds
|
||||
{
|
||||
public void EnsureElementsHaveIds(XDocument xdoc)
|
||||
{
|
||||
foreach (var element in xdoc.Descendants("Node"))
|
||||
{
|
||||
if (element.Attribute("Id") != null) continue;
|
||||
var id = Guid.NewGuid();
|
||||
element.Add(new XAttribute("Id", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,7 @@
|
||||
<Compile Include="Config\Serializers\XmlCredentialDeserializer.cs" />
|
||||
<Compile Include="Config\Serializers\XmlCredentialRecordSerializer.cs" />
|
||||
<Compile Include="Config\Serializers\XmlRootNodeSerializer.cs" />
|
||||
<Compile Include="Config\Serializers\ConfConsEnsureConnectionsHaveIds.cs" />
|
||||
<Compile Include="Config\Settings\ExternalAppsLoader.cs" />
|
||||
<Compile Include="Config\Settings\LayoutSettingsLoader.cs" />
|
||||
<Compile Include="Config\Settings\Providers\AppSettingsProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user