Esempio n. 1
0
        public void WriteConfigurationTest()
        {
            var config = new AutoConfigFileConfiguration();

            config.Initialize();

            config.MaxDisplayListItems         = 12;
            config.DebugMode                   = DebugModes.DeveloperErrorMessage;
            config.ApplicationName             = "Changed";
            config.SendAdminEmailConfirmations = true;
            config.Write();

            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Console.WriteLine(text);

            Assert.IsTrue(text.Contains(@"<add key=""DebugMode"" value=""DeveloperErrorMessage"" />"));
            Assert.IsTrue(text.Contains(@"<add key=""MaxDisplayListItems"" value=""12"" />"));
            Assert.IsTrue(text.Contains(@"<add key=""SendAdminEmailConfirmations"" value=""True"" />"));

            var config2 = new AutoConfigFileConfiguration();

            config2.Initialize();

            Assert.AreEqual(config2.MaxDisplayListItems, 12);
            Assert.AreEqual(config2.ApplicationName, "Changed");

            // reset to default val
            config2.MaxDisplayListItems = 15;
            config2.Write();
        }
Esempio n. 2
0
        public void NativePerfTest()
        {
            // Try to create instance
            var ser = new JsonSerializer();

            ser.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            ser.Converters.Add(new StringEnumConverter());

            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;

            string result = null;

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 10000; i++)
            {
                var writer = new StringWriter();
                var jtw    = new JsonTextWriter(writer);
                jtw.Formatting = Formatting.Indented;
                ser.Serialize(jtw, config);
                result = writer.ToString();
                jtw.Close();
            }

            sw.Stop();
            Console.WriteLine("Native Serialize: " + sw.ElapsedMilliseconds + "ms");
            Console.WriteLine(result);
        }
        public void JsonSerializeToFile()
        {
            var config = new AutoConfigFileConfiguration();

            bool result = JsonSerializationUtils.SerializeToFile(config, "serialized.config", true, true);
            string filetext = File.ReadAllText("serialized.config");
            Console.WriteLine(filetext);
        }
Esempio n. 4
0
        public void JsonSerializeToFile()
        {
            var config = new AutoConfigFileConfiguration();

            bool   result   = JsonSerializationUtils.SerializeToFile(config, "serialized.config", true, true);
            string filetext = File.ReadAllText("serialized.config");

            Console.WriteLine(filetext);
        }
Esempio n. 5
0
        public void JsonStringSerializeTest()
        {
            var config = new AutoConfigFileConfiguration();

            string json = JsonSerializationUtils.Serialize(config, true, true);

            Console.WriteLine(json);
            Assert.IsNotNull(json);
        }
        public void JsonStringSerializeTest()
        {
            var config = new AutoConfigFileConfiguration();

            string json = JsonSerializationUtils.Serialize(config, true, true);

            Console.WriteLine(json);
            Assert.IsNotNull(json);
        }
Esempio n. 7
0
        public void JsonStringSerializeCamelCaseTest()
        {
            var config = new AutoConfigFileConfiguration();

            string json = JsonSerializationUtils.Serialize(config, true, true, true);

            Console.WriteLine(json);
            Assert.IsNotNull(json);
            Assert.IsTrue(json.Contains("\"applicationName\": "));
        }
        public void DefaultConstructorInstanceTest()
        {         
            var config = new AutoConfigFileConfiguration();
            
            // gets .config file, AutoConfigFileConfiguration section
            config.Initialize();

            Assert.IsNotNull(config);
            Assert.IsFalse(string.IsNullOrEmpty(config.ApplicationName));
            Assert.AreEqual(config.MaxDisplayListItems, 15);

            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());
            Console.WriteLine(text);
        }
        public void DefaultConstructorInstanceTest()
        {
            var config = new AutoConfigFileConfiguration();

            // gets .config file, AutoConfigFileConfiguration section
            config.Initialize();

            Assert.IsNotNull(config);
            Assert.IsFalse(string.IsNullOrEmpty(config.ApplicationName));
            Assert.AreEqual(config.MaxDisplayListItems, 15);

            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Console.WriteLine(text);
        }
        public void JsonDeserializeStringTest()
        {
            var config = new AutoConfigFileConfiguration();
            config.ApplicationName = "New App";
            config.DebugMode = DebugModes.DeveloperErrorMessage;
            string json = JsonSerializationUtils.Serialize(config, true, true);

            config = null;

            config = JsonSerializationUtils.Deserialize(json, typeof(AutoConfigFileConfiguration), true) as AutoConfigFileConfiguration;

            Assert.IsNotNull(config);
            Assert.IsTrue(config.ApplicationName == "New App");
            Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage);
        }
