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 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 injector = new SimpleSettingsInjector(); var reader = new SimpleSettingsReader(settingsSource); var settings = new SmtpSettings(); injector.Inject(settings, reader); Assert.AreEqual("fake-server", settings.Server); Assert.AreEqual(12345, settings.Port); Assert.IsTrue(settings.UseSSL); }
public void FailsIfSettingsHaveNoCorrespondingProperty() { SimpleSettingsReader reader = null; SimpleSettingsInjector injector = null; try { var settingsSource = new NameValueCollection(); settingsSource["My:Name"] = "Mike"; settingsSource["My:Blog"] = "http://codermike.com"; reader = new SimpleSettingsReader(settingsSource); injector = new SimpleSettingsInjector(); } catch (Exception ex) { Assert.Inconclusive("Unexpected Exception occurred: {0}", ex); } var settings = new MySettings(); injector.Inject(settings, reader); Assert.Fail("Should have thrown"); }
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 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 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); }