Exemple #1
0
        public void Add(string key, object value)
        {
            if (value == null)
            {
                return;
            }

            if (value is string stringValue)
            {
                StringProperties.Add(key, stringValue);
            }
            else if (value is byte[] binaryValue)
            {
                BinaryProperties.Add(key, binaryValue);
            }
            else if (value is bool boolValue)
            {
                BooleanProperties.Add(key, boolValue);
            }
            else if (value is DateTimeOffset dateTimeOffsetValue)
            {
                DateTimeProperties.Add(key, dateTimeOffsetValue);
            }
            else if (value is DateTime dateTimeValue)
            {
                DateTimeProperties.Add(key, dateTimeValue);
            }
            else
            {
                IntegerProperties.Add(key, Convert.ToInt64(value));
            }
        }
Exemple #2
0
        private static void InitConfig()
        {
            // create a non-dynamic K/V (string/string) configuration source
            PropertiesFileConfigurationSourceConfig sourceConfig = StringPropertySources
                                                                   .NewPropertiesFileSourceConfigBuilder().SetName("app-properties-file").SetFileName("app.properties")
                                                                   .Build();
            IConfigurationSource source = StringPropertySources.NewPropertiesFileSource(sourceConfig);

            // create a configuration manager with single source
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("little-app")
                                                       .AddSource(1, source).Build();
            IConfigurationManager manager = ConfigurationManagers.NewManager(managerConfig);

            // create a StringProperties facade tool
            _properties = new StringProperties(manager);

            // default to null
            _appId = _properties.GetStringProperty("app.id");

            // default to "unknown"
            _appName = _properties.GetStringProperty("app.name", "unknown");

            // default to empty list
            _userList = _properties.GetListProperty("user.list", new List <string>());

            // default to empty map
            _userData = _properties.GetDictionaryProperty("user.data", new Dictionary <string, string>());

            // default to 1000, if value in app._properties is invalid, ignore the invalid value
            _sleepTime = _properties.GetIntProperty("sleep.time", 1000, v => v < 0 ? null : v);

            // custom type property
            _myCustomData = _properties.GetProperty("my-custom-type-property", MyCustomType.Converter);
        }
        public virtual void TestDemo()
        {
            // create an apollo config
            IConfig appConfig = ApolloConfigurationManager.GetAppConfig().Result;

            // create a scf apollo configuration source
            ApolloConfigurationSourceConfig sourceConfig = new ApolloConfigurationSourceConfig.Builder()
                                                           .SetName("apollo-source").SetApolloConfig(appConfig).Build();
            ApolloConfigurationSource source = new ApolloConfigurationSource(sourceConfig);

            // create scf manager & properties facade tool
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("my-app")
                                                       .AddSource(1, source).Build();
            IConfigurationManager manager    = ConfigurationManagers.NewManager(managerConfig);
            StringProperties      properties = new StringProperties(manager);

            // use properties
            IProperty <string, string> appName = properties.GetStringProperty("app.name", "unknown");

            Console.WriteLine("app name: " + appName.Value);

            // add listener for dynamic property
            IProperty <string, int?> requestTimeout = properties.GetIntProperty("request.timeout", 1000);

            Console.WriteLine("request timeout: " + requestTimeout.Value);
            requestTimeout.OnChange += (o, e) => Console.WriteLine("do something");
        }
        public StringState(StringProperties properties, char terminator, char openingParenthesis, int nestingLevel)
        {
            Debug.Assert(!Tokenizer.IsLetterOrDigit(terminator));

            _properties         = properties;
            _terminator         = terminator;
            _openingParenthesis = openingParenthesis;
            _nestingLevel       = nestingLevel;
        }
 internal HeredocState(StringProperties properties, string /*!*/ label, int resumePosition, char[] resumeLine, int resumeLineLength, int firstLine, int firstLineIndex)
     : base(properties, label)
 {
     _resumePosition   = resumePosition;
     _resumeLine       = resumeLine;
     _resumeLineLength = resumeLineLength;
     _firstLine        = firstLine;
     _firstLineIndex   = firstLineIndex;
 }
Exemple #6
0
        public void GeneratePureRandomStrings()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;
            string s1 = StringFactory.GenerateRandomString(properties, 1234);

            Assert.NotNull(s1);
        }
Exemple #7
0
 public void Clear()
 {
     Id      = string.Empty;
     Name    = string.Empty;
     SetCode = string.Empty;
     StringProperties.Clear();
     IntMinProperties.Clear();
     IntMaxProperties.Clear();
     BoolProperties.Clear();
     EnumProperties.Clear();
 }
