Example #1
0
        public void Config_persistence()
        {
            // arrange
            var cfg = new MyTestConfig()
            {
                MyNumbericValue = 333,
                MyStringValue   = "abcde",
                NestedConfig    = new MyNestedTestConfig()
                {
                    NestedValue = "nested abcde"
                }
            };

            // act
            cfg.Save(_testFilePathName);

            // assert
            Assert.IsTrue(File.Exists(_testFilePathName));

            var loadedCfg = Config.Load <MyTestConfig>(_testFilePathName);

            Assert.AreEqual(cfg.MyStringValue, loadedCfg.MyStringValue);
            Assert.AreEqual(cfg.MyNumbericValue, loadedCfg.MyNumbericValue);
            Assert.AreEqual(cfg.NestedConfig.NestedValue, loadedCfg.NestedConfig.NestedValue);
        }
Example #2
0
        public void After_load_the_config_knows_its_path()
        {
            // arrange
            var cfg = new MyTestConfig();

            cfg.Save(_testFilePathName);

            // act
            var loadedCfg = Config.Load <MyTestConfig>(_testFilePathName);

            // assert
            Assert.AreEqual(_testFilePathName, loadedCfg.FilePathName);
        }
Example #3
0
        public void Save_on_new_config_without_filename_should_throw()
        {
            // arrange
            var cfg = new MyTestConfig();

            // act
            var result = Assert.Throws <Exception>(() =>
            {
                cfg.Save();
            });

            // assert
        }
Example #4
0
        public void After_load_can_save_with_implicit_filepathname()
        {
            // arrange
            var cfg = new MyTestConfig();

            cfg.Save(_testFilePathName);
            var loadedCfg = Config.Load <MyTestConfig>(_testFilePathName);

            // act
            loadedCfg.Save();

            // assert
            Assert.Pass();
        }