Package() 공개 메소드

public Package ( ) : IServiceResult
리턴 IServiceResult
예제 #1
0
        public void Package_FoldersExist_NuSpecFileExists_ButItsContentIsInvalid_ResultIsFalse(string nuspecFileContent)
        {
            // Arrange
            string prePackagingFolderPath = Path.GetFullPath("prepackaging");
            string packagingFolderPath = Path.GetFullPath("packaging");

            string nuspecFilePath = Path.GetFullPath("test.nuspec");
            Stream nuspecFileStream = TestUtilities.GetStreamReaderForText(nuspecFileContent).BaseStream;

            var prePackagingFolderPathProviderMock = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProviderMock.Setup(p => p.GetPrePackagingFolderPath()).Returns(prePackagingFolderPath);

            var packagingFolderPathProviderMock = new Mock<IPackagingFolderPathProvider>();
            packagingFolderPathProviderMock.Setup(p => p.GetPackagingFolderPath()).Returns(packagingFolderPath);

            var filesystemAccessorMock = new Mock<IFilesystemAccessor>();

            filesystemAccessorMock.Setup(f => f.DirectoryExists(prePackagingFolderPath)).Returns(true);
            filesystemAccessorMock.Setup(f => f.DirectoryExists(packagingFolderPath)).Returns(true);

            filesystemAccessorMock.Setup(f => f.GetFiles(prePackagingFolderPath)).Returns(new List<FileInfo> { new FileInfo(nuspecFilePath) });
            filesystemAccessorMock.Setup(f => f.GetReadStream(nuspecFilePath)).Returns(nuspecFileStream);

            var packagingService = new PackagingService(prePackagingFolderPathProviderMock.Object, packagingFolderPathProviderMock.Object, filesystemAccessorMock.Object);

            // Act
            var result = packagingService.Package();
            nuspecFileStream.Close();

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
예제 #2
0
        public void Package_PrePackagingFolderPathDoesNotexist_ResultIsFalse()
        {
            // Arrange
            string prePackagingFolderPath = Path.GetFullPath("prepackaging");

            var prePackagingFolderPathProviderMock = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProviderMock.Setup(p => p.GetPrePackagingFolderPath()).Returns(prePackagingFolderPath);

            var packagingFolderPathProviderMock = new Mock<IPackagingFolderPathProvider>();

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

            var packagingService = new PackagingService(prePackagingFolderPathProviderMock.Object, packagingFolderPathProviderMock.Object, filesystemAccessorMock.Object);

            // Act
            var result = packagingService.Package();

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
예제 #3
0
        public void Package_FoldersExist_NuSpecFileExistsAndIsValid_ResultIsTrue()
        {
            // Arrange
            string prePackagingFolderPath = Path.GetFullPath("prepackaging");
            Directory.CreateDirectory(prePackagingFolderPath);
            File.WriteAllText(Path.Combine(prePackagingFolderPath, "sample.txt"), "yada yada");

            string packagingFolderPath = Path.GetFullPath("packaging");
            Directory.CreateDirectory(packagingFolderPath);
            string targetPackagePath = Path.Combine(packagingFolderPath, "package.zip");
            FileStream packageStream = File.Open(targetPackagePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            string nuspecFilePath = Path.GetFullPath("test.nuspec");
            string nuspecFileContent = "<?xml version=\"1.0\"?> <package> <metadata> <id>Packaging.Test</id> <version>1.0.0</version> <authors>NuDeploy.Tests</authors> <owners>NuDeploy.Tests</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Packaging Test</description> <releaseNotes></releaseNotes> <copyright>NuDeploy.Tests</copyright> </metadata> </package>";
            Stream nuspecFileStream = TestUtilities.GetStreamReaderForText(nuspecFileContent).BaseStream;

            var prePackagingFolderPathProviderMock = new Mock<IPrePackagingFolderPathProvider>();
            prePackagingFolderPathProviderMock.Setup(p => p.GetPrePackagingFolderPath()).Returns(prePackagingFolderPath);

            var packagingFolderPathProviderMock = new Mock<IPackagingFolderPathProvider>();
            packagingFolderPathProviderMock.Setup(p => p.GetPackagingFolderPath()).Returns(packagingFolderPath);

            var filesystemAccessorMock = new Mock<IFilesystemAccessor>();

            filesystemAccessorMock.Setup(f => f.DirectoryExists(prePackagingFolderPath)).Returns(true);
            filesystemAccessorMock.Setup(f => f.DirectoryExists(packagingFolderPath)).Returns(true);

            filesystemAccessorMock.Setup(f => f.GetFiles(prePackagingFolderPath)).Returns(new List<FileInfo> { new FileInfo(nuspecFilePath) });
            filesystemAccessorMock.Setup(f => f.GetReadStream(nuspecFilePath)).Returns(nuspecFileStream);

            filesystemAccessorMock.Setup(f => f.GetWriteStream(It.IsAny<string>())).Returns(packageStream);

            var packagingService = new PackagingService(prePackagingFolderPathProviderMock.Object, packagingFolderPathProviderMock.Object, filesystemAccessorMock.Object);

            // Act
            var result = packagingService.Package();

            nuspecFileStream.Close();
            packageStream.Close();

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
            Assert.IsTrue(File.Exists(targetPackagePath));
        }