Exemple #8
0
 /// <summary>
 /// Sets a string property. If value is null, the string property is deleted.
 /// </summary>
 public void SetStrPropValue(int tpt, string bstrVal)
 {
     if (bstrVal == null)
     {
         StringProperties.Remove(tpt);
     }
     else
     {
         StringProperties[tpt] = bstrVal.Length == 0 ? null : bstrVal;
     }
 }
        static SortedList<DateTime, string> BuildEntriesList(int seed, ICollection<int> offsets)
        {
            var sp = new StringProperties { MinNumberOfCodePoints = 0, MaxNumberOfCodePoints = 1000 };

            var iterations = new SortedList<DateTime, string>(offsets.Count);
            foreach (var offset in offsets)
            {
                iterations.Add(GetDateByOffset(offset), StringFactory.GenerateRandomString(sp, seed++));
            }

            return iterations;
        }
Exemple #10
0
        public void GenerateRandomBidiStringsWithCodePointsFromLatinAndHebrewOnly()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 20;

            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.Arabic));
            properties.UnicodeRanges.Clear();

            properties.UnicodeRanges.Add(new UnicodeRange(0x0030, 0x007A));
            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.Hebrew));
            properties.IsBidirectional = true;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isInTheRange = false;

            foreach (char c in s1)
            {
                if ((Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x007A) ||
                    (Convert.ToInt32(c) >= 0x0590 && Convert.ToInt32(c) <= 0x05FF))
                {
                    isInTheRange = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 20);
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure Latin code point is in the string
                if (Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x007A)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure Hebrew code point is in the string
                if (Convert.ToInt32(c) >= 0x0590 && Convert.ToInt32(c) <= 0x05FF)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);
        }
Exemple #11
0
        public void VerifyStringLength()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 20;
            properties.MaxNumberOfCodePoints = 30;
            string s1 = StringFactory.GenerateRandomString(properties, 1234);

            properties.MinNumberOfCodePoints = properties.MaxNumberOfCodePoints = 5;
            string s2 = StringFactory.GenerateRandomString(properties, 1234);

            Assert.True(s1.Length >= 20 && s1.Length <= 60);
            Assert.True(s2.Length >= 5 && s2.Length <= 10);
        }
        static SortedList <DateTime, string> BuildEntriesList(int seed, ICollection <int> offsets)
        {
            var sp = new StringProperties {
                MinNumberOfCodePoints = 0, MaxNumberOfCodePoints = 1000
            };

            var iterations = new SortedList <DateTime, string>(offsets.Count);

            foreach (var offset in offsets)
            {
                iterations.Add(GetDateByOffset(offset), StringFactory.GenerateRandomString(sp, seed++));
            }

            return(iterations);
        }
Exemple #13
0
        public void GenerateRandomString()
        {
            StringProperties sp = new StringProperties();

            Assert.Throws <NotImplementedException>(
                delegate
            {
                string s1 = StringFactory.GenerateRandomString(sp, 75);
                string s2 = StringFactory.GenerateRandomString(sp, 75);

                Assert.NotNull(s1);
                Assert.NotNull(s2);
                Assert.Equal <string>(s1, s2);
            });
        }
Exemple #14
0
        public void GenerateRandomNormalizedString()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0x1FFFF);
            properties.NormalizationForm     = NormalizationForm.FormC;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isFormC = s1.IsNormalized(NormalizationForm.FormC);

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 60);
            Assert.True(isFormC);
        }
Exemple #15
0
        public void AllPropertiesAreNullUponObjectInstantiation()
        {
            StringProperties sp = new StringProperties();

            Assert.True(sp.UnicodeRange == null);
            Assert.Equal <int?>(null, sp.MinNumberOfCombiningMarks);
            Assert.Equal <bool?>(null, sp.HasNumbers);
            Assert.Equal <bool?>(null, sp.IsBidirectional);
            Assert.Equal <NormalizationForm?>(null, sp.NormalizationForm);
            Assert.Equal <int?>(null, sp.MinNumberOfCodePoints);
            Assert.Equal <int?>(null, sp.MaxNumberOfCodePoints);
            Assert.Equal <int?>(null, sp.MinNumberOfEndUserDefinedCodePoints);
            Assert.Equal <int?>(null, sp.MinNumberOfLineBreaks);
            Assert.Equal <int?>(null, sp.MinNumberOfSurrogatePairs);
            Assert.Equal <int?>(null, sp.MinNumberOfTextSegmentationCodePoints);
        }
