public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var relativeFilePathInfoFactory = new Mock<IRelativeFilePathInfoFactory>();

            // Act
            var buildResultFilePathProvider = new ConventionBasedBuildResultFilePathProvider(filesystemAccessor.Object, relativeFilePathInfoFactory.Object);

            // Assert
            Assert.IsNotNull(buildResultFilePathProvider);
        }
        public void GetApplicationFilePaths_FolderDoesNotExist_ResultIsEmptyList()
        {
            // Arrange
            string buildFolder = Path.GetFullPath("build-folder");

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(false);

            var relativeFilePathInfoFactory = new Mock<IRelativeFilePathInfoFactory>();

            var buildResultFilePathProvider = new ConventionBasedBuildResultFilePathProvider(filesystemAccessor.Object, relativeFilePathInfoFactory.Object);

            // Act
            var result = buildResultFilePathProvider.GetApplicationFilePaths(buildFolder);

            // Assert
            Assert.AreEqual(0, result.Length);
        }
        public void GetApplicationFilePaths_FolderExist_ContainsOneApplication_ResultCountEqualsFileCount_GetRelativeFilePathInfoIsCalledForEachFile()
        {
            // Arrange
            string buildFolder = Path.GetFullPath("build-folder");

            string applicationPath = Path.Combine(buildFolder, ConventionBasedBuildResultFilePathProvider.FolderNamePublishedApplications, "Test.App.1");

            var files = new List<FileInfo>
                {
                    new FileInfo(Path.Combine(applicationPath, "file1.txt")),
                    new FileInfo(Path.Combine(applicationPath, "file2.txt")),
                };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(true);
            filesystemAccessor.Setup(f => f.GetAllFiles(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(files);

            var relativeFilePathInfoFactory = new Mock<IRelativeFilePathInfoFactory>();

            var buildResultFilePathProvider = new ConventionBasedBuildResultFilePathProvider(filesystemAccessor.Object, relativeFilePathInfoFactory.Object);

            // Act
            var result = buildResultFilePathProvider.GetApplicationFilePaths(buildFolder);

            // Assert
            Assert.AreEqual(files.Count, result.Length);
            foreach (var websiteFile in files)
            {
                string absolutePath = websiteFile.FullName;
                relativeFilePathInfoFactory.Verify(r => r.GetRelativeFilePathInfo(absolutePath, It.IsAny<string>()), Times.Once());
            }
        }
        public void GetWebsiteFilePaths_FolderExist_ButContainsNoWebsites_ResultIsEmptyList()
        {
            // Arrange
            string buildFolder = Path.GetFullPath("build-folder");

            var publishedWebApplicationDirectories = new List<DirectoryInfo>
                {
                    new DirectoryInfo(Path.Combine(buildFolder, "WebApplication1")),
                    new DirectoryInfo(Path.Combine(buildFolder, "WebApplication2")),
                    new DirectoryInfo(Path.Combine(buildFolder, "WebApplication3"))
                };

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(true);
            filesystemAccessor.Setup(f => f.GetSubDirectories(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(publishedWebApplicationDirectories);

            var relativeFilePathInfoFactory = new Mock<IRelativeFilePathInfoFactory>();

            var buildResultFilePathProvider = new ConventionBasedBuildResultFilePathProvider(filesystemAccessor.Object, relativeFilePathInfoFactory.Object);

            // Act
            var result = buildResultFilePathProvider.GetWebsiteFilePaths(buildFolder);

            // Assert
            Assert.AreEqual(0, result.Length);
        }
        public void GetDeploymentPackageAdditionFilePaths_FolderExist_ButIsEmpty_ResultIsEmptyList()
        {
            // Arrange
            string buildFolder = Path.GetFullPath("build-folder");

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DirectoryExists(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(true);
            filesystemAccessor.Setup(f => f.GetSubDirectories(It.Is<string>(s => s.StartsWith(buildFolder)))).Returns(new List<DirectoryInfo>());

            var relativeFilePathInfoFactory = new Mock<IRelativeFilePathInfoFactory>();

            var buildResultFilePathProvider = new ConventionBasedBuildResultFilePathProvider(filesystemAccessor.Object, relativeFilePathInfoFactory.Object);

            // Act
            var result = buildResultFilePathProvider.GetDeploymentPackageAdditionFilePaths(buildFolder);

            // Assert
            Assert.AreEqual(0, result.Length);
        }