public void ShouldGetAnObjectEvenIfNoSettingsAreFound()
		{
			var reader = new SimpleSettingsReader(new TestSettingsProvider(new Dictionary<string, string>()));
			var settings = reader.Read(typeof(MySettings));
			Assert.NotNull(settings);
			Assert.IsType<MySettings>(settings);
		}
 public void ShouldGetAnCollectionEvenIfNoSettingsAreFound()
 {
     var reader = new SimpleSettingsReader(new NameValueCollection());
     object settings = reader.Read();
     Assert.IsNotNull(settings, "Didn't get a settings object at all");
     Assert.IsNotNull(settings as NameValueCollection, "Didn't get a settings object of the correct type");
 }
        public void ShouldGetAnObjectEvenIfNoSettingsAreFound()
        {
            var reader = new SimpleSettingsReader(new NameValueCollection());
            var settings = reader.Read(typeof(MySettings));
            Assert.NotNull(settings);
	        Assert.IsType<MySettings>(settings);
        }
		public void CanLoadValuesFromFileSpecifiedAsXml()
		{
			var reader = new SimpleSettingsReader("MultipleEntriesXml", SettingFileType.Xml);

			var testSettings = reader.Read<FirstSettings>();

			Assert.NotNull(testSettings);
		}
		public void WillLoadConfigurationValuesFromAutodetectedXmlFile()
		{
			var reader = new SimpleSettingsReader("MultipleEntries.xml");

			var testSettings = reader.Read<FirstSettings>();

			Assert.Equal("etc", testSettings.Value);
		}
        public void UnconvertableSettingResultsInFormatException()
        {
            var settingsSource = new NameValueCollection();
            settingsSource["Smtp:Port"] = "abcdef";
            var reader = new SimpleSettingsReader(settingsSource);
            
			Assert.Throws<FormatException>(() => reader.Read<SmtpSettings>());
        }
		public void CanLoadValuesFromAutodetectedXmlFile()
		{
			var reader = new SimpleSettingsReader("MultipleEntries.xml");

			var testSettings = reader.Read<FirstSettings>();

			Assert.NotNull(testSettings);
		}
 public void FailsIfSettingsHaveNoCorrespondingProperty()
 {
     var settingsSource = new NameValueCollection();
     settingsSource["My:Name"] = "Mike";
     settingsSource["My:Blog"] = "http://codermike.com";
     var reader = new SimpleSettingsReader(settingsSource);
     Assert.Throws<Exception>(() => reader.Read<MySettings>());
 }
 public void CanReadAStringValue()
 {
     var settingsSource = new NameValueCollection();
     settingsSource["My:Name"] = "Mike";
     var reader = new SimpleSettingsReader(settingsSource);
     var settings = reader.Read<MySettings>();
     Assert.Equal("Mike", settings.Name);
 }
		public void WillLoadConfigurationValuesFromFileSpecifiedAsJson()
		{
			var reader = new SimpleSettingsReader("MultipleEntriesJson", SettingFileType.Json);

			var testSettings = reader.Read<FirstSettings>();

			Assert.Equal("blah", testSettings.Value);
		}
		public void UnconvertableSettingResultsInFormatException()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"Smtp:Port", "abcdef"}
			});
			var reader = new SimpleSettingsReader(settingsProvider);

			Assert.Throws<FormatException>(() => reader.Read<SmtpSettings>());
		}
 public void CanReadAStringValue()
 {
     var settingsSource = new NameValueCollection();
     settingsSource["My:Name"] = "Mike";
     var reader = new SimpleSettingsReader(settingsSource);
     var injector = new SimpleSettingsInjector();
     var settings = new MySettings();
     injector.Inject(settings, reader);
     Assert.AreEqual("Mike", settings.Name);
 }
		public void CanReadAStringValue()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"My:Name", "Mike"}
			});
			var reader = new SimpleSettingsReader(settingsProvider);
			var settings = reader.Read<MySettings>();
			Assert.Equal("Mike", settings.Name);
		}
		public void FailsIfSettingsHaveNoCorrespondingProperty()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"My:Name", "Mike"},
				{"My:Blog", "http://codermike.com"}
			});
			var reader = new SimpleSettingsReader(settingsProvider);
			Assert.Throws<Exception>(() => reader.Read<MySettings>());
		}
 public void CanReadManySettingsFromASingleSource()
 {
     var settingsSource = new NameValueCollection();
     settingsSource["Smtp:Server"] = "test-server";
     settingsSource["My:Name"] = "Mike";
     var reader = new SimpleSettingsReader(settingsSource);
     var smtpSettings = reader.Read<SmtpSettings>();
     var mySettings = reader.Read<MySettings>();
     Assert.Equal("test-server", smtpSettings.Server);
     Assert.Equal("Mike", mySettings.Name);
 }
           public void UnconvertableSettingResultsInFormatException()
           {
               var settingsSource = new NameValueCollection();
               settingsSource["Smtp:Port"] = "abcdef";
               var reader = new SimpleSettingsReader(settingsSource);
               var injector = new SimpleSettingsInjector();
               var settings = new SmtpSettings();

               injector.Inject(settings, reader);
               Assert.Fail("Should have thrown");
           }
 public void CanReadTypesOtherThanString()
 {
     var settingsSource = new NameValueCollection();
     settingsSource["Smtp:Server"] = "fake-server";
     settingsSource["Smtp:Port"] = "12345";
     settingsSource["Smtp:UseSSL"] = "True";
     var reader = new SimpleSettingsReader(settingsSource);
     var settings = reader.Read<SmtpSettings>();
     Assert.Equal("fake-server", settings.Server);
     Assert.Equal(12345, settings.Port);
     Assert.True(settings.UseSSL);
 }
		public void CanReadTypesOtherThanString()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"Smtp:Server", "fake-server"},
				{"Smtp:Port", "12345"},
				{"Smtp:UseSSL", "True"}
			});
			var reader = new SimpleSettingsReader(settingsProvider);
			var settings = reader.Read<SmtpSettings>();
			Assert.Equal("fake-server", settings.Server);
			Assert.Equal(12345, settings.Port);
			Assert.True(settings.UseSSL);
		}
 public void CannotGetNullSettings()
 {
     var exceptionWasThrown = false;
     var reader = new SimpleSettingsReader(new NameValueCollection());
     try
     {
         reader.Read(null);
     }
     catch (ArgumentNullException)
     {
         exceptionWasThrown = true;
     }
     Assert.IsTrue(exceptionWasThrown, "Call should have thrown an exception");
 }
           public void CanReadManySettingsFromASingleSource()
           {
               var settingsSource = new NameValueCollection();
               settingsSource["Smtp:Server"] = "test-server";
               settingsSource["My:Name"] = "Mike";
               var reader = new SimpleSettingsReader(settingsSource);
               var injector = new SimpleSettingsInjector();
               var smtpSettings = new SmtpSettings();
               var mySettings = new MySettings();

               injector.Inject(smtpSettings, reader);
               injector.Inject(mySettings, reader);

               Assert.AreEqual("test-server", smtpSettings.Server);
               Assert.AreEqual("Mike", mySettings.Name);
           }
 public void FailsIfSettingsHaveNoCorrespondingProperty()
 {
     SimpleSettingsReader reader = null;
     try
     {
         var settingsSource = new NameValueCollection();
         settingsSource["My:Name"] = "Mike";
         settingsSource["My:Blog"] = "http://codermike.com";
         reader = new SimpleSettingsReader(settingsSource);
     }
     catch (Exception ex)
     {
         Assert.Inconclusive("Unexpected Exception occurred: {0}", ex);
     }
     var settings = reader.Read<MySettings>();
     Assert.Fail("Should have thrown");
 }