Exemple #16
0
        public void GenerateRandomStringsWithCodePointsFromTaiLeAndNewTaiLueOnly()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 20;
            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.TaiLe));
            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.NewTaiLue));
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isInTheRange = false;

            foreach (char c in s1)
            {
                if ((Convert.ToInt32(c) >= 0x1950 && Convert.ToInt32(c) <= 0x19DF))
                {
                    isInTheRange = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 20);
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure Tai Le code point is in the string
                if (Convert.ToInt32(c) >= 0x1950 && Convert.ToInt32(c) <= 0x197F)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure New Tai Lue code point is in the string
                if (Convert.ToInt32(c) >= 0x1980 && Convert.ToInt32(c) <= 0x19DF)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);
        }
Exemple #17
0
        public bool TryGetProperty <T>(string key, out T value)
        {
            if (IntegerProperties.TryGetValue(key, out var val))
            {
                value = (T)Convert.ChangeType(val, typeof(T));
                return(true);
            }

            if (StringProperties.TryGetValue(key, out var stringVal))
            {
                value = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(stringVal);
                return(true);
            }

            value = default;
            return(false);
        }
        public void TestConvertHtmlMessageToPlainTextBasic()
        {
            var properties = new StringProperties();
            properties.MinNumberOfCodePoints = 20;
            RandomDataHelper.Ranges.ForEach(properties.UnicodeRanges.Add);
            properties.UnicodeRanges.Remove(new UnicodeRange('<', '<'));
            properties.UnicodeRanges.Remove(new UnicodeRange('>', '>'));

            // Can't have '<' or '>' chars in the content, since it breaks the HTML processing. This is OK, since real HTML should never have these
            // chracters either (they will be escaped as &lt; and &gt;)
            var expectedText = 
                StringFactory.GenerateRandomString(properties, _rand.Next()).Trim().Replace("<", "").Replace(">", "");
            var htmlText = string.Format("<html><head></head><body><p>{0}</p></body></html>", expectedText);
            var plainText = EmailBodyProcessingUtils.ConvertHtmlMessageToPlainText(htmlText);

            Assert.AreEqual(plainText, expectedText);
        }
Exemple #19
0
        public void VerifySameSeedGeneratesSameString()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;

            string s1 = StringFactory.GenerateRandomString(properties, 1234);
            string s2 = StringFactory.GenerateRandomString(properties, 1234);
            string s3 = StringFactory.GenerateRandomString(properties, 4321);

            Assert.NotNull(s1);
            Assert.NotNull(s2);
            Assert.NotNull(s2);

            Assert.Equal <string>(s1, s2);
            Assert.NotEqual <string>(s1, s3);
        }
Exemple #20
0
 public void HookName()
 {
     if (Info.PropertyType.IsArray)
     {
         foreach (var item in _ExposeProperties.Controls)
         {
             if (item is Skill.Editor.UI.TextField)
             {
                 StringProperties sp = item.UserData as StringProperties;
                 if (sp != null && sp.Info.Name.Equals("Name", StringComparison.OrdinalIgnoreCase))
                 {
                     UpdateName(sp.Control);
                     ((Skill.Editor.UI.TextField)item).TextChanged += SerializableObjectProperties_TextChanged;
                 }
             }
         }
     }
 }
Exemple #21
0
        public void TestConvertHtmlMessageToPlainTextBasic()
        {
            var properties = new StringProperties();

            properties.MinNumberOfCodePoints = 20;
            RandomDataHelper.Ranges.ForEach(properties.UnicodeRanges.Add);
            properties.UnicodeRanges.Remove(new UnicodeRange('<', '<'));
            properties.UnicodeRanges.Remove(new UnicodeRange('>', '>'));

            // Can't have '<' or '>' chars in the content, since it breaks the HTML processing. This is OK, since real HTML should never have these
            // chracters either (they will be escaped as &lt; and &gt;)
            var expectedText =
                StringFactory.GenerateRandomString(properties, _rand.Next()).Trim().Replace("<", "").Replace(">", "");
            var htmlText  = string.Format("<html><head></head><body><p>{0}</p></body></html>", expectedText);
            var plainText = EmailBodyProcessingUtils.ConvertHtmlMessageToPlainText(htmlText);

            Assert.AreEqual(plainText, expectedText);
        }
