Reorganized PackageManager and added documentation

--- Tests/OpenIIoT.Core.Tests/Package/PackageManager.cs
+++ Tests/OpenIIoT.Core.Tests/Package/PackageManager.cs
@@ -1,19 +1,69 @@
-using Moq;
-using OpenIIoT.SDK;
-using OpenIIoT.SDK.Package;
-using OpenIIoT.SDK.Platform;
+/*
+      █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀  ▀  ▀      ▀▀
+      █
+      █      ▄███████▄                                                                 ▄▄▄▄███▄▄▄▄
+      █     ███    ███                                                               ▄██▀▀▀███▀▀▀██▄
+      █     ███    ███   ▄█████   ▄██████    █  █▄     ▄█████     ▄████▄     ▄█████  ███   ███   ███   ▄█████  ██▄▄▄▄    ▄█████     ▄████▄     ▄█████    █████
+      █     ███    ███   ██   ██ ██    ██   ██ ▄██▀    ██   ██   ██    ▀    ██   █   ███   ███   ███   ██   ██ ██▀▀▀█▄   ██   ██   ██    ▀    ██   █    ██  ██
+      █   ▀█████████▀    ██   ██ ██    ▀    ██▐█▀      ██   ██  ▄██        ▄██▄▄     ███   ███   ███   ██   ██ ██   ██   ██   ██  ▄██        ▄██▄▄     ▄██▄▄█▀
+      █     ███        ▀████████ ██    ▄  ▀▀████     ▀████████ ▀▀██ ███▄  ▀▀██▀▀     ███   ███   ███ ▀████████ ██   ██ ▀████████ ▀▀██ ███▄  ▀▀██▀▀    ▀███████
+      █     ███          ██   ██ ██    ██   ██ ▀██▄    ██   ██   ██    ██   ██   █   ███   ███   ███   ██   ██ ██   ██   ██   ██   ██    ██   ██   █    ██  ██
+      █    ▄████▀        ██   █▀ ██████▀    ▀█   ▀█▀   ██   █▀   ██████▀    ███████   ▀█   ███   █▀    ██   █▀  █   █    ██   █▀   ██████▀    ███████   ██  ██
+      █
+      █       ███
+      █   ▀█████████▄
+      █      ▀███▀▀██    ▄█████   ▄█████     ██      ▄█████
+      █       ███   ▀   ██   █    ██  ▀  ▀███████▄   ██  ▀
+      █       ███      ▄██▄▄      ██         ██  ▀   ██
+      █       ███     ▀▀██▀▀    ▀███████     ██    ▀███████
+      █       ███       ██   █     ▄  ██     ██       ▄  ██
+      █      ▄████▀     ███████  ▄████▀     ▄██▀    ▄████▀
+      █
+ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄  ▄▄ ▄▄   ▄▄▄▄ ▄▄     ▄▄     ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
+ █████████████████████████████████████████████████████████████ ███████████████ ██  ██ ██   ████ ██     ██     ████████████████ █ █
+      ▄
+      █  Unit tests for the PackageManager class.
+      █
+      █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀     ▀▀               ▀
+      █  The GNU Affero General Public License (GNU AGPL)
+      █
+      █  Copyright (C) 2016-2017 JP Dillingham (jp@dillingham.ws)
+      █
+      █  This program is free software: you can redistribute it and/or modify
+      █  it under the terms of the GNU Affero General Public License as published by
+      █  the Free Software Foundation, either version 3 of the License, or
+      █  (at your option) any later version.
+      █
+      █  This program is distributed in the hope that it will be useful,
+      █  but WITHOUT ANY WARRANTY; without even the implied warranty of
+      █  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+      █  GNU Affero General Public License for more details.
+      █
+      █  You should have received a copy of the GNU Affero General Public License
+      █  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+      █
+      ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀  ▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀██
+                                                                                ██
+                                                                                ▀█▄ ██ ▄█▀
+                                                                                ▀████▀
+                                                                                ▀▀                            */
+
 using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
