public void ItReturnsErrorWhenCodePointIsInBoundsOfRange()
        {
            var configurationMockFactory = new Moq.Mock <IConfiguration>();
            List <Configuration.CodePointRange> whitelist = new List <Configuration.CodePointRange> {
                new Configuration.CodePointRange {
                    Start = 0x00,
                    End   = 0x77  // x - 1
                },
                new Configuration.CodePointRange {
                    Start = 0x7B, // z + 1
                    End   = 0x10FFFF
                },
            };

            configurationMockFactory.Setup(configuration => configuration.WhitelistOfCodePointRanges()).Returns(whitelist);
            configurationMockFactory.Setup(configuration => configuration.BlacklistOfCodePoints()).Returns(new List <int>());
            FilenamesCharactersValidation validation = new FilenamesCharactersValidation(configurationMockFactory.Object);

            var fileInfoMockFactory = new Moq.Mock <IFileInfo>();

            fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns("AAAxAAAzAAA");
            IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);

            Assert.StrictEqual <Result>(Result.Fail, validationResult.Result);
            Assert.True(validationResult.Positions.Count == 2, $"Unexpected number of error positions");
            Assert.True(validationResult.Positions[0] == 4, $"Unexpected position of first error");
            Assert.True(validationResult.Positions[1] == 8, $"Unexpected position of second error");
        }
        public void TestWithRealConfigReturnsSuccessForValidSurrogateCodePoint()
        {
            FilenamesCharactersValidation validation = new FilenamesCharactersValidation(this._configuration);

            var fileInfoMockFactory = new Moq.Mock <IFileInfo>();

            fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns(new string(new char[] { 'a', (char)0xD834, (char)0xDD1E, 'z' }));
            IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);

            Assert.StrictEqual <Result>(Result.Success, validationResult.Result);
        }
        public void ItReturnsErrorOnFileWithInvalidCodePoint()
        {
            var        configurationMockFactory = new Moq.Mock <IConfiguration>();
            List <int> codePointBlacklist       = new List <int>
            {
                0x7A
            };

            configurationMockFactory.Setup(configuration => configuration.BlacklistOfCodePoints()).Returns(codePointBlacklist);
            configurationMockFactory.Setup(configuration => configuration.WhitelistOfCodePointRanges()).Returns(this._configuration.WhitelistOfCodePointRanges);
            FilenamesCharactersValidation validation = new FilenamesCharactersValidation(configurationMockFactory.Object);

            var fileInfoMockFactory = new Moq.Mock <IFileInfo>();

            fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns("AAAzAAA");

            IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);

            Assert.StrictEqual <Result>(Result.Fail, validationResult.Result);
        }
        public void TestWithRealConfigReturnsErrorForInvalidCodePoint()
        {
            FilenamesCharactersValidation validation = new FilenamesCharactersValidation(this._configuration);

            var fileInfoMockFactory = new Moq.Mock <IFileInfo>();

            fileInfoMockFactory.SetupGet(fileInfo => fileInfo.Name).Returns(new string(new char[] {
                'a',
                (char)0xD834, (char)0xDD1E, // valid surrogate pair
                (char)0xFFF0,               // invalid codepoint
                'z',
                (char)0x007C                // blacklisted codepoint
            }));
            IValidationResult validationResult = validation.Validate(fileInfoMockFactory.Object);

            Assert.StrictEqual <Result>(Result.Fail, validationResult.Result);
            Assert.True(validationResult.Positions.Count == 2, $"Unexpected number of error positions");
            Assert.True(validationResult.Positions[0] == 3, $"Unexpected position of first error");
            Assert.True(validationResult.Positions[1] == 5, $"Unexpected position of second error");
        }