Exemple #22
0
        private static void InitConfig()
        {
            // create a non-dynamic K/V (string/string) configuration source
            PropertiesFileConfigurationSourceConfig sourceConfig = StringPropertySources
                                                                   .NewPropertiesFileSourceConfigBuilder().SetName("app-properties-file").SetFileName("app.properties")
                                                                   .Build();
            IConfigurationSource source = StringPropertySources.NewPropertiesFileSource(sourceConfig);

            // crate a dynamic K/V (string/string) configuration source
            _systemPropertiesSource = StringPropertySources.NewMemoryDictionarySource("system-property");

            // create a configuration manager with 2 sources, system property has higher priority then app.properties
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("little-app")
                                                       .AddSource(1, source).AddSource(2, _systemPropertiesSource).Build();
            IConfigurationManager manager = ConfigurationManagers.NewManager(managerConfig);

            // Add a log listener
            manager.OnChange += (o, e) =>
                                Console.WriteLine("\nproperty {0} changed, old value: {1}, new value: {2}, changeTime: {3}",
                                                  e.Property, e.OldValue, e.NewValue, e.ChangeTime);

            // create a StringProperties facade tool
            _properties = new StringProperties(manager);

            // default to null
            _appId = _properties.GetStringProperty("app.id");

            // default to "unknown"
            _appName = _properties.GetStringProperty("app.name", "unknown");
            // Add change listener to app.name
            _appName.OnChange += (o, e) => Console.WriteLine("\napp.name changed, maybe we need do something");

            // default to empty list
            _userList = _properties.GetListProperty("user.list", new List <string>());

            // default to empty map
            _userData = _properties.GetDictionaryProperty("user.data", new Dictionary <string, string>());

            // default to 1000, if value in app._properties is invalid, ignore the invalid value
            _sleepTime = _properties.GetIntProperty("sleep.time", 1000, v => v < 0 ? null : v);

            // custom type property
            _myCustomData = _properties.GetProperty("my-custom-type-property", MyCustomType.Converter);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the String below to analyse ");
            string inp      = Console.ReadLine();
            string buildUrl = string.Format("http://localhost:40631/AnalyseString.svc/Analyse?value={0}", inp);

            HttpWebRequest request        = (HttpWebRequest)WebRequest.Create(buildUrl);
            WebResponse    response       = request.GetResponse();
            Stream         responseStream = response.GetResponseStream();

            StreamReader     reader = new StreamReader(responseStream);
            String           output = (reader.ReadToEnd());
            StringProperties str    = JsonConvert.DeserializeObject <StringProperties>(output);

            Console.WriteLine("Digits : {0}", str.digit_count);
            Console.WriteLine("Uppercase Letters : {0}", str.uppercase_count);
            Console.WriteLine("Lowercase Letters : {0}", str.lowercase_count);
            Console.ReadKey();
        }
Exemple #24
0
        public LargeApp()
        {
            // OwnManagerComponent both users config and defines how to config properties itself
            _ownManagerComponent = new OwnManagerComponent();

            // OuterManagerComponent only uses config, let the component's user to define how to config
            // each user can define different config way
            PropertiesFileConfigurationSourceConfig sourceConfig = StringPropertySources
                                                                   .NewPropertiesFileSourceConfigBuilder().SetName("properties-file")
                                                                   .SetFileName("outer-component.properties").Build();
            IConfigurationSource       source        = StringPropertySources.NewPropertiesFileSource(sourceConfig);
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("outer-component")
                                                       .AddSource(1, source).Build();
            IConfigurationManager manager = ConfigurationManagers.NewManager(managerConfig);

            _outerManagerComponent = new OuterManagerComponent(manager);

            // LabeledPropertyComponent only uses config, let the component's user to define how to config
            // each user can define different config way
            YamlFileConfigurationSourceConfig labeledSourceConfig = new YamlFileConfigurationSourceConfig.Builder()
                                                                    .SetName("yaml-file").SetFileName("labeled-property-component.yaml").Build();
            IConfigurationSource         labeledSource        = new YamlDcConfigurationSource(labeledSourceConfig);
            DynamicDcConfigurationSource dynamicLabeledSource = new DynamicDcConfigurationSource(
                ConfigurationSources.NewConfig("dynamic-labeled-source"));
            ConfigurationManagerConfig managerConfig2 = ConfigurationManagers.NewConfigBuilder()
                                                        .SetName("labeled-property-component").AddSource(1, labeledSource).AddSource(2, dynamicLabeledSource)
                                                        .Build();
            ILabeledConfigurationManager manager2 = LabeledConfigurationManagers.NewManager(managerConfig2);

            _labeledPropertyComponent = new LabeledPropertyComponent(manager2);

            // large app's config
            PropertiesFileConfigurationSourceConfig sourceConfig2 = StringPropertySources
                                                                    .NewPropertiesFileSourceConfigBuilder().SetName("properties-file").SetFileName("app.properties")
                                                                    .Build();
            IConfigurationSource       source2        = StringPropertySources.NewPropertiesFileSource(sourceConfig2);
            ConfigurationManagerConfig managerConfig3 = ConfigurationManagers.NewConfigBuilder().SetName("outer-component")
                                                        .AddSource(1, source2).Build();
            IConfigurationManager manager3 = ConfigurationManagers.NewManager(managerConfig3);

            _appProperties = new StringProperties(manager3);
        }
