public void CorrectlyEncodesAndDecodesInput()
        {
            const string decodedInput = "This is a substitution cipher";
            const string encodedInput = "Guvf vf n fhofgvghgvba pvcure";

            var attributes = new List<FilterAttributeEntry> { new FilterAttributeEntry("rot13") };
            var filter = new SubstitutionCipherFilter("cipher-filter", attributes);
            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + ".rot13";
            using (var repo = new Repository(repoPath))
            {
                CreateConfigurationWithDummyUser(repo, Constants.Identity);
                CreateAttributesFile(repo, "*.rot13 filter=rot13");

                var blob = CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
                var textDetected = blob.GetContentText();

                Assert.Equal(encodedInput, textDetected);
                Assert.Equal(1, filter.CleanCalledCount);
                Assert.Equal(0, filter.SmudgeCalledCount);

                var branch = repo.CreateBranch("delete-files");
                Commands.Checkout(repo, branch.FriendlyName);

                DeleteFile(repo, fileName);

                Commands.Checkout(repo, "master");

                var fileContents = ReadTextFromFile(repo, fileName);
                Assert.Equal(1, filter.SmudgeCalledCount);
                Assert.Equal(decodedInput, fileContents);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }
        public void CleanIsCalledIfAttributeEntryMatches(string filterAttribute, string attributeEntry, int cleanCount)
        {
            const string decodedInput = "This is a substitution cipher";

            var filterForAttributes = new List<FilterAttributeEntry> { new FilterAttributeEntry(filterAttribute) };
            var filter = new SubstitutionCipherFilter("cipher-filter", filterForAttributes);

            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + ".txt";

            using (var repo = new Repository(repoPath))
            {
                CreateConfigurationWithDummyUser(repo, Constants.Identity);
                CreateAttributesFile(repo, attributeEntry);

                CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

                Assert.Equal(cleanCount, filter.CleanCalledCount);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }
        public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string attributeEntry, int smudgeCount)
        {
            const string decodedInput = "This is a substitution cipher";

            var filterForAttributes = new List<FilterAttributeEntry> { new FilterAttributeEntry(filterAttribute) };
            var filter = new SubstitutionCipherFilter("cipher-filter", filterForAttributes);

            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + ".txt";

            using (var repo = new Repository(repoPath))
            {
                CreateConfigurationWithDummyUser(repo, Constants.Identity);
                CreateAttributesFile(repo, attributeEntry);

                CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

                var branch = repo.CreateBranch("delete-files");
                Commands.Checkout(repo, branch.FriendlyName);

                DeleteFile(repo, fileName);

                Commands.Checkout(repo, "master");

                Assert.Equal(smudgeCount, filter.SmudgeCalledCount);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }
        public void WhenStagedFileDoesNotMatchPathSpecFileIsNotFiltered(string pathSpec, string fileExtension, int cleanCount, int smudgeCount)
        {
            const string filterName = "rot13";
            const string decodedInput = "This is a substitution cipher";
            string attributeFileEntry = string.Format("{0} filter={1}", pathSpec, filterName);

            var filterForAttributes = new List<FilterAttributeEntry> { new FilterAttributeEntry(filterName) };
            var filter = new SubstitutionCipherFilter("cipher-filter", filterForAttributes);

            var filterRegistration = GlobalSettings.RegisterFilter(filter);

            string repoPath = InitNewRepository();
            string fileName = Guid.NewGuid() + fileExtension;

            using (var repo = new Repository(repoPath))
            {
                CreateConfigurationWithDummyUser(repo, Constants.Identity);
                CreateAttributesFile(repo, attributeFileEntry);

                CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

                Assert.Equal(cleanCount, filter.CleanCalledCount);
                Assert.Equal(smudgeCount, filter.SmudgeCalledCount);
            }

            GlobalSettings.DeregisterFilter(filterRegistration);
        }