+using Moq;
+using OpenIIoT.SDK;
+using OpenIIoT.SDK.Package;
+using OpenIIoT.SDK.Platform;
 using Utility.OperationResult;
 using Xunit;

 namespace OpenIIoT.Core.Tests.Package
 {
+    /// <summary>
+    ///     Unit tests for the <see cref="Core.Package.PackageManager"/> class.
+    /// </summary>
     public class PackageManager : IDisposable
     {
         #region Public Constructors
@@ -37,7 +87,172 @@

         #endregion Public Constructors

+        #region Private Properties
+
+        /// <summary>
+        ///     Gets or sets the package test data directory.
+        /// </summary>
+        private string Data { get; set; }
+
+        /// <summary>
+        ///     Gets or sets the root test data directory.
+        /// </summary>
+        private string DataRoot { get; set; }
+
+        /// <summary>
+        ///     Gets or sets the temporary data directory.
+        /// </summary>
+        private string Temp { get; set; }
+
+        #endregion Private Properties
+
         #region Public Methods
+
+        /// <summary>
+        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a known good package payload.
+        /// </summary>
+        [Fact]
+        public void CreatePackage()
+        {
+            byte[] data = File.ReadAllBytes(Path.Combine(Data, "package.zip"));
+
+            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
+            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
+
+            Mock<IDirectories> dirMock = new Mock<IDirectories>();
+            dirMock.Setup(d => d.Packages).Returns(Temp);
+            dirMock.Setup(d => d.Temp).Returns(Temp);
+
+            IResult<string> successResult = new Result<string>();
+
+            Mock<IPlatform> platformMock = new Mock<IPlatform>();
+            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
+
+            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
+                .Returns(successResult)
+                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
+
+            platformMock.Setup(p => p.CopyFile(It.IsAny<string>(), It.IsAny<string>(), true))
+                .Returns(successResult)
+                    .Callback<string, string, bool>((s, d, o) => File.Copy(s, d, o));
+
+            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
+
+            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
+
+            IResult<IPackage> package = test.CreatePackage(data);
+
+            Assert.Equal(ResultCode.Success, package.ResultCode);
+            Assert.True(File.Exists(Path.Combine(Temp, "OpenIIoT.Plugin.DefaultPlugin.1.0.0.zip")));
+        }
+
+        /// <summary>
+        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a known bad package payload.
+        /// </summary>
+        [Fact]
+        public void CreatePackageBadData()
+        {
+            byte[] data = File.ReadAllBytes(Path.Combine(DataRoot, "notapackage.zip"));
+
+            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
+            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
+
+            Mock<IDirectories> dirMock = new Mock<IDirectories>();
+            dirMock.Setup(d => d.Packages).Returns(Temp);
+            dirMock.Setup(d => d.Temp).Returns(Temp);
+
+            IResult<string> successResult = new Result<string>();
+
+            Mock<IPlatform> platformMock = new Mock<IPlatform>();
+            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
+
+            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
+                .Returns(successResult)
+                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
+
+            platformMock.Setup(p => p.CopyFile(It.IsAny<string>(), It.IsAny<string>(), true))
+                .Returns(successResult)
+                    .Callback<string, string, bool>((s, d, o) => File.Copy(s, d, o));
+
+            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
+
+            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
+
+            IResult<IPackage> package = test.CreatePackage(data);
+
+            Assert.Equal(ResultCode.Failure, package.ResultCode);
+        }
+
+        /// <summary>
+        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a mocked platform simulating a
+        ///     failed file copy.
+        /// </summary>
+        [Fact]
+        public void CreatePackageCopyFailed()
+        {
+            byte[] data = File.ReadAllBytes(Path.Combine(Data, "package.zip"));
+
+            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
+            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
+
+            Mock<IDirectories> dirMock = new Mock<IDirectories>();
+            dirMock.Setup(d => d.Packages).Returns(Temp);
+            dirMock.Setup(d => d.Temp).Returns(Temp);
+
+            IResult<string> successResult = new Result<string>();
+            IResult<string> failResult = new Result<string>(ResultCode.Failure);
+
+            Mock<IPlatform> platformMock = new Mock<IPlatform>();
+            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
+
+            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
+                .Returns(successResult)
+                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
+
+            platformMock.Setup(p => p.CopyFile(It.IsAny<string>(), It.IsAny<string>(), true))
+                .Returns(failResult);
+
+            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
+
+            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
+            IResult<IPackage> package = test.CreatePackage(data);
+
+            Assert.Equal(ResultCode.Failure, package.ResultCode);
+        }
+
+        /// <summary>
+        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a mocked platform simulating a
+        ///     failed file write.
+        /// </summary>
+        [Fact]
+        public void CreatePackageWriteFailed()
+        {
+            byte[] data = new byte[] { };
+
+            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
+            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
+
+            Mock<IDirectories> dirMock = new Mock<IDirectories>();
+            dirMock.Setup(d => d.Packages).Returns(Temp);
+            dirMock.Setup(d => d.Temp).Returns(Temp);
+
+            IResult<string> failResult = new Result<string>(ResultCode.Failure);
+
+            Mock<IPlatform> platformMock = new Mock<IPlatform>();
+            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
+
+            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
+                .Returns(failResult)
+                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
+
+            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
+
+            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
+
+            IResult<IPackage> package = test.CreatePackage(data);
+
+            Assert.Equal(ResultCode.Failure, package.ResultCode);
+        }

         /// <summary>
         ///     Disposes of this instance.
@@ -47,8 +262,6 @@
             Dispose(true);
             GC.SuppressFinalize(this);
         }
-
-        #endregion Public Methods

         /// <summary>
         ///     Tests the <see cref="Core.Package.PackageUtility.Scan(string)"/> method with a bad directory.
@@ -172,6 +385,8 @@
             Assert.NotEqual(0, list.ReturnValue[0].FQN.Length);
         }