Exemple #25
0
        private void InitConfig()
        {
            // create a non-dynamic K/V (String/String) configuration source
            PropertiesFileConfigurationSourceConfig sourceConfig = StringPropertySources
                                                                   .NewPropertiesFileSourceConfigBuilder().SetName("properties-file")
                                                                   .SetFileName("own-component.properties").Build();
            IConfigurationSource source1 = StringPropertySources.NewPropertiesFileSource(sourceConfig);

            // create other dynamic or non-dynamic sources
            // ...

            // create a configuration manager with single source
            ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("own-component")
                                                       .AddSource(1, source1)
                                                       // Add other sources
                                                       .Build();
            IConfigurationManager manager = ConfigurationManagers.NewManager(managerConfig);

            // create a StringProperties facade tool
            _properties = new StringProperties(manager);
        }
Exemple #26
0
        /// <summary>
        /// Set a string property. If value is null and the length is 0, the string property is deleted.
        /// </summary>
        public void SetStrPropValueRgch(int tpt, byte[] rgchVal, int nValLength)
        {
            if (rgchVal == null && nValLength == 0)
            {
                StringProperties.Remove(tpt);
            }
            else
            {
                if (rgchVal == null)
                {
                    throw new ArgumentNullException("rgchVal");
                }

                var sb = new StringBuilder();
                for (int i = 0; i < nValLength; i += 2)
                {
                    sb.Append((char)(rgchVal[i + 1] << 8 | rgchVal[i]));
                }
                StringProperties[tpt] = sb.Length == 0 ? null : sb.ToString();
            }
        }
Exemple #27
0
        public void AllPropertiesAreNullUponObjectInstantiation()
        {
            StringProperties sp = new StringProperties();

            Assert.Equal <CultureInfo>(null, sp.CultureInfo);
            Assert.Equal <bool?>(null, sp.HasCombiningMarks);
            Assert.Equal <bool?>(null, sp.HasNumbers);
            Assert.Equal <bool?>(null, sp.IsBidirectional);
            Assert.Equal <NormalizationForm?>(null, sp.NormalizationForm);
            Assert.Equal <int?>(null, sp.MinNumberOfCharacters);
            Assert.Equal <int?>(null, sp.MaxNumberOfCharacters);
            Assert.Equal <int?>(null, sp.MinNumberOfEndUserDefinedCharacters);
            Assert.Equal <int?>(null, sp.MaxNumberOfEndUserDefinedCharacters);
            Assert.Equal <int?>(null, sp.MinNumberOfLineBreaks);
            Assert.Equal <int?>(null, sp.MaxNumberOfLineBreaks);
            Assert.Equal <int?>(null, sp.StartOfUnicodeRange);
            Assert.Equal <int?>(null, sp.EndOfUnicodeRange);
            Assert.Equal <int?>(null, sp.MinNumberOfSurrogatePairs);
            Assert.Equal <int?>(null, sp.MaxNumberOfSurrogatePairs);
            Assert.Equal <int?>(null, sp.MinNumberOfTextSegmentationCharacters);
            Assert.Equal <int?>(null, sp.MaxNumberOfTextSegmentationCharacters);
        }
Exemple #28
0
        public override object GetData(DeterministicRandom random)
        {
            if (instance == null)
            {
                lock (lockObject)
                {
                    if (instance == null)
                    {
                        instance = new CLRDataItem();
                        StringProperties strProperties = new StringProperties();
                        strProperties.MinNumberOfCodePoints = 0;
                        strProperties.MaxNumberOfCodePoints = 200;
// Fixed build break + notified Microsoft.  Turns out to not be a 3.5/4.0 issue but rather a plain old build break.
//                        strProperties.UnicodeRange = new UnicodeRange(0x0000, 0xffff);
                        string stringValue = StringFactory.GenerateRandomString(strProperties, random.Next());
                        instance.ModifyData(stringValue, random.Next(10), random.NextBool(), random.NextDouble(), (float)random.NextDouble());
                    }
                }
            }

            return(instance);
        }
