예제 #1
0
        private void AddFiles(PackageBuilder builder, string itemType, string targetFolder)
        {
            // Skip files that are added by dependency packages
            string             packagesConfig = GetPackagesConfig();
            IPackageRepository repository     = GetPackagesRepository();
            var contentFilesInDependencies    = new List <IPackageFile>();

            if (packagesConfig != null && repository != null)
            {
                var references = new PackageReferenceFile(packagesConfig).GetPackageReferences();
                contentFilesInDependencies = references.Select(reference => repository.FindPackage(reference.Id, reference.Version))
                                             .SelectMany(a => a.GetContentFiles())
                                             .ToList();
            }

            // Get the content files from the project
            foreach (var item in _project.GetItems(itemType))
            {
                string fullPath = item.GetMetadataValue("FullPath");

                if (_excludeFiles.Contains(Path.GetFileName(fullPath)))
                {
                    continue;
                }

                string targetFilePath = GetTargetPath(item);

                if (!File.Exists(fullPath))
                {
                    Logger.Log(MessageLevel.Warning, NuGetResources.Warning_FileDoesNotExist, targetFilePath);
                    continue;
                }

                // Check that file is added by dependency
                string       targetPath = Path.Combine(targetFolder, targetFilePath);
                IPackageFile targetFile = contentFilesInDependencies.Find(a => a.Path.Equals(targetPath, StringComparison.OrdinalIgnoreCase));
                if (targetFile != null)
                {
                    // Compare contents as well
                    using (var dependencyFileStream = targetFile.GetStream())
                        using (var fileContentsStream = File.Open(fullPath, FileMode.Open))
                        {
                            var isEqual = FileHelper.AreFilesEqual(dependencyFileStream, fileContentsStream);
                            if (isEqual)
                            {
                                Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsNotChanged, targetFilePath);
                                continue;
                            }

                            Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsChanged, targetFilePath);
                        }
                }

                builder.Files.Add(new PhysicalPackageFile
                {
                    SourcePath = fullPath,
                    TargetPath = targetPath
                });
            }
        }
예제 #2
0
        public void DifferentTextFilePathsShouldNotBeEqual()
        {
            // Act
            var result = FileHelper.AreFilesEqual("./Moq.xml", "./Ninject.xml");

            // Assert
            Assert.False(result);
        }
예제 #3
0
        public void SameTextFilePathsShouldBeEqual()
        {
            // Act
            var result = FileHelper.AreFilesEqual("./Moq.xml", "./Moq.xml");

            // Assert
            Assert.True(result);
        }
예제 #4
0
        public void SameBinaryFilePathShouldBeEqual()
        {
            // Act
            var result = FileHelper.AreFilesEqual("./Moq.dll", "./Moq.dll");

            // Assert
            Assert.True(result);
        }
예제 #5
0
 public void SameBinaryFileStreamShouldBeEqual()
 {
     // Arrange
     using (var file1 = File.OpenRead("./Moq.dll"))
         using (var file2 = File.OpenRead("./Moq.dll"))
         {
             // Act
             var result = FileHelper.AreFilesEqual(file1, file2);
             // Assert
             Assert.True(result);
         }
 }
예제 #6
0
        public void DifferentTextFileStreamsShouldNotBeEqual()
        {
            // Arrange
            using (var file1 = File.OpenRead("./Moq.xml"))
                using (var file2 = File.OpenRead("./Ninject.xml"))
                {
                    // Act
                    var result = FileHelper.AreFilesEqual(file1, file2);

                    // Assert
                    Assert.False(result);
                }
        }
예제 #7
0
 public void should_return_false_if_one_of_the_provided_file_name_does_not_exist()
 {
     FileHelper.AreFilesEqual(_existingFile, _oneFileThatDoesNotExist).ShouldBeFalse();
 }
예제 #8
0
 public void should_return_false_if_the_files_does_not_have_the_same_content()
 {
     FileHelper.AreFilesEqual(_existingFile, _anotherExistingFile).ShouldBeFalse();
 }
예제 #9
0
 public void should_return_true_if_the_files_have_the_same_content()
 {
     FileHelper.AreFilesEqual(_existingFile, _existingFile).ShouldBeTrue();
     FileHelper.AreFilesEqual(_existingFile, _copyOfExistingFile).ShouldBeTrue();
     FileHelper.AreFilesEqual(_existingFile, _anotherFileWithTheSameContent).ShouldBeTrue();
 }
예제 #10
0
 public void should_use_the_file_already_open_as_source_for_the_new_session_factory()
 {
     FileHelper.AreFilesEqual(_fileNameToCreate, _anotherFile).ShouldBeTrue();
 }