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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.47
2.1.48
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
namespace VirtualClient.Common
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -66,5 +68,42 @@ public void WaitForResponseAsyncExtensionThrowsIfTheExpectedResponseIsNotReceive
Assert.ThrowsAsync<TimeoutException>(
() => this.mockProcess.WaitForResponseAsync("NeverGonnaShow", CancellationToken.None, timeout: TimeSpan.Zero));
}

[Test]
public void ProcessDetailsCloneCreatesANewInstanceWithTheSameValues()
{
ProcessDetails process1 = new ProcessDetails
{
Id = -1,
CommandLine = Guid.NewGuid().ToString(),
ExitTime = DateTime.UtcNow,
ExitCode = -2,
StandardOutput = Guid.NewGuid().ToString(),
StandardError = Guid.NewGuid().ToString(),
StartTime = DateTime.MinValue,
ToolName = Guid.NewGuid().ToString(),
WorkingDirectory = Guid.NewGuid().ToString(),
Results = new[]
{
new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString())
}
};

ProcessDetails process2 = process1.Clone();

Assert.AreNotEqual(process1, process2);

Assert.AreEqual(process1.Id, process2.Id);
Assert.AreEqual(process1.CommandLine, process2.CommandLine);
Assert.AreEqual(process1.ExitTime, process2.ExitTime);
Assert.AreEqual(process1.ExitCode, process2.ExitCode);
Assert.AreEqual(process1.StandardOutput, process2.StandardOutput);
Assert.AreEqual(process1.StandardError, process2.StandardError);
Assert.AreEqual(process1.StartTime, process2.StartTime);
Assert.AreEqual(process1.ToolName, process2.ToolName);
Assert.AreEqual(process1.WorkingDirectory, process2.WorkingDirectory);
Assert.AreEqual(process1.Results.Count(), process2.Results.Count());
}
}
}
32 changes: 32 additions & 0 deletions src/VirtualClient/VirtualClient.Common/ProcessDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;

namespace VirtualClient.Common
{
Expand Down Expand Up @@ -78,5 +79,36 @@ public TimeSpan? ElapsedTime
/// Working Directory.
/// </summary>
public string WorkingDirectory { get; set; }

/// <summary>
/// Returns a clone of the current instance.
/// </summary>
/// <returns>
/// A clone of the current instance.
/// </returns>
public virtual ProcessDetails Clone()
{
ProcessDetails clonedDetails = new ProcessDetails
{
Id = this.Id,
CommandLine = this.CommandLine,
ExitTime = this.ExitTime,
ExitCode = this.ExitCode,
StandardOutput = this.StandardOutput,
StandardError = this.StandardError,
StartTime = this.StartTime,
ToolName = this.ToolName,
WorkingDirectory = this.WorkingDirectory,
Results = new List<KeyValuePair<string, string>>()
};

// Always create a new collection instance when Results is non-null.
if (this.Results != null)
{
clonedDetails.Results = this.Results.ToList();
}

return clonedDetails;
}
}
}
Loading
Loading