public void Cleanup_HasMatchingFilesInDirectory_MatchingFilesAreDeleted()
        {
            var matchingFilePaths = new List <string>
            {
                "c:\\test\\pch\\myPch.abc",
                "c:\\test\\pch\\MYpch.aBC",
                "c:\\test\\pch\\myPch.abcd",
                "c:\\test\\pch\\myPch.abcd.e",
                "c:\\test\\pch\\myPch.abc.d",
                "c:\\test\\pch\\myPch.abc.d.e",
                "c:\\test\\pch\\myPch.abc.de.f",
                "c:\\test\\pch\\myPCH.ABC.d.E"
            };

            foreach (var filePath in matchingFilePaths)
            {
                fileSystemMock.AddFile(filePath, new MockFileData(""));
            }

            var testSubject = new PchCacheCleaner(fileSystemMock, "c:\\test\\pch\\myPch.abc");

            testSubject.Cleanup();

            fileSystemMock.AllFiles.Should().BeEmpty();
        }
        public void Cleanup_NoFilesInDirectory_NoException()
        {
            var testSubject = new PchCacheCleaner(fileSystemMock, "c:\\test\\pch\\myPch.abc");

            Action act = () => testSubject.Cleanup();

            act.Should().NotThrow();
        }
        public void Cleanup_HasMatchingAndNonMatchingFilesInDirectory_OnlyMatchingFilesAreDeleted()
        {
            var matchingFile    = "c:\\test\\pch\\myPch.abc.d";
            var nonMatchingFile = "c:\\test\\pch\\myPch.abd";

            fileSystemMock.AddFile(matchingFile, new MockFileData(""));
            fileSystemMock.AddFile(nonMatchingFile, new MockFileData(""));

            var testSubject = new PchCacheCleaner(fileSystemMock, "c:\\test\\pch\\myPch.abc");

            testSubject.Cleanup();

            fileSystemMock.AllFiles.Should().BeEquivalentTo(new List <string> {
                nonMatchingFile
            });
        }
        public void Cleanup_FailsToDeleteSomeFiles_DeletesTheOnesThatSucceed()
        {
            var matchingFile = "c:\\test\\pch\\myPch.abc.d";

            fileSystemMock.AddFile(matchingFile, new MockFileData(""));

            var matchingFailingFile = "c:\\test\\pch\\myPch.abc.de";
            var failingFileMockData = new MockFileData("")
            {
                AllowedFileShare = FileShare.None
            };

            fileSystemMock.AddFile(matchingFailingFile, failingFileMockData);

            var testSubject = new PchCacheCleaner(fileSystemMock, "c:\\test\\pch\\myPch.abc");

            testSubject.Cleanup();

            fileSystemMock.AllFiles.Should().BeEquivalentTo(new List <string> {
                matchingFailingFile
            });
        }
        public void Cleanup_NoMatchingFilesInDirectory_NonMatchingFilesAreNotDeleted()
        {
            var nonMatchingFilePaths = new List <string>
            {
                "c:\\test\\pch\\test.abc",
                "c:\\test\\pch\\myPch.ab",
                "c:\\test\\pch\\myPch.ab.c",
                "c:\\test\\pch\\myPch.abd",
                "c:\\test\\pch\\amyPch.abc",
                "c:\\test\\pch\\sub\\myPch.abc",
                "c:\\test\\myPch.abc"
            };

            foreach (var filePath in nonMatchingFilePaths)
            {
                fileSystemMock.AddFile(filePath, new MockFileData(""));
            }

            var testSubject = new PchCacheCleaner(fileSystemMock, "c:\\test\\pch\\myPch.abc");

            testSubject.Cleanup();

            fileSystemMock.AllFiles.Should().BeEquivalentTo(nonMatchingFilePaths);
        }