Exemplo n.º 22
0
        public bool PrintDefaultIni(String out_path)
        {
            bool r = false;

            try{
                using (FileStream fs = new FileStream(out_path, FileMode.OpenOrCreate))
                {
                }
                SimpleSettingsReader sr = new SimpleSettingsReader();
                sr.SettingsINI = out_path;
                sr.AddSettings(this.Defaults);
                r = sr.SaveSettings();
                sr.Settings.Clear();

                sr = null;
            }catch (Exception ex)
            {
            }
            return(r);
        }
Exemplo n.º 23
0
        public bool PrintDefaultIni(String out_path)
        {
            bool r = false;
            try{
                using(FileStream fs = new FileStream(out_path, FileMode.OpenOrCreate))
                {

                }
                SimpleSettingsReader sr = new SimpleSettingsReader();
                sr.SettingsINI = out_path;
                sr.AddSettings(this.Defaults);
                r = sr.SaveSettings();
                sr.Settings.Clear();

                sr = null;
            }catch(Exception ex)
            {

            }
            return r;
        }
           public void CanSetPrivateProperties()
           {
               var settingsSource = new NameValueCollection();
               settingsSource["Foo:Bar"] = "Baz";
               var reader = new SimpleSettingsReader(settingsSource);
               var injector = new SimpleSettingsInjector();
               var settings = new FooSettings();

               injector.Inject(settings, reader);
               Assert.AreEqual("Baz", settings.Bar);
           }
 public void CanSetPrivateProperties()
 {
     var settingsSource = new NameValueCollection();
     settingsSource["Foo:Bar"] = "Baz";
     var reader = new SimpleSettingsReader(settingsSource);
     var settings = reader.Read<FooSettings>();
     Assert.Equal("Baz", settings.Bar);
 }
           public void AttemptToSetTheUnsettableResultsInAnException()
           {
               var settingsSource = new NameValueCollection();
               settingsSource["Test:Unsettable"] = "Bang";
               var reader = new SimpleSettingsReader(settingsSource);
               var injector = new SimpleSettingsInjector();
               var settings = new TestSettings();

               injector.Inject(settings, reader);
           }
 public void RequiresASettingsSource()
 {
     var reader = new SimpleSettingsReader(null);
 }
		public void CanSetPrivateProperties()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"Foo:Bar", "Baz"}
			});

			var reader = new SimpleSettingsReader(settingsProvider);
			var settings = reader.Read<FooSettings>();
			Assert.Equal("Baz", settings.Bar);
		}
		public void AttemptToSetTheUnsettableResultsInAnException()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"Test:Unsettable", "Bang"}
			});

			var reader = new SimpleSettingsReader(settingsProvider);

			Assert.Throws<ArgumentException>(() => reader.Read<TestSettings>());
		}
		public void CannotGetNullSettings()
		{
			var reader = new SimpleSettingsReader(new TestSettingsProvider(new Dictionary<string, string>()));
			Assert.Throws<ArgumentNullException>(() => reader.Read(null));
		}
		public void CanReadManySettingsFromASingleSource()
		{
			var settingsProvider = new TestSettingsProvider(new Dictionary<string, string>
			{
				{"Smtp:Server", "test-server"},
				{"My:Name", "Mike"}
			});

			var reader = new SimpleSettingsReader(settingsProvider);
			var smtpSettings = reader.Read<SmtpSettings>();
			var mySettings = reader.Read<MySettings>();
			Assert.Equal("test-server", smtpSettings.Server);
			Assert.Equal("Mike", mySettings.Name);
		}