Exemple #29
0
        public void GenerateRandomStringsWithProvidedChartOfArabicSupplement()
        {
            StringProperties properties1 = new StringProperties();

            properties1.MinNumberOfCodePoints = 5;
            properties1.MaxNumberOfCodePoints = 10;
            properties1.UnicodeRange          = new UnicodeRange(UnicodeChart.ArabicSupplement);
            string s1 = StringFactory.GenerateRandomString(properties1, 1234);

            bool isInTheRange = true;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) < 0x0750 || Convert.ToInt32(c) > 0x077F)
                {
                    isInTheRange = false;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 5 && s1.Length <= 20);
            Assert.True(isInTheRange);
        }
        public virtual void TestDynamicProperty2()
        {
            MemoryDictionaryConfigurationSource source = CreateSource();
            IConfigurationManager manager          = CreateManager(source);
            StringProperties      stringProperties = new StringProperties(manager);
            IProperty <string, Dictionary <String, String> > property =
                stringProperties.GetDictionaryProperty("map-value");

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            Dictionary <string, string> mapValue = new Dictionary <string, string>()
            {
                { "k1", "v1" },
                { "k2", "v2" }
            };

            source.SetPropertyValue("map-value", "k1:v1,k2:v2");
            Thread.Sleep(10);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal(mapValue, property.Value);
            Assert.NotSame(mapValue, property.Value);

            mapValue = property.Value;

            source.SetPropertyValue("map-value", "k1:v1,k2:v2");
            Thread.Sleep(10);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal(mapValue, property.Value);
            Assert.Same(mapValue, property.Value);

            source.SetPropertyValue("map-value", "k3:v3,k4:v4");
            Thread.Sleep(10);
            Console.WriteLine("property: " + property + "\n");
            Assert.NotEqual(mapValue, property.Value);
            Assert.NotSame(mapValue, property.Value);
        }
Exemple #31
0
        /// <summary>
        /// This should be called after any postback and/or before any save.  due to how we can delete mid-row
        /// in the UI, properties are only soft-deleted and need to be physically removed here.
        /// </summary>
        public void CleanDeletedAndEmptyProperties()
        {
            StringProperties?.RemoveAll(x => x == null || x.Deleted || x.Value == null);
            IntProperties?.RemoveAll(x => x == null || x.Deleted || x.Value == null);
            Int64Properties?.RemoveAll(x => x == null || x.Deleted || x.Value == null);
            DoubleProperties?.RemoveAll(x => x == null || x.Deleted || x.Value == null);
            BoolProperties?.RemoveAll(x => x == null || x.Deleted);
            DidProperties?.RemoveAll(x => x == null || x.Deleted || x.Value == null);
            IidProperties?.RemoveAll(x => x == null || x.Deleted || x.Value == null);
            Spells?.RemoveAll(x => x == null || x.Deleted);
            BookProperties?.RemoveAll(x => x == null || x.Deleted);
            Positions?.RemoveAll(x => x == null || x.Deleted);
            EmoteTable.ForEach(es => es.Emotes.RemoveAll(x => x == null || x.Deleted));
            EmoteTable?.RemoveAll(x => x == null || x.Deleted);
            BodyParts?.RemoveAll(x => x == null || x.Deleted);
            GeneratorTable?.RemoveAll(x => x == null || x.Deleted);
            CreateList?.RemoveAll(x => x == null || x.Deleted);
            Skills.RemoveAll(x => x == null || x.Deleted);

            if (!HasAbilities)
            {
                Abilities = null;
            }
        }
Exemple #32
0
        public void GenerateRandomStringsWithEndUserDefinedCharactersAndHasNumber()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 40;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0xFFFF);
            properties.MinNumberOfEndUserDefinedCodePoints = 6;
            properties.HasNumbers = true;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool hasNumbers = false;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x0039)
                {
                    hasNumbers = true;
                }
            }
            Assert.True(hasNumbers);

            int numOfEUDCs = 0;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0xE000 && Convert.ToInt32(c) <= 0xF8FF)
                {
                    numOfEUDCs++;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 40);
            Assert.True(numOfEUDCs >= 6);
        }