public void SanitizePropertiesTrimsLeadingAndTraliningSpacesFromValues()
        {
            const string OriginalKey = "test";
            const string OriginalValue = " name with spaces ";
            var original = new Dictionary<string, string> { { OriginalKey, OriginalValue } };

            original.SanitizeProperties();

            string sanitizedValue = OriginalValue.Trim();
            Assert.Equal(new[] { new KeyValuePair<string, string>(OriginalKey, sanitizedValue) }, original);
        }
        public void SanitizePropertiesMakesKeysUniqueAfterTruncation()
        {
            string originalKey = new string('A', Property.MaxDictionaryNameLength + 1);
            const string OriginalValue = "Test Value";
            var original = new Dictionary<string, string> 
            { 
                { originalKey + "1", OriginalValue },
                { originalKey + "2", OriginalValue },
                { originalKey + "3", OriginalValue },
            };

            original.SanitizeProperties();

            Assert.Equal(3, original.Count);
            Assert.Equal(Property.MaxDictionaryNameLength, original.Keys.Max(key => key.Length));
        }
        public void SanitizePropertiesTruncatesValuesLongerThan1024Characters()
        {
            const string OriginalKey = "test";
            string originalValue = new string('A', Property.MaxValueLength + 10);
            var original = new Dictionary<string, string> { { OriginalKey, originalValue } };

            original.SanitizeProperties();

            string sanitizedValue = originalValue.Substring(0, Property.MaxValueLength);
            Assert.Equal(new[] { new KeyValuePair<string, string>(OriginalKey, sanitizedValue) }, original);
        }
        public void SanitizePropertiesTruncatesKeysLongerThan150Characters()
        {
            string originalKey = new string('A', Property.MaxNameLength + 1);
            const string OriginalValue = "Test Value";
            var original = new Dictionary<string, string> { { originalKey, OriginalValue } };

            original.SanitizeProperties();

            Assert.Equal(Property.MaxDictionaryNameLength, original.First().Key.Length);
        }
        public void SanitizePropertiesMakesKeyUniqueAfterReplacingSpecialCharactersWithUnderscores()
        {
            string originalKey = "test#key";
            var dictionary = new Dictionary<string, string> 
            {
                { originalKey, string.Empty },
                { originalKey.Replace("#", "_"), string.Empty },
            };

            dictionary.SanitizeProperties();

            Assert.Contains("test_key001", dictionary.Keys);
        }
        public void SanitizePropertiesReplacesSpecialCharactersWithUnderscores()
        {
            foreach (char invalidCharacter in GetInvalidNameCharacters())
            {
                string originalKey = "test" + invalidCharacter + "key";
                const string OriginalValue = "Test Value";
                var original = new Dictionary<string, string> { { originalKey, OriginalValue } };

                original.SanitizeProperties();

                string sanitizedKey = originalKey.Replace(invalidCharacter, '_');
                Assert.Equal(new[] { new KeyValuePair<string, string>(sanitizedKey, OriginalValue) }, original);
            }
        }
 public void SanitizePropertiesReplacesEmptyStringWithEmptyWordToEnsurePropertyValueWillBeSerializedWithoutExceptions()
 {
     var dictionary = new Dictionary<string, string> { { string.Empty, string.Empty } };
     dictionary.SanitizeProperties();
     Assert.Equal("(required property name is empty)", dictionary.Single().Key);
 }
        public void SanitizePropertiesTrimsLeadingAndTrailingSpaceInKeyNames()
        {
            const string OriginalKey = " key with spaces ";
            const string OriginalValue = "Test Value";
            var original = new Dictionary<string, string> { { OriginalKey, OriginalValue } };

            original.SanitizeProperties();

            string sanitizedKey = OriginalKey.Trim();
            Assert.Equal(new[] { new KeyValuePair<string, string>(sanitizedKey, OriginalValue) }, original);
        }