Пример #1
0
        public void AddFilesAskingForResolutionForEveryConflict()
        {
            var resolutions = new FileConflictResolution[]
            {
                FileConflictResolution.Ignore,
                FileConflictResolution.Overwrite,
                FileConflictResolution.Ignore,
                FileConflictResolution.IgnoreAll,
                FileConflictResolution.OverwriteAll,
                FileConflictResolution.Overwrite,
            };

            var index  = 0;
            var logger = new Mock <ILogger>();

            logger.Setup(l => l.ResolveFileConflict(It.IsAny <string>()))
            .Returns(() => resolutions[index++]);

            // Arrange
            var project = new MockProjectSystem();

            project.AddFile("a.txt", "this is a");
            project.AddFile("b.txt", "this is b");
            project.AddFile("c.txt", "this is c");
            project.AddFile("d.txt", "this is d");
            project.AddFile("e.txt", "this is e");
            project.AddFile("f.txt", "this is f");
            project.Logger = logger.Object;

            var files = PackageUtility.CreateFiles(new [] { "a.txt", "b.txt", "c.txt", "d.txt", "e.txt", "f.txt" }, "content");

            // Act
            project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>());

            // Assert
            Assert.True(project.FileExists("a.txt"));
            Assert.True(project.FileExists("b.txt"));
            Assert.True(project.FileExists("c.txt"));
            Assert.True(project.FileExists("d.txt"));
            Assert.True(project.FileExists("e.txt"));
            Assert.True(project.FileExists("f.txt"));

            logger.Verify(l => l.ResolveFileConflict(It.IsAny <string>()), Times.Exactly(6));

            Assert.Equal("this is a", project.ReadAllText("a.txt"));
            Assert.Equal("content\\b.txt", project.ReadAllText("b.txt"));
            Assert.Equal("this is c", project.ReadAllText("c.txt"));
            Assert.Equal("this is d", project.ReadAllText("d.txt"));
            Assert.Equal("content\\e.txt", project.ReadAllText("e.txt"));
            Assert.Equal("content\\f.txt", project.ReadAllText("f.txt"));
        }
Пример #2
0
        public void AddFilesAddFilesToProjectSystem()
        {
            // Arrange
            var fileSystem = new MockProjectSystem();
            var files      = PackageUtility.CreateFiles(new[] { "A", "B", "C" });

            // Act
            fileSystem.AddFiles(files, String.Empty);

            // Assert
            Assert.True(fileSystem.FileExists("A"));
            Assert.True(fileSystem.FileExists("B"));
            Assert.True(fileSystem.FileExists("C"));
        }
Пример #3
0
        public void AddFilesDoNotCallResolveFileConflictIfThereIsNoFileConflict()
        {
            var logger = new Mock <ILogger>();

            // Arrange
            var project = new MockProjectSystem();

            project.AddFile("a.txt", "this is a");
            project.AddFile("c.txt", "this is c");
            project.Logger = logger.Object;

            var files = PackageUtility.CreateFiles(new[] { "b.txt", "d.txt" }, "content");

            // Act
            project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>());

            // Assert
            logger.Verify(l => l.ResolveFileConflict(It.IsAny <string>()), Times.Never());
        }
Пример #4
0
        public void AddFilesCallResolveFileConflictIfThereIsFileConflict()
        {
            var logger = new Mock <ILogger>();

            // Arrange
            var project = new MockProjectSystem(VersionUtility.ParseFrameworkName("net40"), "x:\\root");

            project.AddFile("a.txt", "this is a");
            project.AddFile("c.txt", "this is c");
            project.Logger = logger.Object;

            var files = PackageUtility.CreateFiles(new[] { "a.txt", "b.txt" }, "content");

            // Act
            project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>());

            // Assert
            logger.Verify(l => l.ResolveFileConflict("File 'a.txt' already exists in project 'x:\\root'. Do you want to overwrite it?"), Times.Once());
        }
Пример #5
0
        public void AddFilesDoNotCallResolveFileConflictIfTheConflictFileDoesNotBelongToProject()
        {
            var logger = new Mock <ILogger>();

            // Arrange
            var project = new MockProjectSystem();

            project.AddFile("a.txt", "this is a");
            project.AddFile("b.txt", "this is b");
            project.ExcludeFileFromProject("b.txt");
            project.Logger = logger.Object;

            var files = PackageUtility.CreateFiles(new[] { "b.txt", "d.txt" }, "content");

            // Act
            project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>());

            // Assert
            Assert.True(project.FileExists("d.txt"));
            Assert.False(project.FileExistsInProject("b.txt"));
            logger.Verify(l => l.ResolveFileConflict(It.IsAny <string>()), Times.Never());
        }