Added a copy constructor to the CredentialRecord

This commit is contained in:
David Sparer
2016-10-28 11:41:27 -06:00
parent 1d2889f5b8
commit fffc0f9eae
2 changed files with 43 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Security;
using mRemoteNG.Credential;
using mRemoteNG.Security;
using NUnit.Framework;
@@ -13,7 +14,12 @@ namespace mRemoteNGTests.Credential
[SetUp]
public void Setup()
{
_credentialRecord = new CredentialRecord();
_credentialRecord = new CredentialRecord
{
Username = "userHere",
Domain = "domainHere",
Password = "somepass".ConvertToSecureString()
};
}
[Test]
@@ -48,5 +54,33 @@ namespace mRemoteNGTests.Credential
_credentialRecord = new CredentialRecord(customGuid);
Assert.That(_credentialRecord.UniqueId, Is.EqualTo(customGuid));
}
[Test]
public void CopyConstructorGeneratesNewGuid()
{
var cred2 = new CredentialRecord(_credentialRecord);
Assert.That(cred2.UniqueId, Is.Not.EqualTo(_credentialRecord.UniqueId));
}
[Test]
public void CopyConstructorCopiesUsername()
{
var cred2 = new CredentialRecord(_credentialRecord);
Assert.That(cred2.Username, Is.EqualTo(_credentialRecord.Username));
}
[Test]
public void CopyConstructorCopiesPassword()
{
var cred2 = new CredentialRecord(_credentialRecord);
Assert.That(cred2.Password, Is.EqualTo(_credentialRecord.Password));
}
[Test]
public void CopyConstructorCopiesDomain()
{
var cred2 = new CredentialRecord(_credentialRecord);
Assert.That(cred2.Domain, Is.EqualTo(_credentialRecord.Domain));
}
}
}

View File

@@ -6,7 +6,7 @@ namespace mRemoteNG.Credential
{
public class CredentialRecord : ICredential
{
public Guid UniqueId { get; }
public Guid UniqueId { get; } = Guid.NewGuid();
public string Username { get; set; } = "";
@@ -17,7 +17,13 @@ namespace mRemoteNG.Credential
public CredentialRecord()
{
UniqueId = Guid.NewGuid();
}
public CredentialRecord(ICredential otherCredential)
{
Username = otherCredential.Username;
Password = otherCredential.Password;
Domain = otherCredential.Domain;
}
public CredentialRecord(Guid customGuid)