Esempio n. 11
0
        public void JsonDeserializeStringTest()
        {
            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;
            string json = JsonSerializationUtils.Serialize(config, true, true);

            config = null;

            config = JsonSerializationUtils.Deserialize(json, typeof(AutoConfigFileConfiguration), true) as AutoConfigFileConfiguration;

            Assert.IsNotNull(config);
            Assert.IsTrue(config.ApplicationName == "New App");
            Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage);
        }
Esempio n. 12
0
        public void JsonNativeInstantiation()
        {
            // Try to create instance
            var ser = new JsonSerializer();

            //ser.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            //ser.ObjectCreationHandling = ObjectCreationHandling.Auto;
            //ser.MissingMemberHandling = MissingMemberHandling.Ignore;
            ser.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            ser.Converters.Add(new StringEnumConverter());

            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;

            var writer = new StringWriter();
            var jtw    = new JsonTextWriter(writer);

            jtw.Formatting = Formatting.Indented;

            ser.Serialize(jtw, config);

            string result = writer.ToString();

            jtw.Close();

            Console.WriteLine(result);

            dynamic json          = ReflectionUtils.CreateInstanceFromString("Newtonsoft.Json.JsonSerializer");
            dynamic enumConverter = ReflectionUtils.CreateInstanceFromString("Newtonsoft.Json.Converters.StringEnumConverter");

            json.Converters.Add(enumConverter);

            writer         = new StringWriter();
            jtw            = new JsonTextWriter(writer);
            jtw.Formatting = Formatting.Indented;

            json.Serialize(jtw, config);

            result = writer.ToString();
            jtw.Close();

            Console.WriteLine(result);
        }
        public void DeserializeFromFileTest()
        {
            string fname = "serialized.config";

            var config = new AutoConfigFileConfiguration();
            config.ApplicationName = "New App";
            config.DebugMode = DebugModes.DeveloperErrorMessage;
            bool result = JsonSerializationUtils.SerializeToFile(config, fname, true, true);

            Assert.IsTrue(result);

            config = null;

            config = JsonSerializationUtils.DeserializeFromFile(fname, typeof(AutoConfigFileConfiguration)) as
                AutoConfigFileConfiguration;

            Assert.IsNotNull(config);
            Assert.IsTrue(config.ApplicationName == "New App");
            Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage);
        }
        public void JsonNativeInstantiation()
        {
            // Try to create instance
            var ser = new JsonSerializer();

            //ser.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            //ser.ObjectCreationHandling = ObjectCreationHandling.Auto;
            //ser.MissingMemberHandling = MissingMemberHandling.Ignore;
            ser.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            ser.Converters.Add(new StringEnumConverter());

            var config = new AutoConfigFileConfiguration();
            config.ApplicationName = "New App";
            config.DebugMode = DebugModes.DeveloperErrorMessage;

            var writer = new StringWriter();
            var jtw = new JsonTextWriter(writer);
            jtw.Formatting = Formatting.Indented;

            ser.Serialize(jtw, config);

            string result = writer.ToString();
            jtw.Close();

            Console.WriteLine(result);

            dynamic json = ReflectionUtils.CreateInstanceFromString("Newtonsoft.Json.JsonSerializer");
            dynamic enumConverter = ReflectionUtils.CreateInstanceFromString("Newtonsoft.Json.Converters.StringEnumConverter");
            json.Converters.Add(enumConverter);

            writer = new StringWriter();
            jtw = new JsonTextWriter(writer);
            jtw.Formatting = Formatting.Indented;

            json.Serialize(jtw, config);

            result = writer.ToString();
            jtw.Close();

            Console.WriteLine(result);
        }
Esempio n. 15
0
        public void DeserializeFromFileTest()
        {
            string fname = "serialized.config";

            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;
            bool result = JsonSerializationUtils.SerializeToFile(config, fname, true, true);

            Assert.IsTrue(result);

            config = null;

            config = JsonSerializationUtils.DeserializeFromFile(fname, typeof(AutoConfigFileConfiguration)) as
                     AutoConfigFileConfiguration;

            Assert.IsNotNull(config);
            Assert.IsTrue(config.ApplicationName == "New App");
            Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage);
        }
        public void AutoConfigWriteConfigurationTest()
        {
            var config = new AutoConfigFileConfiguration();
            config.Initialize();

            Assert.IsNotNull(config);
            Assert.IsFalse(string.IsNullOrEmpty(config.ApplicationName));
            Assert.AreEqual(config.MaxDisplayListItems, 15);

            config.MaxDisplayListItems = 17;
            config.Write();

            var config2 = new AutoConfigFileConfiguration();
            config2.Initialize();

            Assert.AreEqual(config2.MaxDisplayListItems, 17);

            // reset to default val
            config2.MaxDisplayListItems = 15;
            config2.Write();
        }
Esempio n. 17
0
        public void Native2PerfTest()
        {
            var config = new AutoConfigFileConfiguration();

            config.ApplicationName = "New App";
            config.DebugMode       = DebugModes.DeveloperErrorMessage;

            string result = JsonSerializationUtils.Serialize(config, true, true);

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 10000; i++)
            {
                result = JsonSerializationUtils.Serialize(config, true, true);
            }

            sw.Stop();
            Console.WriteLine("Utils Serialize: " + sw.ElapsedMilliseconds + "ms");
            Console.WriteLine(result);
        }
        public void AutoConfigWriteConfigurationTest()
        {
            var config = new AutoConfigFileConfiguration();

            config.Initialize();

            Assert.IsNotNull(config);
            Assert.IsFalse(string.IsNullOrEmpty(config.ApplicationName));
            Assert.AreEqual(config.MaxDisplayListItems, 15);

            config.MaxDisplayListItems = 17;
            config.Write();

            var config2 = new AutoConfigFileConfiguration();

            config2.Initialize();

            Assert.AreEqual(config2.MaxDisplayListItems, 17);

            // reset to default val
            config2.MaxDisplayListItems = 15;
            config2.Write();
        }
        public void DefaultConstructorWithCustomProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider <AutoConfigFileConfiguration>()
            {
                ConfigurationSection = "CustomConfiguration",
                EncryptionKey        = "seekrit123",
                PropertiesToEncrypt  = "MailServer,MailServerPassword"
            };

            config.Initialize(provider);

            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<CustomConfiguration>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);
        }
        public void DefaultConstructorWithCustomProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider<AutoConfigFileConfiguration>()
            {
                ConfigurationSection = "CustomConfiguration",
                EncryptionKey = "seekrit123",
                PropertiesToEncrypt = "MailServer,MailServerPassword"                
            };

            config.Initialize(provider);  
            
            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<CustomConfiguration>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);
        }
        public void DefaultConstructorWithAppSettingsProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider<AutoConfigFileConfiguration>()
            {
                ConfigurationSection = null, // forces to AppSettings
                EncryptionKey = "seekrit123",
                PropertiesToEncrypt = "MailServer,MailServerPassword"
            };

            config.Initialize(provider);

            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<appSettings>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);

            config.ApplicationName = "Updated Configuration";
            config.Write();

            config = null;
            config = new AutoConfigFileConfiguration();
            config.Initialize(provider);

            config.Initialize(); // should reload, reread

            Console.WriteLine("Application Name: " + config.ApplicationName);

            Assert.IsTrue(config.ApplicationName == "Updated Configuration");

        }
        public void DefaultConstructorWithAppSettingsProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider <AutoConfigFileConfiguration>()
            {
                ConfigurationSection = null, // forces to AppSettings
                EncryptionKey        = "seekrit123",
                PropertiesToEncrypt  = "MailServer,MailServerPassword"
            };

            config.Initialize(provider);

            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<appSettings>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);

            config.ApplicationName = "Updated Configuration";
            config.Write();

            config = null;
            config = new AutoConfigFileConfiguration();
            config.Initialize(provider);

            config.Initialize(); // should reload, reread

            Console.WriteLine("Application Name: " + config.ApplicationName);

            Assert.IsTrue(config.ApplicationName == "Updated Configuration");
        }
        public void UtilsPerfTest()
        {
            var config = new AutoConfigFileConfiguration();
            config.ApplicationName = "New App";
            config.DebugMode = DebugModes.DeveloperErrorMessage;

            string result = JsonSerializationUtils.Serialize(config, true, true);
            result = JsonSerializationUtils.Serialize(config, true, true);

            var sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < 10000; i++)
            {
                result = JsonSerializationUtils.Serialize(config, true, true);
            }

            sw.Stop();
            Console.WriteLine("Utils Serialize: " + sw.ElapsedMilliseconds + "ms");
            Console.WriteLine(result);
        }
        public void NativePerfTest()
        {
            // Try to create instance
            var ser = new JsonSerializer();
            ser.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            ser.Converters.Add(new StringEnumConverter());

            var config = new AutoConfigFileConfiguration();
            config.ApplicationName = "New App";
            config.DebugMode = DebugModes.DeveloperErrorMessage;

            string result = null;

            var sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < 10000; i++)
            {
                var writer = new StringWriter();
                var jtw = new JsonTextWriter(writer);
                jtw.Formatting = Formatting.Indented;
                ser.Serialize(jtw, config);
                result = writer.ToString();
                jtw.Close();
            }

            sw.Stop();
            Console.WriteLine("Native Serialize: " + sw.ElapsedMilliseconds + "ms");
            Console.WriteLine(result);
        }
        public void WriteConfigurationTest()
        {
            var config = new AutoConfigFileConfiguration();
            config.Initialize();

            config.MaxDisplayListItems = 12;
            config.DebugMode = DebugModes.DeveloperErrorMessage;
            config.ApplicationName = "Changed";
            config.SendAdminEmailConfirmations = true;

            // update complex type
            config.License.Company = "Updated Company";
            config.License.Name = "New User";
            config.License.LicenseKey = 22;

            config.Write();

            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());
            Console.WriteLine(text);

            Assert.IsTrue(text.Contains(@"<add key=""DebugMode"" value=""DeveloperErrorMessage"" />"));
            Assert.IsTrue(text.Contains(@"<add key=""MaxDisplayListItems"" value=""12"" />"));
            Assert.IsTrue(text.Contains(@"<add key=""SendAdminEmailConfirmations"" value=""True"" />"));

            Assert.IsTrue(text.Contains(@"<add key=""License"" value=""New User,Updated Company,22"" />"));

            var config2 = new AutoConfigFileConfiguration();
            config2.Initialize();

            Assert.AreEqual(config2.MaxDisplayListItems, 12);
            Assert.AreEqual(config2.ApplicationName, "Changed");
            Assert.AreEqual("Updated Company",config2.License.Company);

            // reset to default val
            config2.MaxDisplayListItems = 15;
            config2.Write();
        }