Inheritance: IPrepackagingService
        public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var assemblyResourceDownloader = new Mock<IAssemblyResourceDownloader>();
            var buildResultFilePathProvider = new Mock<IBuildResultFilePathProvider>();
            var prePackagingFolderPathProvider = new Mock<IPrePackagingFolderPathProvider>();

            // Act
            var prepackagingService = new PrepackagingService(
                filesystemAccessor.Object, assemblyResourceDownloader.Object, buildResultFilePathProvider.Object, prePackagingFolderPathProvider.Object);

            // Assert
            Assert.IsNotNull(prepackagingService);
        }
        public void Prepackage_Applications_FilesAreCopiedToTheApplicationsFolder_SuccessResultIsReturned()
        {
            // Arrange
            string buildFolder = "C:\\build";
            string prepackagingFolder = Path.GetFullPath("Prepackaging");

            var relativeFilePathInfos = new[]
                {
                    new RelativeFilePathInfo(@"C:\app\some-folder\some-file1.txt", @"some-folder\some-file1.txt"),
                    new RelativeFilePathInfo(@"C:\app\some-folder\some-file2.txt", @"some-folder\some-file2.txt"),
                    new RelativeFilePathInfo(@"C:\app\some-other-folder\some-file1.txt", @"some-other-folder\some-file1.txt")
                };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(prepackagingFolder)).Returns(true);
            filesystemAccessor.Setup(f => f.DirectoryExists(buildFolder)).Returns(true);

            var assemblyResourceDownloader = new Mock<IAssemblyResourceDownloader>();
            var buildResultFilePathProvider = new Mock<IBuildResultFilePathProvider>();
            buildResultFilePathProvider.Setup(b => b.GetApplicationFilePaths(It.IsAny<string>())).Returns(relativeFilePathInfos);

            var prePackagingFolderPathProvider = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProvider.Setup(p => p.GetPrePackagingFolderPath()).Returns(prepackagingFolder);

            var prepackagingService = new PrepackagingService(
                filesystemAccessor.Object, assemblyResourceDownloader.Object, buildResultFilePathProvider.Object, prePackagingFolderPathProvider.Object);

            // Act
            var result = prepackagingService.Prepackage(buildFolder);

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
            foreach (var relativeFilePathInfo in relativeFilePathInfos)
            {
                string absolutePath = relativeFilePathInfo.AbsoluteFilePath;
                string relativePath = Path.Combine(PrepackagingService.TargetFolderNameApplications, relativeFilePathInfo.RelativeFilePath);
                filesystemAccessor.Verify(f => f.CopyFile(absolutePath, It.Is<string>(s => s.EndsWith(relativePath))), Times.Once());
            }
        }
        public void Prepackage_PrepackagingFolderIsInvalid_FailureResultIsReturned(string prepackagingFolder)
        {
            // Arrange
            string buildFolder = "C:\\build";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(prepackagingFolder)).Returns(false);

            var assemblyResourceDownloader = new Mock<IAssemblyResourceDownloader>();
            var buildResultFilePathProvider = new Mock<IBuildResultFilePathProvider>();
            var prePackagingFolderPathProvider = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProvider.Setup(p => p.GetPrePackagingFolderPath()).Returns(prepackagingFolder);

            var prepackagingService = new PrepackagingService(
                filesystemAccessor.Object, assemblyResourceDownloader.Object, buildResultFilePathProvider.Object, prePackagingFolderPathProvider.Object);

            // Act
            var result = prepackagingService.Prepackage(buildFolder);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void Prepackage_PrepackagingFolderIsDoesNotExist_FailureResultIsReturned()
        {
            // Arrange
            string buildFolder = "C:\\build";
            string prepackagingFolder = Path.GetFullPath("Non-Existing-Folder");

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var assemblyResourceDownloader = new Mock<IAssemblyResourceDownloader>();
            var buildResultFilePathProvider = new Mock<IBuildResultFilePathProvider>();
            var prePackagingFolderPathProvider = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProvider.Setup(p => p.GetPrePackagingFolderPath()).Returns(prepackagingFolder);

            var prepackagingService = new PrepackagingService(
                filesystemAccessor.Object, assemblyResourceDownloader.Object, buildResultFilePathProvider.Object, prePackagingFolderPathProvider.Object);

            // Act
            var result = prepackagingService.Prepackage(buildFolder);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void Prepackage_OneOfTheSubFunctionsThrowsAnExecption_FailureResultIsReturned()
        {
            // Arrange
            string buildFolder = "C:\\build";
            string prepackagingFolder = Path.GetFullPath("Prepackaging");

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(prepackagingFolder)).Returns(true);

            var assemblyResourceDownloader = new Mock<IAssemblyResourceDownloader>();
            var buildResultFilePathProvider = new Mock<IBuildResultFilePathProvider>();
            var prePackagingFolderPathProvider = new Mock<IPrePackagingFolderPathProvider>();

            prePackagingFolderPathProvider.Setup(p => p.GetPrePackagingFolderPath()).Returns(prepackagingFolder);
            buildResultFilePathProvider.Setup(b => b.GetDeploymentPackageAdditionFilePaths(It.IsAny<string>())).Throws(new Exception());

            var prepackagingService = new PrepackagingService(
                filesystemAccessor.Object, assemblyResourceDownloader.Object, buildResultFilePathProvider.Object, prePackagingFolderPathProvider.Object);

            // Act
            var result = prepackagingService.Prepackage(buildFolder);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void Prepackage_NoFilesInBuildResultFolder_NothingIsCopied_SuccessResultIsReturned()
        {
            // Arrange
            string buildFolder = "C:\\build";
            string prepackagingFolder = Path.GetFullPath("Prepackaging");

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(prepackagingFolder)).Returns(true);
            filesystemAccessor.Setup(f => f.DirectoryExists(buildFolder)).Returns(true);

            var assemblyResourceDownloader = new Mock<IAssemblyResourceDownloader>();
            var buildResultFilePathProvider = new Mock<IBuildResultFilePathProvider>();
            var prePackagingFolderPathProvider = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProvider.Setup(p => p.GetPrePackagingFolderPath()).Returns(prepackagingFolder);

            var prepackagingService = new PrepackagingService(
                filesystemAccessor.Object, assemblyResourceDownloader.Object, buildResultFilePathProvider.Object, prePackagingFolderPathProvider.Object);

            // Act
            var result = prepackagingService.Prepackage(buildFolder);

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
            filesystemAccessor.Verify(f => f.CopyFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }