public void GetString() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual("String", va.GetString("ValidString", "DefaultString")); Assert.AreEqual("DefaultString", va.GetString("NonExistingString", "DefaultString")); }
public void GetInt64() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((long)1, va.GetInt64("ValidInt64", 2)); Assert.AreEqual((long)2, va.GetInt64("InvalidInt64", 2, false)); }
public void GetGuid() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual(TESTGUID, va.GetGuid("ValidGuid", TESTGUID_DEFAULT)); Assert.AreEqual(TESTGUID_DEFAULT, va.GetGuid("InvalidGuid", TESTGUID_DEFAULT, false)); }
public void GetInt32() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((int)1, va.GetInt32("ValidInt32", 2)); Assert.AreEqual((int)2, va.GetInt32("InvalidInt32", 2, false)); }
public void GetByte() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((byte)1, va.GetByte("ValidByte", 2)); Assert.AreEqual((byte)2, va.GetByte("InvalidByte", 2, false)); }
public void GetBoolean() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual(true, va.GetBoolean("ValidBoolean", false)); Assert.AreEqual(true, va.GetBoolean("InvalidBoolean", true, false)); }
public void GetChar() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual('c', va.GetChar("ValidChar", 'a')); Assert.AreEqual('a', va.GetChar("InvalidChar", 'a', false)); Assert.Throws <ArgumentException>(() => va.GetChar("InvalidChar", 'a', true)); }
public void GetDecimal() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((decimal)1, va.GetDecimal("ValidDecimal", 2.0m)); Assert.AreEqual((decimal)2, va.GetDecimal("InvalidDecimal", 2.0m, false)); va.GetDecimal("InvalidDecimal", 2, true); }
public void GetDouble() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((double)1, va.GetDouble("ValidDouble", 2.0)); Assert.AreEqual((double)2, va.GetDouble("InvalidDouble", 2.0, false)); va.GetDouble("InvalidDouble", 2, true); }
public void GetFloat() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((float)1, va.GetFloat("ValidFloat", 2.0f)); Assert.AreEqual((float)2, va.GetFloat("InvalidFloat", 2.0f, false)); va.GetFloat("InvalidFloat", 2, true); }
public void GetInt16() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((short)1, va.GetInt16("ValidInt16", 2)); Assert.AreEqual((short)2, va.GetInt16("InvalidInt16", 2, false)); va.GetInt16("InvalidInt16", 2, true); }
public void GetDateTime() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual(TESTDATETIME, va.GetDateTime("ValidDateTime", null, TESTDATETIME_DEFAULT)); Assert.AreEqual(TESTDATETIME.ToUniversalTime(), va.GetDateTime("ValidDateTimeUtcRoundtripFormatted", "u", TESTDATETIME_DEFAULT)); Assert.AreEqual(TESTDATETIME_DEFAULT, va.GetDateTime("InvalidDateTime", null, TESTDATETIME_DEFAULT, false)); Assert.Throws <FormatException>(() => va.GetDateTime("InvalidDateTime", null, TESTDATETIME_DEFAULT, true)); }
public void GetChar() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual('c', va.GetChar("ValidChar", 'a')); Assert.AreEqual('a', va.GetChar("InvalidChar", 'a', false)); try { va.GetChar("InvalidChar", 'a', true); Assert.Fail(); } catch { } }
/// <summary> /// Initializes a new <see cref="ConfigSectionSessionScopeSettings"/> instance. /// </summary> /// <param name="ownerType">The type, who's name will be used to prefix setting variables with</param> /// <param name="variableSource">The variable source to obtain settings from.</param> public ConfigSectionSessionScopeSettings(Type ownerType, IVariableSource variableSource) : base() { string sessionFactoryObjectNameSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "SessionFactoryObjectName"); string entityInterceptorObjectNameSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "EntityInterceptorObjectName"); string singleSessionSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "SingleSession"); string defaultFlushModeSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "DefaultFlushMode"); VariableAccessor variables = new VariableAccessor(variableSource); this.sessionFactoryObjectName = variables.GetString(sessionFactoryObjectNameSettingsKey, DEFAULT_SESSION_FACTORY_OBJECT_NAME); this.entityInterceptorObjectName = variables.GetString(entityInterceptorObjectNameSettingsKey, null); this.SingleSession = variables.GetBoolean(singleSessionSettingsKey, this.SingleSession); this.DefaultFlushMode = (FlushMode)variables.GetEnum(defaultFlushModeSettingsKey, this.DefaultFlushMode); AssertUtils.ArgumentNotNull(sessionFactoryObjectName, "sessionFactoryObjectName"); // just to be sure }
public void GetDouble() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((double)1, va.GetDouble("ValidDouble", 2.0)); Assert.AreEqual((double)2, va.GetDouble("InvalidDouble", 2.0, false)); try { va.GetDouble("InvalidDouble", 2, true); Assert.Fail(); } catch { } }
public void GetStringIgnoresEmptyString() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual("DefaultString", va.GetString("EmptyString", "DefaultString")); }
public void GetBoolean() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual(true, va.GetBoolean("ValidBoolean", false)); Assert.AreEqual(true, va.GetBoolean("InvalidBoolean", true, false)); try { va.GetBoolean("InvalidBoolean", true, true); Assert.Fail(); }catch {} }
public void AcceptsNullVariableSource() { VariableAccessor va = new VariableAccessor(null); Assert.AreEqual("default", va.GetString("somekey", "default")); }
public void GetByte() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((byte)1, va.GetByte("ValidByte", 2)); Assert.AreEqual((byte)2, va.GetByte("InvalidByte", 2, false)); try { va.GetByte("InvalidByte", 2, true); Assert.Fail(); } catch { } }
public void GetInt64() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((long)1, va.GetInt64("ValidInt64", 2)); Assert.AreEqual((long)2, va.GetInt64("InvalidInt64", 2, false)); try { va.GetInt64("InvalidInt64", 2, true); Assert.Fail(); } catch { } }
public void GetDateTime() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual(TESTDATETIME, va.GetDateTime("ValidDateTime", null, TESTDATETIME_DEFAULT)); Assert.AreEqual(TESTDATETIME.ToUniversalTime(), va.GetDateTime("ValidDateTimeUtcRoundtripFormatted", "u", TESTDATETIME_DEFAULT)); Assert.AreEqual(TESTDATETIME_DEFAULT, va.GetDateTime("InvalidDateTime", null, TESTDATETIME_DEFAULT, false)); Assert.Throws<FormatException>(() => va.GetDateTime("InvalidDateTime", null, TESTDATETIME_DEFAULT, true)); }
public void GetGuid() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual(TESTGUID, va.GetGuid("ValidGuid", TESTGUID_DEFAULT)); Assert.AreEqual(TESTGUID_DEFAULT, va.GetGuid("InvalidGuid", TESTGUID_DEFAULT, false)); try { va.GetGuid("InvalidGuid", TESTGUID_DEFAULT, true); Assert.Fail(); } catch { } }
public void GetDecimal() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((decimal)1, va.GetDecimal("ValidDecimal", 2.0m)); Assert.AreEqual((decimal)2, va.GetDecimal("InvalidDecimal", 2.0m, false)); try { va.GetDecimal("InvalidDecimal", 2, true); Assert.Fail(); } catch { } }
public void GetFloat() { VariableAccessor va = new VariableAccessor(_testVariableSource); Assert.AreEqual((float)1, va.GetFloat("ValidFloat", 2.0f)); Assert.AreEqual((float)2, va.GetFloat("InvalidFloat", 2.0f, false)); try { va.GetFloat("InvalidFloat", 2, true); Assert.Fail(); } catch { } }