+        #endregion Public Methods
+
         #region Protected Methods

         /// <summary>
@@ -186,174 +401,5 @@
         }

         #endregion Protected Methods
-
-        #region Private Properties
-
-        /// <summary>
-        ///     Gets or sets the package test data directory.
-        /// </summary>
-        private string Data { get; set; }
-
-        /// <summary>
-        ///     Gets or sets the root test data directory.
-        /// </summary>
-        private string DataRoot { get; set; }
-
-        /// <summary>
-        ///     Gets or sets the temporary data directory.
-        /// </summary>
-        private string Temp { get; set; }
-
-        #endregion Private Properties
-
-        #region Public Methods
-
-        /// <summary>
-        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a known good package payload.
-        /// </summary>
-        [Fact]
-        public void CreatePackage()
-        {
-            byte[] data = File.ReadAllBytes(Path.Combine(Data, "package.zip"));
-
-            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
-            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
-
-            Mock<IDirectories> dirMock = new Mock<IDirectories>();
-            dirMock.Setup(d => d.Packages).Returns(Temp);
-            dirMock.Setup(d => d.Temp).Returns(Temp);
-
-            IResult<string> successResult = new Result<string>();
-
-            Mock<IPlatform> platformMock = new Mock<IPlatform>();
-            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
-
-            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
-                .Returns(successResult)
-                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
-
-            platformMock.Setup(p => p.CopyFile(It.IsAny<string>(), It.IsAny<string>(), true))
-                .Returns(successResult)
-                    .Callback<string, string, bool>((s, d, o) => File.Copy(s, d, o));
-
-            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
-
-            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
-
-            IResult<IPackage> package = test.CreatePackage(data);
-
-            Assert.Equal(ResultCode.Success, package.ResultCode);
-            Assert.True(File.Exists(Path.Combine(Temp, "OpenIIoT.Plugin.DefaultPlugin.1.0.0.zip")));
-        }
-
-        /// <summary>
-        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a known bad package payload.
-        /// </summary>
-        [Fact]
-        public void CreatePackageBadData()
-        {
-            byte[] data = File.ReadAllBytes(Path.Combine(DataRoot, "notapackage.zip"));
-
-            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
-            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
-
-            Mock<IDirectories> dirMock = new Mock<IDirectories>();
-            dirMock.Setup(d => d.Packages).Returns(Temp);
-            dirMock.Setup(d => d.Temp).Returns(Temp);
-
-            IResult<string> successResult = new Result<string>();
-
-            Mock<IPlatform> platformMock = new Mock<IPlatform>();
-            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
-
-            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
-                .Returns(successResult)
-                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
-
-            platformMock.Setup(p => p.CopyFile(It.IsAny<string>(), It.IsAny<string>(), true))
-                .Returns(successResult)
-                    .Callback<string, string, bool>((s, d, o) => File.Copy(s, d, o));
-
-            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
-
-            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
-
-            IResult<IPackage> package = test.CreatePackage(data);
-
-            Assert.Equal(ResultCode.Failure, package.ResultCode);
-        }
-
-        /// <summary>
-        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a mocked platform simulating a
-        ///     failed file copy.
-        /// </summary>
-        [Fact]
-        public void CreatePackageCopyFailed()
-        {
-            byte[] data = File.ReadAllBytes(Path.Combine(Data, "package.zip"));
-
-            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
-            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
-
-            Mock<IDirectories> dirMock = new Mock<IDirectories>();
-            dirMock.Setup(d => d.Packages).Returns(Temp);
-            dirMock.Setup(d => d.Temp).Returns(Temp);
-
-            IResult<string> successResult = new Result<string>();
-            IResult<string> failResult = new Result<string>(ResultCode.Failure);
-
-            Mock<IPlatform> platformMock = new Mock<IPlatform>();
-            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
-
-            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
-                .Returns(successResult)
-                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
-
-            platformMock.Setup(p => p.CopyFile(It.IsAny<string>(), It.IsAny<string>(), true))
-                .Returns(failResult);
-
-            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
-
-            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
-            IResult<IPackage> package = test.CreatePackage(data);
-
-            Assert.Equal(ResultCode.Failure, package.ResultCode);
-        }
-
-        /// <summary>
-        ///     Tests the <see cref="Core.Package.PackageUtility.Create(byte[])"/> method with a mocked platform simulating a
-        ///     failed file write.
-        /// </summary>
-        [Fact]
-        public void CreatePackageWriteFailed()
-        {
-            byte[] data = new byte[] { };
-
-            Mock<IApplicationManager> managerMock = new Mock<IApplicationManager>();
-            Mock<IPlatformManager> platformManagerMock = new Mock<IPlatformManager>();
-
-            Mock<IDirectories> dirMock = new Mock<IDirectories>();
-            dirMock.Setup(d => d.Packages).Returns(Temp);
-            dirMock.Setup(d => d.Temp).Returns(Temp);
-
-            IResult<string> failResult = new Result<string>(ResultCode.Failure);
-
-            Mock<IPlatform> platformMock = new Mock<IPlatform>();
-            platformMock.Setup(p => p.Directories).Returns(dirMock.Object);
-
-            platformMock.Setup(p => p.WriteFileBytes(It.IsAny<string>(), It.IsAny<byte[]>()))
-                .Returns(failResult)
-                    .Callback<string, byte[]>((f, b) => File.WriteAllBytes(f, b));
-
-            platformManagerMock.Setup(p => p.Platform).Returns(platformMock.Object);
-
-            IPackageManager test = Core.Package.PackageManager.Instantiate(managerMock.Object, platformManagerMock.Object);
-
-            IResult<IPackage> package = test.CreatePackage(data);
-
-            Assert.Equal(ResultCode.Failure, package.ResultCode);
-        }
-
-        #endregion Public Methods
     }
 }